static void c2demo(int mode, char inputfile[], char outputfile[]) { struct CODEC2 *codec2; short *inbuf, *outbuf; unsigned char *bits; int nsam, nbit; FILE *fin, *fout; int frame; PROFILE_VAR(enc_start, dec_start); codec2 = codec2_create(mode); nsam = codec2_samples_per_frame(codec2); outbuf = (short*)malloc(nsam*sizeof(short)); inbuf = (short*)malloc(nsam*sizeof(short)); nbit = codec2_bits_per_frame(codec2); bits = (unsigned char*)malloc(nbit*sizeof(char)); fin = fopen(inputfile, "rb"); if (fin == NULL) { printf("Error opening input file: %s\n\nTerminating....\n",inputfile); exit(1); } fout = fopen(outputfile, "wb"); if (fout == NULL) { printf("Error opening output file: %s\n\nTerminating....\n",outputfile); exit(1); } #ifdef DUMP dump_on("stm32f4"); #endif frame = 0; while (fread(inbuf, sizeof(short), nsam, fin) == nsam) { PROFILE_SAMPLE(enc_start); codec2_encode(codec2, bits, inbuf); PROFILE_SAMPLE_AND_LOG(dec_start, enc_start, " enc"); codec2_decode(codec2, outbuf, bits); PROFILE_SAMPLE_AND_LOG2(dec_start, " dec"); PROFILE_SAMPLE_AND_LOG2(enc_start, " enc & dec"); fwrite((char*)outbuf, sizeof(short), nsam, fout); printf("frame: %d\n", ++frame); machdep_profile_print_logged_samples(); } #ifdef DUMP dump_off("sm32f4"); #endif fclose(fin); fclose(fout); free(inbuf); free(outbuf); free(bits); codec2_destroy(codec2); }
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; }
int main(int argc, char *argv[]) { 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]; FILE *fin, *fout, *ftotal; int frame, nin_16k, nin, i, nout = 0; struct FDMDV_STATS stats; PROFILE_VAR(fdmdv_16_to_8_start, freedv_rx_start, fdmdv_8_to_16_start); machdep_profile_init(); f = freedv_open(FREEDV_MODE_1600); // Receive --------------------------------------------------------------------- frame = 0; fin = fopen("mod_16k.raw", "rb"); if (fin == NULL) { printf("Error opening input file\n"); exit(1); } fout = fopen("speechout_16k.raw", "wb"); if (fout == NULL) { printf("Error opening output file\n"); exit(1); } ftotal = fopen("total.txt", "wt"); assert(ftotal != NULL); /* 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; nin = freedv_nin(f); nin_16k = 2*nin; nout = nin; while (fread(&adc16k[FDMDV_OS_TAPS_16K], sizeof(short), nin_16k, fin) == nin_16k) { PROFILE_SAMPLE(fdmdv_16_to_8_start); fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], nin); PROFILE_SAMPLE_AND_LOG(freedv_rx_start, fdmdv_16_to_8_start, " fdmdv_16_to_8"); nout = freedv_rx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k); nin = freedv_nin(f); nin_16k = 2*nin; fdmdv_get_demod_stats(f->fdmdv, &stats); PROFILE_SAMPLE_AND_LOG(fdmdv_8_to_16_start, freedv_rx_start, " freedv_rx"); fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], nout); PROFILE_SAMPLE_AND_LOG2(fdmdv_8_to_16_start, " fdmdv_8_to_16"); fprintf(ftotal, "%d\n", machdep_profile_sample() - fdmdv_16_to_8_start); machdep_profile_print_logged_samples(); fwrite(dac16k, sizeof(short), 2*nout, fout); fdmdv_get_demod_stats(f->fdmdv, &stats); printf("frame: %d nin_16k: %d sync: %d SNR: %3.2f \n", ++frame, nin_16k, stats.sync, (double)stats.snr_est); } fclose(fin); fclose(fout); fclose(ftotal); return 0; }