Hi all, David, Jeroen and developers,

Houston, we have a problem:

On testing freedv_mixed_rx in mode 700D, with the flag "--codecrx"

the output file is correct size but garbled.

The source 700D audio was ve9qrp_700d.wav passed speaker to mic,

and was intact on my Odroid N2, decoding well as in 

2020-07-04-16.raw

with the --codecrx flag set

2020-07-04-16b.raw

Files at http://www.unixservice.com.au/parrot

(cannot send large files > 200Kb here)

I've been tearing my hair out looking into my "parrot" code looking

for my error, three days now!!!!

The original "freedv_mixed_rx.c" has tests for mode 700D but is not

allowed to be used by the main() argument processing.  

Developers, can you please look at this?

Alan VK2ZIW

At this point, I'm not a good enough C programmer.

Alan VK2ZIW

On Fri, 3 Jul 2020 13:56:11 +1000, Al Beard wrote
> Hi Jeroen, David and developers,
> 
> 
> In the old code, on SourceForge SVN 3955, in freedv_api.c we have clearly
> defined locations of rx "packed_bits".
>  
> 
>     f->packed_codec_bits = (unsigned char*)malloc(nbyte*sizeof(char));
>     if (f->packed_codec_bits == NULL) return(NULL);
> 
> So, to get said "packed_codec_bits" I added a function to the end of 
> freedv_api.c and defined in .h
> 
> 
> So, in the new API, how do I extract 700C frames out from freedv_rawdatarx() ?
> 
> 
> I'd be happy with unpacked bits as the routine to pack is easy.
> 
> 
> BTW: my "parrot.c" code is taken from current "freebeacon.c" code, mode set 
> to 700D.
> 
> 
> 
> 
> ==== last email ====
> It all looks to be working until.......
> 
> 
> 1) the received packed bits file is rubbish.
> 2) transmitting out the packed bits, doesn't read down my buffer quick enough.
> 3) squelch does not work properly. Sync stays up on noise. A quick whistle
>      will get it out of sync. I've set squelch_en = 1 and given it a level.
> 
> 
> usage: ./parrot --dev 5 -v
> 
> 
> speaker to mic from file ve9qrp_700d.wav
> 
> 
> Compiling:
> Add parrot.c to freebeacon and add this to CMakeLists.txt
> 
> 
> 
> ############ Parrot ################
> add_executable(parrot parrot.c)
> target_link_libraries(parrot ${FREEBEACON_LINK_LIBS} codec2)
> if(FREEBEACON_STATIC_DEPS)
>     add_dependencies(parrot ${FREEBEACON_STATIC_DEPS})
> endif()
> 
> 
> install(TARGETS parrot RUNTIME DESTINATION bin)
> -----------
> then, as usual, mkdir build; cd build; cmake ../ ; make
> 
> Running FreeDV GUI on the same machine, decodes ve9qrp_700d.wav
> just fine, from the same microphone input.
> 
> -------------------------- In the previous parrot version ------------------
> I added a function in freedv_api.c to make available the packed_bits and that 
> worked.
> 
> I'm trying to NOT modify the freedv_api.
> 
> Alan VK2ZIW
> 
> 
> On Sat, 27 Jun 2020 21:57:31 +0200, Jeroen Vreeken wrote
> > Hi Al,
> > 
> > On first glance your code looks ok.
> > (Haven't looked at the whole thing in detail though)
> > 
> > 73,
> > Jeroen PE1RXQ
> > 
> > On 06/27/2020 01:37 PM, Al Beard wrote:
> > Hi Jeroen and David,
> > 
> > 
> > I fixed it, use freedv_rawdatatx().
> > 
> > 
> > Anyway, it compiles and needs testing.
> > 
> > 
> > Can you look at my code please?
> > 
> > 
> > Alan VK2ZIW
> > 
> > 
> > 
> > 
> > On Sat, 20 Jun 2020 21:56:31 +0200, JeroenVreeken wrote
> > > Hi Al,
> > > 
> > > Yes, my repeater code is available, 
> > > (https://github.com/JeroenVreeken/eth_ar),but it might be a bit overkill 
> > > as it implements everythingneeded for a mixed mode UHF repeater. (And is 
> > > poorlydocumented)
> > > But have a look if you get any usefull ideas from it.
> > > 
> > > If you are targetting mode 700D for your setup thefreedv_rawdata 
> > > functions are probably the best match.
> > > (freedv_datatx won't be usefull as 700D has no dedicatedVHF data channel).
> > > The only additional challenge you have is that you wantto locally listen 
> > > to it.
> > > For that you can use the 'use_codecrx==1' snippet offreedv_mixed_rx.c as 
> > > an example.
> > > It basicly does the same thing: receive the 'raw' codec2frames and 
> > > decodes it to audio using codec2_decode.
> > > 
> > > For you parrot repeater you just need one extra step:store the frames and 
> > > send them again with freedv_rawdatatx()
> > > 
> > > 73,
> > > Jeroen PE1RXQ
> > > 
> > > On 06/19/2020 01:52 AM, Al Beard wrote:
> > > Hi Jeroen, 
> > > >So what kind of 'data' do you want to repeat?
> > >  
> > >  
> > > First, the repeater will be on HF,80m, 40m or 20m. 
> > > Built already is a MST3 kit alongwith a Banana Pi M2 Berry (Pi clone). 
> > > (and a 500Gb spinning hard disk forstorage) 
> > >  
> > >  
> > > What 'data'?   Mode 700D, is what I expect is what most activityis. 
> > > 
> > > > An other thingthey are usefull for are repeaters (like yours and 
> > > > mine)where you want to re-transmit the incomming data withoutloosing 
> > > > quality by passing through an decoder/encoderagain. 
> > >  
> > >  
> > > I did not know you had "repeater"code. 
> > >  
> > >  
> > > I'm not trying to reinvent thewheel, I'm wanting to implement, build the 
> > > saidrepeater. 
> > >  
> > >  
> > > My reasoning in decoding to voicethe received signal is, when at the 
> > > repeater site, it'd
> > > be great to be able to listen to theaudio. 
> > >  
> > >  
> > > So, is your "repeater" codeavailable for me to implement. 
> > >  
> > >  
> > > As mentioned, I'm not a "C" guru. Ican "tinker". 
> > >  
> > >  
> > > MRFE6S9160                      (somewhat more useful than a 73) 
> > >  
> > >  
> > > Alan VK2ZIW 
> > >  
> > >  
> > > On Thu, 18 Jun 2020 23:23:58 +0200,Jeroen Vreeken wrote 
> > > > Hi Al, 
> > > > 
> > > > You might be confused by the different types of'data' we send. 
> > > > A number of modes (2400A, 2400B, 800XA, 6000)have a dedicated data 
> > > > channel (David sugested to call itthe 'VHF data channel'). When packets 
> > > > of data aretransmitted with it a different sync word is used on airand 
> > > > the freedv library will pass the received packets tocallback functions. 
> > > > (In case of freedv_mixed_rx thefunction my_datarx()) 
> > > > 
> > > > If such a data frame is received thefreedv_rx/freedv_rawdatarx function 
> > > > will return zero toindicate there was no voice payload. 
> > > > 
> > > > The other modes only have the 'voice' datachannel (and a few varicode 
> > > > text bits, which could also becalled 'data'). 
> > > > When the regular freedv_rx/freedv_tx functionsare used it will always 
> > > > contain codec2 or lpcnet frames. 
> > > > The freedv_rawdatarx/freedv_rawdatarx work onthe same data, but allow 
> > > > you access the 'raw' bits that gointo the actual modem functions. 
> > > > They are usefull if you want to send alternatedata (or alternate 
> > > > codecs), but there is no way thereceiver 'knows' about this. 
> > > > An other thing they are usefull for arerepeaters (like yours and mine) 
> > > > where you want tore-transmit the incomming data without loosing quality 
> > > > bypassing through an decoder/encoder again. 
> > > > 
> > > > So what kind of 'data'do you want to repeat? 
> > > > Is it the voice codec data? then receivingwith freedv_rawdatarx and 
> > > > sending withfreedv_rawdatatx will do the trick and can betriggered by 
> > > > varicode text. 
> > > > Is it the 'VHF' data channel? then you canuse callback functions for 
> > > > the packets. To switch tothe frames instead of voice used freedv_datatx 
> > > > insteadof the regular ones. 
> > > > Whether 'data' wants to be repeated isindeed a good question, the text 
> > > > like you used beforecould work, or in case of the VHF data channel 
> > > > youcould select based on the destination address of apacket. (e.g. if 
> > > > it is the 'broadcast' address thesender appearently wanted as many 
> > > > people to know aspossible) 
> > > > 
> > > > 73, 
> > > > Jeroen PE1RXQ 
> > > > 
> > > > On 06/18/2020 01:46 PM, Al Beard wrote: 
> > > > Hi Jeroen, 
> > > > I've just lookedat "freedv_mixed_rx.c" and it looks not to extract 
> > > > adata frame, 
> > > > only a codec2 frame orframes. 
> > > >  
> > > >  
> > > > In my proposed repeater,once triggered, I'd want to repeat data frames.
> > > > Also, if only data framesare received, how do I determine that this 
> > > > datastream 
> > > > "wants" to be repeated?
> > > >  
> > > >  
> > > > Alan VK2ZIW 
> > > >  
> > > >  
> > > > On Thu, 18 Jun 202016:34:25 +1000, Al Beard wrote 
> > > > > Hi again Jeroen,
> > > > >  
> > > > >  
> > > > > Inadding codec2_decode(c2, ...), I now need to addto 
> > > > > /usr/local/include/codec2/ 
> > > > > newamp2.h
> > > > > newamp1.h 
> > > > > kiss_fftr.h
> > > > > kiss_fft.h
> > > > > defines.h
> > > > > codec2_fft.h
> > > > > codec2_internal.h
> > > > >  
> > > > >  
> > > > > and in the end, voidcodec2_decode() does not return how many samples
> > > > > of audio it haddecoded. So, if it were a data frame, it mightreturn 
> > > > > zero. 
> > > > >  
> > > > >  
> > > > > Still in progress.So far, it compiles, but not tested.  
> > > > >  
> > > > >  
> > > > > Alan VK2ZIW
> > > > >  
> > > > > 
> > > > 
> > > >--------------------------------------------------- 
> > > > Alan Beard 
> > > > 
> > > > OpenWebMail 2.53 
> > > > 
> > > >  
> > > > 
> > > > 
> > > > 
> > > >_______________________________________________
Freetel-codec2 mailing

list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freetel-codec2

> > > 
> > > --------------------------------------------------- 
> > > Alan Beard 
> > > 
> > > OpenWebMail 2.53 
> > > 
> > >  
> > 
> > --------------------------------------------------- 
> > Alan Beard 
> > 
> > OpenWebMail 2.53 
> > 
> > 
> 
> --------------------------------------------------- 
> Alan VK2ZIW 
> 
> OpenWebMail 2.53, nothing in the cloud. 
> 
>

--------------------------------------------------- 
Alan VK2ZIW

OpenWebMail 2.53, nothing in the cloud.

 
/*---------------------------------------------------------------------------*\

  FILE........: freedv_mixed_rx.c
  AUTHOR......: Jeroen Vreeken & David Rowe
  DATE CREATED: May 2020

  Demo receive program for FreeDV API that demonstrates shows mixed
  VHF packet data and speech frames.

\*---------------------------------------------------------------------------*/

/*
  Copyright (C) 2014 David Rowe

  All rights reserved.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License version 2.1, as
  published by the Free Software Foundation.  This program is
  distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>

#include "freedv_api.h"
#include "modem_stats.h"

#include "codec2.h"


struct my_callback_state {
    int calls;
    FILE *ftxt;
};

/* Called when a packet has been received */
void my_datarx(void *callback_state, unsigned char *packet, size_t size) {
    struct my_callback_state* pstate = (struct my_callback_state*)callback_state;
    
    pstate->calls++;
    
    if (pstate->ftxt != NULL) {
        size_t i;
	
	fprintf(pstate->ftxt, "data (%zd bytes): ", size);
	for (i = 0; i < size; i++) {
	    fprintf(pstate->ftxt, "0x%02x ", packet[i]);
	}
	fprintf(pstate->ftxt, "\n");
    }
}

/* Called when a new packet can be send */
void my_datatx(void *callback_state, unsigned char *packet, size_t *size) {
    /* This should not happen while receiving.. */
    fprintf(stderr, "datarx callback called, this should not happen!\n");    
    *size = 0;
}

int main(int argc, char *argv[]) {
    FILE                      *fin, *fout, *ftxt;
    struct freedv             *freedv;
    int                        nin, nout, nout_total = 0, frame = 0;
    struct my_callback_state   my_cb_state = {0};
    int                        mode;
    int                        use_codecrx, verbose;
    struct CODEC2             *c2 = NULL;
    int                        i;

    
    if (argc < 4) {
	printf("usage: %s 2400A|2400B|800XA|700D InputModemSpeechFile OutputSpeechRawFile\n"
               " [--codecrx] [-v]\n", argv[0]);
	printf("e.g    %s 2400A hts1a_fdmdv.raw hts1a_out.raw\n", argv[0]);
	exit(1);
    }

    mode = -1;
    if (!strcmp(argv[1],"2400A"))
        mode = FREEDV_MODE_2400A;
    if (!strcmp(argv[1],"2400B"))
        mode = FREEDV_MODE_2400B;
    if (!strcmp(argv[1],"800XA"))
        mode = FREEDV_MODE_800XA;
    if (!strcmp(argv[1],"700D"))
        mode = FREEDV_MODE_700D;
    assert(mode != -1);

    if (strcmp(argv[2], "-")  == 0) fin = stdin;
    else if ( (fin = fopen(argv[2],"rb")) == NULL ) {
	fprintf(stderr, "Error opening input raw modem sample file: %s: %s.\n",
         argv[2], strerror(errno));
	exit(1);
    }

    if (strcmp(argv[3], "-") == 0) fout = stdout;
    else if ( (fout = fopen(argv[3],"wb")) == NULL ) {
	fprintf(stderr, "Error opening output speech sample file: %s: %s.\n",
         argv[3], strerror(errno));
	exit(1);
    }

    use_codecrx = 0; verbose = 0;
    
    if (argc > 4) {
        for (i = 4; i < argc; i++) {
            if (strcmp(argv[i], "--codecrx") == 0) {
                int c2_mode;

                if ((mode == FREEDV_MODE_700C) || (mode == FREEDV_MODE_700D) || (mode == FREEDV_MODE_800XA)) {
                    c2_mode = CODEC2_MODE_700C;
                } else {
                    c2_mode = CODEC2_MODE_1300;
                }
                use_codecrx = 1;

                c2 = codec2_create(c2_mode);
                assert(c2 != NULL);
            }

            if (strcmp(argv[i], "-v") == 0) {
                verbose = 1;
            }
            if (strcmp(argv[i], "-vv") == 0) {
                verbose = 2;
            }
        }
    }
    fprintf(stderr, "codecrx = %d \n", use_codecrx);

    freedv = freedv_open(mode);
    assert(freedv != NULL);

    freedv_set_verbose(freedv, verbose);

    short speech_out[freedv_get_n_max_speech_samples(freedv)];
    short demod_in[freedv_get_n_max_modem_samples(freedv)];

    ftxt = fopen("freedv_rx_log.txt","wt");
    assert(ftxt != NULL);
    my_cb_state.ftxt = ftxt;
    freedv_set_callback_data(freedv, my_datarx, my_datatx, &my_cb_state);

    /* Note we need to work out how many samples demod needs on each
       call (nin).  This is used to adjust for differences in the tx and rx
       sample clock frequencies.  Note also the number of output
       speech samples is time varying (nout). */

    nin = freedv_nin(freedv);
    while(fread(demod_in, sizeof(short), nin, fin) == nin) {
        frame++;
        
        if (use_codecrx == 0) {
            /* usual case: use the freedv_api to do everything: speech decoding, demodulating */
            nout = freedv_rx(freedv, speech_out, demod_in);
        } else {
            /* demo of codecrx mode - separate demodulation and speech decoding */
            int bits_per_codec_frame = codec2_bits_per_frame(c2);
            int bytes_per_codec_frame = (bits_per_codec_frame + 7) / 8;
            int codec_frames = freedv_get_bits_per_modem_frame(freedv) / bits_per_codec_frame;
            int samples_per_frame = codec2_samples_per_frame(c2);
            unsigned char encoded[bytes_per_codec_frame * codec_frames];

            nout = 0;
	    
            /* Use the freedv_api to demodulate only */
            int ncodec = freedv_rawdatarx(freedv, encoded, demod_in);
	  
            /* decode the speech ourself (or send it to elsewhere, e.g. network) */
            if (ncodec) {
                unsigned char *enc_frame = encoded;
                short *speech_frame = speech_out;
                
                for (i = 0; i < codec_frames; i++) {
                    codec2_decode(c2, speech_frame, enc_frame);
                    enc_frame += bytes_per_codec_frame;
                    speech_frame += samples_per_frame;
                    nout += samples_per_frame;
                }
	    }
        }
        fprintf(ftxt, "Demod of %d samples resulted %d speech samples\n", nin, nout);

        if (nout == 0)
	{
	   /* We did not get any audio.
	      This means the modem is (probably) synced, but a data frame was received
	      Fill in the 'blanks' use by data frames with silence 
	    */
	        nout = freedv_get_n_speech_samples(freedv);
	        memset(speech_out, 0, nout * sizeof(short));
        }
	
        nin = freedv_nin(freedv);

        fwrite(speech_out, sizeof(short), nout, fout);
        nout_total += nout;
        
	/* if this is in a pipeline, we probably don't want the usual
           buffering to occur */

        if (fout == stdout) fflush(stdout);
        if (fin == stdin) fflush(stdin);
    }

    fclose(ftxt);
    fclose(fin);
    fclose(fout);
    fprintf(stderr, "frames decoded: %d  output speech samples: %d, data packets: %d\n", frame, nout_total, my_cb_state.calls);

    freedv_close(freedv);
    return 0;
}

_______________________________________________
Freetel-codec2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freetel-codec2

Reply via email to