コード例 #1
0
ファイル: sm1000_main.c プロジェクト: rpiskun/codec2
int main(void) {
    struct freedv *f;
    short  buf[FREEDV_NSAMPLES];
    int    nin, nout;

    /* init all the drivers for various peripherals */

    sm1000_leds_switches_init();
    dac_open(4*DAC_BUF_SZ);
    adc_open();
    f = freedv_open(FREEDV_MODE_1600);

    /* LEDs into a known state */

    led_pwr(1); led_ptt(0); led_rt(0); led_err(0);

    /* 
       TODO:
       [ ] UT analog interfaces from file IO
       [ ] UTs for simultaneous tx & rx on analog interfaces
       [ ] measure CPU load of various parts with a blinky
       [ ] detect program assert type errors with a blinky
       [ ] timer tick function to measure 10ms-ish type times
       [ ] switch debouncing?
       [ ] light led with bit errors
    */

    while(1) {

        if(switch_ptt()) {

            /* Transmit -------------------------------------------------------------------------*/

            /* ADC2 is the SM1000 microphone, DAC1 is the modulator signal we send to radio tx */

            if (adc2_read(buf, FREEDV_NSAMPLES) == FREEDV_NSAMPLES) {
                freedv_tx(f, buf, buf);
                dac1_write(buf, FREEDV_NSAMPLES);
                led_ptt(1); led_rt(0); led_err(0);
            }
        }
        else {
            
            /* Receive --------------------------------------------------------------------------*/

            /* ADC1 is the demod in signal from the radio rx, DAC2 is the SM1000 speaker */

            nin = freedv_nin(f);
            f->total_bit_errors = 0;
            
            if (adc1_read(buf, nin) == nin) {
                nout = freedv_rx(f, buf, buf);
                dac2_write(buf, nout);
                led_ptt(0); led_rt(f->fdmdv_stats.sync); led_err(f->total_bit_errors);
            }

        }
        
    } /* while(1) ... */
}
コード例 #2
0
ファイル: freedv_tx.c プロジェクト: McuMirror/4-codec2
int main(int argc, char *argv[]) {
    FILE                     *fin, *fout;
    short                     speech_in[FREEDV_NSAMPLES];
    short                     mod_out[FREEDV_NSAMPLES];
    struct freedv            *freedv;
    struct my_callback_state  my_cb_state;

    if (argc < 3) {
	printf("usage: %s InputRawSpeechFile OutputModemRawFile\n", argv[0]);
	printf("e.g    %s hts1a.raw hts1a_fdmdv.raw\n", argv[0]);
	exit(1);
    }

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

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

    /* set up callback for txt msg chars */

    sprintf(my_cb_state.tx_str, "cq cq cq hello world\n");
    my_cb_state.ptx_str = my_cb_state.tx_str;
    freedv->callback_state = (void*)&my_cb_state;
    freedv->freedv_get_next_tx_char = &my_get_next_tx_char;

    /* OK main loop */

    while(fread(speech_in, sizeof(short), FREEDV_NSAMPLES, fin) == FREEDV_NSAMPLES) {
        freedv_tx(freedv, mod_out, speech_in);
        fwrite(mod_out, sizeof(short), FREEDV_NSAMPLES, fout);

	/* 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);         
    }

    freedv_close(freedv);
    fclose(fin);
    fclose(fout);

    return 0;
}
コード例 #3
0
int main(int argc, char *argv[]) {
    struct freedv *f;
    short          inbuf[FREEDV_NSAMPLES], outbuf[FREEDV_NSAMPLES];
    FILE          *fin, *fout;
    int            frame;
    PROFILE_VAR(freedv_start);

    machdep_profile_init();

    f = freedv_open(FREEDV_MODE_1600);

    // Transmit ---------------------------------------------------------------------

    fin = fopen("stm_in.raw", "rb");
    if (fin == NULL) {
        printf("Error opening input file\n");
        exit(1);
    }

    fout = fopen("mod.raw", "wb");
    if (fout == NULL) {
        printf("Error opening output file\n");
        exit(1);
    }

    frame = 0;

    while (fread(inbuf, sizeof(short), FREEDV_NSAMPLES, fin) == FREEDV_NSAMPLES) {
        PROFILE_SAMPLE(freedv_start);
        freedv_tx(f, outbuf, inbuf);
        PROFILE_SAMPLE_AND_LOG2(freedv_start, "  freedv_tx");     
       
        fwrite(outbuf, sizeof(short), FREEDV_NSAMPLES, fout);
        printf("frame: %d\n", ++frame);
        machdep_profile_print_logged_samples();
   }

    fclose(fin);
    fclose(fout);

    return 0;
}
コード例 #4
0
ファイル: sm1000_main.c プロジェクト: n6wxd/codec2
int main(void) {
    struct freedv *f;
    short          adc16k[FDMDV_OS_TAPS_16K+FREEDV_NSAMPLES_16K];
    short          dac16k[FREEDV_NSAMPLES_16K];
    short          adc8k[FREEDV_NSAMPLES];
    short          dac8k[FDMDV_OS_TAPS_8K+FREEDV_NSAMPLES];
    SWITCH_STATE   ss;
    int            nin, nout, i;

    /* init all the drivers for various peripherals */

    SysTick_Config(SystemCoreClock/168000); /* 1 kHz SysTick */
    sm1000_leds_switches_init();
    dac_open(4*DAC_BUF_SZ);
    adc_open(4*ADC_BUF_SZ);
    f = freedv_open(FREEDV_MODE_1600);

    /* put outputs into a known state */

    led_pwr(1); led_ptt(0); led_rt(0); led_err(0); not_cptt(1);

    /* clear filter memories */

    for(i=0; i<FDMDV_OS_TAPS_16K; i++)
	adc16k[i] = 0.0;
    for(i=0; i<FDMDV_OS_TAPS_8K; i++)
	dac8k[i] = 0.0;

    ss.state = SS_IDLE;
    ss.mode  = ANALOG;

    while(1) {
        
        iterate_select_state_machine(&ss);

        if (switch_ptt()) {

            /* Transmit -------------------------------------------------------------------------*/

            /* ADC2 is the SM1000 microphone, DAC1 is the modulator signal we send to radio tx */

            if (adc2_read(&adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES_16K) == 0) {
                GPIOE->ODR = (1 << 3);

                fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES);

                if (ss.mode == ANALOG) {
                    for(i=0; i<FREEDV_NSAMPLES; i++)
                        dac8k[FDMDV_OS_TAPS_8K+i] = adc8k[i];
                    fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], FREEDV_NSAMPLES);              
                    dac1_write(dac16k, FREEDV_NSAMPLES_16K);
                }
                if (ss.mode == DV) {
                    freedv_tx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k);
                    fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], FREEDV_NSAMPLES);              
                    dac1_write(dac16k, FREEDV_NSAMPLES_16K);
                }

                if (ss.mode == TONE) {
                    while(dac1_write((short*)aSine, SINE_SAMPLES) == 0);
                }

                led_ptt(1); led_rt(0); led_err(0); not_cptt(0);
                GPIOE->ODR &= ~(1 << 3);
            }

        }
        else {
            
            /* Receive --------------------------------------------------------------------------*/

            not_cptt(1); led_ptt(0); 

            /* ADC1 is the demod in signal from the radio rx, DAC2 is the SM1000 speaker */

            if (ss.mode == ANALOG) {

                /* force analog bypass when select down */

                if (adc1_read(&adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES_16K) == 0) {
                    fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES);
                    for(i=0; i<FREEDV_NSAMPLES; i++)
                        dac8k[FDMDV_OS_TAPS_8K+i] = adc8k[i];
                    fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], FREEDV_NSAMPLES);              
                    dac2_write(dac16k, FREEDV_NSAMPLES_16K);
                    led_rt(0); led_err(0);
               }
            }
            else {

                /* regular DV mode */

                nin = freedv_nin(f);   
                nout = nin;
                f->total_bit_errors = 0;

                if (adc1_read(&adc16k[FDMDV_OS_TAPS_16K], 2*nin) == 0) {
                    GPIOE->ODR = (1 << 3);
                    fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], nin);
                    nout = freedv_rx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k);
                    fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], nout);              
                    dac2_write(dac16k, 2*nout);
                    led_rt(f->fdmdv_stats.sync); led_err(f->total_bit_errors);
                    GPIOE->ODR &= ~(1 << 3);
                }
            }

        }
    } /* while(1) ... */
}