Hang on Jeroen,

It's you who suggested I use the routine used within freedv_mixed_rx.

I've always mentioned my repeater project is for HF and mode 700D.

With interleave = 1;

My repeater must support the SM1000 now doing Mode 700D.

So, can you "fix" this test routine from the Codec2 library, which

has tests in places for mode 700D so that we have sample code on

how to receive mode 700D and get the "packed_bits".

Alan VK2ZIW

On Sun, 05 Jul 2020 16:45:12 +0200, Jeroen Vreeken wrote
> Hi Al,
> 
> freedv_mixed_rx doesn't have support for 700D.
> It is intended to show mixed usage with both codec and data frameswhich 700D 
> doesn't support.
> Because of this it also does not perform the necessaryfreedv_open_advanced() 
> call needed for 700D with additional settingslike the interleaver.
> 
> On 07/05/2020 08:59 AM, Al Beard wrote:
> 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 speakerto 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 700Dbut 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 Cprogrammer.
> 
> 
> Alan VK2ZIW
> 
> 
> On Fri, 3 Jul 2020 13:56:11 +1000, AlBeard wrote
> > Hi Jeroen, David anddevelopers,
> > 
> > 
> > In the old code, on SourceForgeSVN 3955, in freedv_api.c we have clearly
> > defined locations of rx"packed_bits".
> >  
> > 
> >     f->packed_codec_bits = (unsignedchar*)malloc(nbyte*sizeof(char));
> >     if (f->packed_codec_bits == NULL)return(NULL);
> > 
> > So, to get said "packed_codec_bits" I added afunction to the end of 
> > freedv_api.c and defined in.h
> > 
> > 
> > So, in the newAPI, how do I extract 700C frames out from freedv_rawdatarx()?
> > 
> > 
> > I'd be happy with unpacked bits as theroutine 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 workinguntil.......
> > 
> > 
> > 1) the received packed bits fileis rubbish.
> > 2) transmitting out the packedbits, doesn't read down my buffer quick 
> > enough.
> > 3) squelch does not workproperly. 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 fromfile ve9qrp_700d.wav
> > 
> > 
> > Compiling:
> > Add parrot.c to freebeacon andadd 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 DESTINATIONbin)
> > -----------
> > 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 parrotversion ------------------
> > I added a function in freedv_api.c to makeavailable 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 detailthough)
> > > 
> > > 73,
> > > Jeroen PE1RXQ
> > > 
> > > On 06/27/2020 01:37 PM, Al Beard wrote:
> > > Hi Jeroen and David,
> > >  
> > >  
> > > I fixed it, usefreedv_rawdatatx(). 
> > >  
> > >  
> > > Anyway, it compiles andneeds testing. 
> > >  
> > >  
> > > Can you look at my codeplease? 
> > >  
> > >  
> > > Alan VK2ZIW
> > >  
> > >  
> > >  
> > >  
> > > On Sat, 20 Jun 202021:56:31 +0200, Jeroen Vreeken wrote 
> > > > Hi Al, 
> > > > 
> > > > Yes, my repeater code is 
> > > > available,(https://github.com/JeroenVreeken/eth_ar),but it might be a 
> > > > bit overkill as it implementseverything needed for a mixed mode UHF 
> > > > repeater.(And is poorly documented) 
> > > > But have a look if you get anyusefull ideas from it. 
> > > > 
> > > > If you are targetting mode 700D foryour setup the freedv_rawdata 
> > > > functions areprobably the best match. 
> > > > (freedv_datatx won't be usefull as700D has no dedicated VHF data 
> > > > channel). 
> > > > The only additional challenge youhave is that you want to locally 
> > > > listen to it. 
> > > > For that you can use the'use_codecrx==1' snippet of freedv_mixed_rx.c 
> > > > asan example. 
> > > > It basicly does the same thing:receive the 'raw' codec2 frames and 
> > > > decodes it toaudio using codec2_decode. 
> > > > 
> > > > For you parrot repeater you justneed one extra step: store the frames 
> > > > and sendthem again with freedv_rawdatatx() 
> > > > 
> > > > 73, 
> > > > Jeroen PE1RXQ 
> > > > 
> > > > On 06/19/2020 01:52 AM, Al Beardwrote: 
> > > > Hi Jeroen,
> > > > > So what kind of 'data'do you want to repeat? 
> > > >  
> > > >  
> > > > First, therepeater will be on HF, 80m, 40m or 20m.
> > > > Built alreadyis a MST3 kit along with a Banana Pi M2Berry (Pi clone). 
> > > > (and a 500Gbspinning hard disk for storage) 
> > > >  
> > > >  
> > > > What 'data' ?   Mode700D, is what I expect is what most activityis. 
> > > > 
> > > > >An other thing they are usefull for arerepeaters (like yours and mine) 
> > > > >where you wantto re-transmit the incomming data withoutloosing quality 
> > > > >by passing through andecoder/encoder again. 
> > > >  
> > > >  
> > > > I did not knowyou had "repeater" code. 
> > > >  
> > > >  
> > > > I'm not tryingto reinvent the wheel, I'm wanting toimplement, build the 
> > > > said repeater.
> > > >  
> > > >  
> > > > My reasoningin decoding to voice the received signal is,when at the 
> > > > repeater site, it'd 
> > > > be great to beable to listen to the audio. 
> > > >  
> > > >  
> > > > So, is your"repeater" code available for me toimplement. 
> > > >  
> > > >  
> > > > As mentioned,I'm not a "C" guru. I can "tinker".
> > > >  
> > > >  
> > > > MRFE6S9160                      (somewhat more usefulthan a 73) 
> > > >  
> > > >  
> > > > Alan VK2ZIW
> > > >  
> > > >  
> > > > On Thu, 18 Jun2020 23:23:58 +0200, Jeroen Vreeken wrote
> > > > > Hi Al, 
> > > > > 
> > > > > You might be confused bythe different types of 'data' we send. 
> > > > > A number of modes (2400A,2400B, 800XA, 6000) have a dedicated 
> > > > > datachannel (David sugested to call it the 'VHFdata channel'). When 
> > > > > packets of data aretransmitted with it a different sync word isused 
> > > > > on air and the freedv library will passthe received packets to 
> > > > > callback functions.(In case of freedv_mixed_rx the 
> > > > > functionmy_datarx()) 
> > > > > 
> > > > > If such a data frame isreceived the 
> > > > > freedv_rx/freedv_rawdatarxfunction will return zero to indicate 
> > > > > therewas no voice payload. 
> > > > > 
> > > > > The other modes only havethe 'voice' data channel (and a few 
> > > > > varicodetext bits, which could also be called 'data').
> > > > > When the regularfreedv_rx/freedv_tx functions are used it willalways 
> > > > > contain codec2 or lpcnet frames. 
> > > > > Thefreedv_rawdatarx/freedv_rawdatarx work on thesame data, but allow 
> > > > > you access the 'raw' bitsthat go into the actual modem functions. 
> > > > > They are usefull if youwant to send alternate data (or 
> > > > > alternatecodecs), but there is no way the receiver'knows' about this. 
> > > > > An other thing they areusefull for are repeaters (like yours andmine) 
> > > > > where you want to re-transmit theincomming data without loosing 
> > > > > quality bypassing through an decoder/encoder again. 
> > > > > 
> > > > >So what kind of 'data' do you want torepeat? 
> > > > > Is it the voice codecdata? then receiving with freedv_rawdatarxand 
> > > > > sending with freedv_rawdatatx will dothe trick and can be triggered 
> > > > > by varicodetext. 
> > > > > Is it the 'VHF' datachannel? then you can use callbackfunctions for 
> > > > > the packets. To switch tothe frames instead of voice 
> > > > > usedfreedv_datatx instead of the regular ones.
> > > > > Whether 'data' wantsto be repeated is indeed a good question,the text 
> > > > > like you used before could work,or in case of the VHF data channel 
> > > > > youcould select based on the destinationaddress of a packet. (e.g. if 
> > > > > it is the'broadcast' address the sender appearentlywanted as many 
> > > > > people to know as possible)
> > > > > 
> > > > > 73, 
> > > > > Jeroen PE1RXQ 
> > > > > 
> > > > > On 06/18/2020 01:46 PM, AlBeard wrote: 
> > > > > Hi Jeroen,
> > > > > I'vejust looked at "freedv_mixed_rx.c" andit looks not to extract a 
> > > > > data frame,
> > > > > onlya codec2 frame or frames. 
> > > > >  
> > > > >  
> > > > > In myproposed repeater, once triggered, I'dwant to repeat data 
> > > > > frames. 
> > > > > Also,if only data frames are received, how doI determine that this 
> > > > > data stream
> > > > > "wants"to be repeated? 
> > > > >  
> > > > >  
> > > > > AlanVK2ZIW 
> > > > >  
> > > > >  
> > > > > OnThu, 18 Jun 2020 16:34:25 +1000, AlBeard wrote 
> > > > > > Hiagain Jeroen, 
> > > > > > 
> > > > > > 
> > > > > > Inadding codec2_decode(c2, ...), I nowneed to add 
> > > > > > to/usr/local/include/codec2/
> > > > > > newamp2.h
> > > > > > newamp1.h 
> > > > > > kiss_fftr.h
> > > > > > kiss_fft.h
> > > > > > defines.h
> > > > > > codec2_fft.h
> > > > > > codec2_internal.h
> > > > > > 
> > > > > > 
> > > > > > andin the end, void codec2_decode() doesnot return how many samples
> > > > > > ofaudio it had decoded. So, if it were adata frame, it might return 
> > > > > > zero.
> > > > > > 
> > > > > > 
> > > > > > Stillin progress. So far, it compiles, butnot tested.  
> > > > > > 
> > > > > > 
> > > > > > AlanVK2ZIW 
> > > > > > 
> > > > > > 
> > > > > 
> > > > >---------------------------------------------------
> > > > > 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. 
> 
> 
> 
> 
> 
>_______________________________________________
Freetel-codec2 mailing

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

--------------------------------------------------- 
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