Hi Steve,

Not quite true, I've had an eighteen month break. Lightning
killed my three radios, main and backup computers and of course,
other interests.

Our Australian Amateur Radio Emergency group (WICEN) showed great
interest in my "parrot" project and provided a Codan HF radio for
the project and we have at least two sites available.

Right now we have two end user solutions:

1) The FreeDV GUI app on a PC and  HF transceiver.
2) The SM1000 and HF transceiver.

You wrote:
> wondering if maybe there's a better way. Since simplex repeaters are
> not real time,

I disagree. Stations 1 and 2 do not have internet but they do have an
excellent HF path to my HF repeater. But, not between themselves!

And yes it IS in real time.

Within two seconds of parrot sensing the end of a QSO, it will retransmit it.

Meanwhile, the Codec2 library has changed in that "packed codec bits"
are not available to the application writer via the API. I had to
add a simple "get" routine in previous versions, not now.
I could Tx without any changes. 

If you look at this file freedv_mixed_rx.c from the library, why if mode
700D is not supported, why is 700D mentioned so so often?
I allowed 700D in the argument parsing to test the --codecrx switch. 

To test the routine Jeroen suggested.

Keep smiling

Alan VK2ZIW






On Sun, 5 Jul 2020 10:04:22 -0500, Steve wrote
> Alan, you've been banging on that code for a couple of years now. I'm
> wondering if maybe there's a better way. Since simplex repeaters are
> not real time, this opens up the possibility of just vocoding the
> audio and sending the resulting data file as an encoded/fec packet.
> For example via Pactor.
> 
> Most Pactor stations are connected to the Internet, so your voice 
> file can reach the recipient pretty fast, and then they can reply through
> the same repeater or even another path.
> 
> But this simplifies everything, as all you have to do is record your
> audio, and use an off-the-shelf data modem which guarantees delivery.
> 
> _______________________________________________
> 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