From 524891c602d286e79df43d39619ae978b842d609 Mon Sep 17 00:00:00 2001 From: Ed Gonzalez Date: Thu, 18 Jun 2015 16:07:09 -0500 Subject: [PATCH] Transmit working with NFM TX --- DSP_API/SmartSDR_Interface/sched_waveform.c | 153 ++++++++++++-------- DSP_API/ThumbDV/DStarDefines.h | 4 +- DSP_API/ThumbDV/dstar.c | 18 ++- DSP_API/ThumbDV/gmsk_modem.c | 48 ++---- DSP_API/ThumbDV/gmsk_modem.h | 2 - DSP_API/ThumbDV/thumbDV.c | 8 +- DSP_API/circular_buffer.c | 9 +- DSP_API/circular_buffer.h | 2 + 8 files changed, 134 insertions(+), 110 deletions(-) diff --git a/DSP_API/SmartSDR_Interface/sched_waveform.c b/DSP_API/SmartSDR_Interface/sched_waveform.c index 39c3755..ac335f0 100644 --- a/DSP_API/SmartSDR_Interface/sched_waveform.c +++ b/DSP_API/SmartSDR_Interface/sched_waveform.c @@ -177,12 +177,12 @@ void sched_waveform_signal() float RX1_buff[(DV_PACKET_SAMPLES * 12)+1]; // RX1 Packet Input Buffer short RX2_buff[(DV_PACKET_SAMPLES * 12)+1]; // RX2 Vocoder input buffer short RX3_buff[(DV_PACKET_SAMPLES * 12)+1]; // RX3 Vocoder output buffer -float RX4_buff[(DV_PACKET_SAMPLES * 12)+1]; // RX4 Packet output Buffer +float RX4_buff[(DV_PACKET_SAMPLES * 12 * 40)+1]; // RX4 Packet output Buffer float TX1_buff[(DV_PACKET_SAMPLES * 12) +1]; // TX1 Packet Input Buffer short TX2_buff[(DV_PACKET_SAMPLES * 12)+1]; // TX2 Vocoder input buffer short TX3_buff[(DV_PACKET_SAMPLES * 12)+1]; // TX3 Vocoder output buffer -float TX4_buff[(DV_PACKET_SAMPLES * 12 * 10)+1]; // TX4 Packet output Buffer +float TX4_buff[(DV_PACKET_SAMPLES * 12 * 40)+1]; // TX4 Packet output Buffer circular_float_buffer rx1_cb; Circular_Float_Buffer RX1_cb = &rx1_cb; @@ -208,11 +208,17 @@ static GMSK_DEMOD _gmsk_demod = NULL; static GMSK_MOD _gmsk_mod = NULL; static DSTAR_MACHINE _dstar = NULL; -static BOOL write_dat = TRUE; -static uint32 data_i = 0; - #define FREEDV_NSAMPLES 160 +static void icom_byteToBits(unsigned char byte, BOOL * bits ) +{ + unsigned char mask = 0x01; + uint32 i = 0; + for ( i = 0 ; i < 8 ; i++, mask <<= 1 ) { + bits[i] = ( byte & mask ) ? TRUE : FALSE; + } +} + static void* _sched_waveform_thread(void* param) { int nout; @@ -226,10 +232,10 @@ static void* _sched_waveform_thread(void* param) int initial_rx = 1; // Flags for RX circular buffer, clear if starting receive // VOCODER I/O BUFFERS - short speech_in[FREEDV_NSAMPLES]; - short speech_out[FREEDV_NSAMPLES]; + short speech_in[DV_PACKET_SAMPLES]; + short speech_out[DV_PACKET_SAMPLES]; //short demod_in[FREEDV_NSAMPLES]; - short mod_out[FREEDV_NSAMPLES]; + unsigned char mod_out[DV_PACKET_SAMPLES]; //unsigned char packet_out[FREEDV_NSAMPLES]; @@ -245,8 +251,6 @@ static void* _sched_waveform_thread(void* param) float tx_float_out_8k[DV_PACKET_SAMPLES]; float tx_float_in_24k[DV_PACKET_SAMPLES * DECIMATION_FACTOR + FILTER_TAPS]; - float tx_float_out_24k[DV_PACKET_SAMPLES * DECIMATION_FACTOR ]; - // ======================= Initialization Section ========================= @@ -254,44 +258,59 @@ static void* _sched_waveform_thread(void* param) thumbDV_init("/dev/ttyUSB0", &_dv_serial_fd); // Initialize the Circular Buffers - - RX1_cb->size = PACKET_SAMPLES*6 +1; // size = no.elements in array+1 + RX1_cb->size = DV_PACKET_SAMPLES * 12 +1; // size = no.elements in array+1 RX1_cb->start = 0; RX1_cb->end = 0; RX1_cb->elems = RX1_buff; - RX2_cb->size = PACKET_SAMPLES*6 +1; // size = no.elements in array+1 + strncpy(RX1_cb->name, "RX1", 4); + + RX2_cb->size = DV_PACKET_SAMPLES * 12 +1; // size = no.elements in array+1 RX2_cb->start = 0; RX2_cb->end = 0; RX2_cb->elems = RX2_buff; - RX3_cb->size = PACKET_SAMPLES*6 +1; // size = no.elements in array+1 + strncpy(RX2_cb->name, "RX2", 4); + + RX3_cb->size = DV_PACKET_SAMPLES * 12 +1; // size = no.elements in array+1 RX3_cb->start = 0; RX3_cb->end = 0; RX3_cb->elems = RX3_buff; - RX4_cb->size = PACKET_SAMPLES*12 +1; // size = no.elements in array+1 + strncpy(RX3_cb->name, "RX3", 4); + + RX4_cb->size = DV_PACKET_SAMPLES*(12*40) +1; // size = no.elements in array+1 RX4_cb->start = 0; RX4_cb->end = 0; RX4_cb->elems = RX4_buff; + strncpy(RX4_cb->name, "RX4", 4); - TX1_cb->size = PACKET_SAMPLES*6 +1; // size = no.elements in array+1 + TX1_cb->size = DV_PACKET_SAMPLES * 12 +1; // size = no.elements in array+1 TX1_cb->start = 0; TX1_cb->end = 0; TX1_cb->elems = TX1_buff; - TX2_cb->size = PACKET_SAMPLES*6 +1; // size = no.elements in array+1 + strncpy(TX1_cb->name, "TX1", 4); + + TX2_cb->size = DV_PACKET_SAMPLES * 12 +1; // size = no.elements in array+1 TX2_cb->start = 0; TX2_cb->end = 0; TX2_cb->elems = TX2_buff; - TX3_cb->size = PACKET_SAMPLES *6 +1; // size = no.elements in array+1 + strncpy(TX2_cb->name, "TX2", 4); + + TX3_cb->size = DV_PACKET_SAMPLES * 12 +1; // size = no.elements in array+1 TX3_cb->start = 0; TX3_cb->end = 0; TX3_cb->elems = TX3_buff; - TX4_cb->size = PACKET_SAMPLES * (12*10) +1; // size = no.elements in array+1 + strncpy(TX3_cb->name, "TX3", 4); + + TX4_cb->size = DV_PACKET_SAMPLES * (12*40) +1; // size = no.elements in array+1 TX4_cb->start = 0; TX4_cb->end = 0; TX4_cb->elems = TX4_buff; + strncpy(TX4_cb->name, "TX4", 4); initial_tx = TRUE; initial_rx = TRUE; + uint32 dstar_tx_frame_count = 0; + // show that we are running BufferDescriptor buf_desc; @@ -343,7 +362,6 @@ static void* _sched_waveform_thread(void* param) // Set the transmit 'initial' flag initial_tx = TRUE; - write_dat = TRUE; // Check for new receiver input packet & move to RX1_cb. // TODO - If transmit packet, discard here? @@ -412,26 +430,19 @@ static void* _sched_waveform_thread(void* param) uint32 check_samples = PACKET_SAMPLES; - if(initial_rx) - check_samples = PACKET_SAMPLES * 3; - - if(cfbContains(RX4_cb) >= check_samples ) { for( i=0 ; i< PACKET_SAMPLES ; i++) { - //output("Fetching from end buffer \n"); // Set up the outbound packet fsample = cbReadFloat(RX4_cb); // // put the fsample into the outbound packet -// + ((Complex*)buf_desc->buf_ptr)[i].real = fsample; ((Complex*)buf_desc->buf_ptr)[i].imag = fsample; } } else { - //output("RX Starved buffer out\n"); - memset( buf_desc->buf_ptr, 0, PACKET_SAMPLES * sizeof(Complex)); if(initial_rx) @@ -496,7 +507,7 @@ static void* _sched_waveform_thread(void* param) // // Check for >= 320 samples in TX2_cb and spin vocoder // Move output to TX3_cb. - + uint32 decode_out = 0; if ( csbContains(TX2_cb) >= DV_PACKET_SAMPLES ) { for( i=0 ; i< DV_PACKET_SAMPLES ; i++) @@ -504,25 +515,19 @@ static void* _sched_waveform_thread(void* param) speech_in[i] = cbReadShort(TX2_cb); } - //output("Speech in = %d", speech_in[0]); - /* DECODE */ - uint32 decode_out = 0; - decode_out = thumbDV_encode(_dv_serial_fd, speech_in, (unsigned char * )mod_out, DV_PACKET_SAMPLES); + decode_out = thumbDV_encode(_dv_serial_fd, speech_in, mod_out, DV_PACKET_SAMPLES); } - FILE * dat = NULL; - - if ( write_dat ) { - dat = fopen("gmsk_txNew2.dat", "a"); - } + float buf[5]; + uint32 j = 0; if ( initial_tx ) { initial_tx = FALSE; - float buf[5]; - uint32 j = 0; + zero_cfb(TX4_cb); + /* Create Sync */ - for ( i = 0 ; i < 64 * 2 ; i += 2 ) { + for ( i = 0 ; i < 64 * 10 ; i += 2 ) { gmsk_encode(_gmsk_mod, TRUE, buf, DSTAR_RADIO_BIT_LENGTH); for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) { @@ -544,8 +549,6 @@ static void* _sched_waveform_thread(void* param) } } -// fclose(dat); - dstar_header tmp_h; tmp_h.flag1 = 0; tmp_h.flag2 = 0; @@ -588,16 +591,51 @@ static void* _sched_waveform_thread(void* param) } } - for ( i = 0 ; i < 10 ; i += 2 ) { - gmsk_encode(_gmsk_mod, FALSE, buf, DSTAR_RADIO_BIT_LENGTH); - for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) { - cbWriteFloat(TX4_cb, buf[j]); - } - gmsk_encode(_gmsk_mod, TRUE, buf, DSTAR_RADIO_BIT_LENGTH); - for ( j = 0 ; j < DSTAR_RADIO_BIT_LENGTH ; j++ ) { - cbWriteFloat(TX4_cb, buf[j]); + dstar_tx_frame_count = 0; + } else { + /* Data and Voice */ + float voice_buf[VOICE_FRAME_LENGTH_BITS * DSTAR_RADIO_BIT_LENGTH] = {0}; + float data_buf[DATA_FRAME_LENGTH_BITS * DSTAR_RADIO_BIT_LENGTH] = {0}; + + if ( decode_out != 0 ) { + BOOL bits[8] = {0} ; + uint32 k = 0; + for ( i = 0 ; i < VOICE_FRAME_LENGTH_BYTES ; i++ ) { + icom_byteToBits(mod_out[i], bits ); + for ( j = 0 ; j < 8 ; j++ ) { + gmsk_encode(_gmsk_mod, bits[j], buf, DSTAR_RADIO_BIT_LENGTH); + + for ( k = 0 ; k < DSTAR_RADIO_BIT_LENGTH ; k++ ) { + cbWriteFloat(TX4_cb, buf[k]); + } + } } + if ( dstar_tx_frame_count % 21 == 0 ) { + /* Sync Bits */ + unsigned char sync_bytes[3] = {0}; + memcpy(sync_bytes, DATA_SYNC_BYTES, 3); + gmsk_encodeBuffer(_gmsk_mod, sync_bytes, DATA_FRAME_LENGTH_BITS, data_buf, DATA_FRAME_LENGTH_BITS * DSTAR_RADIO_BIT_LENGTH); + + for ( i = 0 ; i < DATA_FRAME_LENGTH_BITS * DSTAR_RADIO_BIT_LENGTH ; i++ ) { + cbWriteFloat(TX4_cb, data_buf[i]); + } + } else { + unsigned char dummy_bytes[DATA_FRAME_LENGTH_BYTES] = {0xFF, 0x00, 0xFF }; + BOOL dummy_bits[DATA_FRAME_LENGTH_BITS] = {0}; + BOOL dummy_bits_out[DATA_FRAME_LENGTH_BITS] = {0}; + uint32 dummy_count = 0; + gmsk_bytesToBits(dummy_bytes, dummy_bits, DATA_FRAME_LENGTH_BITS); + dstar_scramble(dummy_bits, dummy_bits_out, DATA_FRAME_LENGTH_BITS, &dummy_count); + + gmsk_bitsToBytes(dummy_bits_out, dummy_bytes, DATA_FRAME_LENGTH_BITS); + + gmsk_encodeBuffer(_gmsk_mod, dummy_bytes, DATA_FRAME_LENGTH_BITS, data_buf, DATA_FRAME_LENGTH_BITS * DSTAR_RADIO_BIT_LENGTH); + for ( i = 0 ; i < DATA_FRAME_LENGTH_BITS * DSTAR_RADIO_BIT_LENGTH ; i++ ) { + cbWriteFloat(TX4_cb, data_buf[i]); + } + } + dstar_tx_frame_count++; } } @@ -608,7 +646,6 @@ static void* _sched_waveform_thread(void* param) { for( i = 0 ; i < PACKET_SAMPLES ; i++) { - //output("Fetching from end buffer \n"); // Set up the outbound packet fsample = cbReadFloat(TX4_cb); @@ -617,18 +654,13 @@ static void* _sched_waveform_thread(void* param) ((Complex*)buf_desc->buf_ptr)[i].imag = fsample; } } else { - //output("TX Starved buffer out\n"); - memset( buf_desc->buf_ptr, 0, PACKET_SAMPLES * sizeof(Complex)); - - } initial_tx = FALSE; } - emit_waveform_output(buf_desc); hal_BufferRelease(&buf_desc); @@ -640,14 +672,13 @@ static void* _sched_waveform_thread(void* param) gmsk_destroyDemodulator(_gmsk_demod); gmsk_destroyModulator(_gmsk_mod); + dstar_destroyMachine(_dstar); return NULL; } void sched_waveform_Init(void) { - //dstar_FECTest(); - //exit(0); _dstar = dstar_createMachine(); @@ -671,10 +702,6 @@ void sched_waveform_Init(void) struct sched_param fifo_param; fifo_param.sched_priority = 30; pthread_setschedparam(_waveform_thread, SCHED_FIFO, &fifo_param); - -// gmsk_testBitsAndEncodeDecode(); -// exit(0); - } void sched_waveformThreadExit() diff --git a/DSP_API/ThumbDV/DStarDefines.h b/DSP_API/ThumbDV/DStarDefines.h index 64f947d..521aee5 100644 --- a/DSP_API/ThumbDV/DStarDefines.h +++ b/DSP_API/ThumbDV/DStarDefines.h @@ -29,7 +29,9 @@ static const BOOL FRAME_SYNC_BITS[] = {TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE}; #define FRAME_SYNC_LENGTH_BITS 15U -static const unsigned char DATA_SYNC_BYTES[] = {0x55, 0x2D, 0x16}; +//static const unsigned char DATA_SYNC_BYTES[] = {0x55, 0x2D, 0x16}; +static const unsigned char DATA_SYNC_BYTES[] = {0xAA, 0xB4, 0x68}; + static const BOOL DATA_SYNC_BITS[] = {TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE}; diff --git a/DSP_API/ThumbDV/dstar.c b/DSP_API/ThumbDV/dstar.c index e89148c..d07ec8e 100644 --- a/DSP_API/ThumbDV/dstar.c +++ b/DSP_API/ThumbDV/dstar.c @@ -546,6 +546,8 @@ BOOL dstar_stateMachine(DSTAR_MACHINE machine, BOOL in_bit, unsigned char * ambe BOOL * voice_bits = machine->voice_bits; BOOL * data_bits = machine->data_bits; + static unsigned char data_bytes[3 * 40] = {0}; + static uint32 long_data_bytes_idx = 0; //unsigned char bytes[((24+72) * 50)/8 + 1]; unsigned char bytes[FEC_SECTION_LENGTH_BITS/8 + 1]; @@ -665,8 +667,20 @@ BOOL dstar_stateMachine(DSTAR_MACHINE machine, BOOL in_bit, unsigned char * ambe uint32 scramble_count = 0; dstar_scramble(data_bits, out, DATA_FRAME_LENGTH_BITS, &scramble_count); - gmsk_bitsToBytes(out, bytes, DATA_FRAME_LENGTH_BITS); - //thumbDV_dump("Data Frame:", bytes, DATA_FRAME_LENGTH_BITS/8); + //gmsk_bitsToBytes(out, bytes, DATA_FRAME_LENGTH_BITS); + uint32 i = 0 ; + uint32 n = 0; + for ( i = 0, n = 0 ; i < DATA_FRAME_LENGTH_BYTES ; i++, n += 8 ) { + bytes[i] = icom_bitsToByte(out + n); + } + //thumbDV_dump("Data Frame:", bytes, DATA_FRAME_LENGTH_BYTES); + + memcpy(data_bytes + long_data_bytes_idx, bytes, 3); + long_data_bytes_idx += 3; + if ( long_data_bytes_idx >= 3 * 40 ) { + thumbDV_dump("Long Data: ", data_bytes, 3 * 40); + long_data_bytes_idx = 0; + } machine->frame_count++; diff --git a/DSP_API/ThumbDV/gmsk_modem.c b/DSP_API/ThumbDV/gmsk_modem.c index ccadb40..8c0373d 100644 --- a/DSP_API/ThumbDV/gmsk_modem.c +++ b/DSP_API/ThumbDV/gmsk_modem.c @@ -153,37 +153,6 @@ void gmsk_FilterProcessBuffer(FIR_FILTER filter, float * buffer, uint32 buffer_l /* Demod Section */ -const float DEMOD_COEFFS_TABLE[] = { - /* 2400 Hz */ - -0.000153959924563F, 0.000000000000000F, 0.000167227768379F, 0.000341615513437F, - 0.000513334449696F, 0.000667493753523F, 0.000783901543032F, 0.000838293462576F, - 0.000805143268199F, 0.000661865814384F, 0.000393913058926F, -0.000000000000000F, - -0.000503471198655F, -0.001079755887508F, -0.001671728086040F, -0.002205032425392F, - -0.002594597675000F, -0.002754194565297F, -0.002608210441859F, -0.002104352817854F, - -0.001225654870420F, 0.000000000000000F, 0.001494548041184F, 0.003130012785731F, - 0.004735238379172F, 0.006109242742194F, 0.007040527007323F, 0.007330850462455F, - 0.006821247169795F, 0.005417521811131F, 0.003112202160626F, -0.000000000000000F, - -0.003715739376345F, -0.007727358782391F, -0.011638713107503F, -0.014992029537478F, - -0.017304097563429F, -0.018108937286588F, -0.017003180218569F, -0.013689829477969F, - -0.008015928769710F, 0.000000000000000F, 0.010154104792614F, 0.022059114281395F, - 0.035162729807337F, 0.048781621388364F, 0.062148583345584F, 0.074469032280094F, - 0.084982001723750F, 0.093020219991183F, 0.098063819576269F, 0.099782731268437F, - 0.098063819576269F, 0.093020219991183F, 0.084982001723750F, 0.074469032280094F, - 0.062148583345584F, 0.048781621388364F, 0.035162729807337F, 0.022059114281395F, - 0.010154104792614F, 0.000000000000000F, -0.008015928769710F, -0.013689829477969F, - -0.017003180218569F, -0.018108937286588F, -0.017304097563429F, -0.014992029537478F, - -0.011638713107503F, -0.007727358782391F, -0.003715739376345F, -0.000000000000000F, - 0.003112202160626F, 0.005417521811131F, 0.006821247169795F, 0.007330850462455F, - 0.007040527007323F, 0.006109242742194F, 0.004735238379172F, 0.003130012785731F, - 0.001494548041184F, 0.000000000000000F, -0.001225654870420F, -0.002104352817854F, - -0.002608210441859F, -0.002754194565297F, -0.002594597675000F, -0.002205032425392F, - -0.001671728086040F, -0.001079755887508F, -0.000503471198655F, -0.000000000000000F, - 0.000393913058926F, 0.000661865814384F, 0.000805143268199F, 0.000838293462576F, - 0.000783901543032F, 0.000667493753523F, 0.000513334449696F, 0.000341615513437F, - 0.000167227768379F, 0.000000000000000F, -0.000153959924563F}; - -#define DEMOD_COEFFS_LENGTH 103U - #define PLLMAX 0x10000U #define PLLINC ( PLLMAX / DSTAR_RADIO_BIT_LENGTH) // 2000 #define INC 32U @@ -290,7 +259,15 @@ const float MOD_COEFFS_TABLE[] = { 8.959797186410563e-007F, 1.310626978701910e-007F, 1.662729407135958e-008F, 1.829471305298363e-009F, 1.745786683011426e-010F, 1.444835156335356e-011F, 1.037067381285011e-012F, 6.455906007234699e-014F}; - +//const float MOD_COEFFS_TABLE[] = { +//1.29118120144693e-13 , 2.88967031267067e-11 , 3.65894261059670e-09 , +//2.62125395740380e-07 , 1.06245073266055e-05 , 0.000243643428039817 , +//0.00316116236025481 ,0.0232051886177988 , 0.0963761566612471 , +//0.226464589054119 , 0.301076739115701 , 0.226464589054118 , +//0.0963761566612471 , 0.0232051886177988 , 0.00316116236025481 , +//0.000243643428039817 , 1.06245073266054e-05 , 2.62125395740380e-07, +//3.65894261059670e-09 , 2.88967031267069e-11 ,1.29118120144693e-13 +//}; #define MOD_COEFFS_LENGTH 41U uint32 gmsk_encode(GMSK_MOD mod, BOOL bit, float * buffer, unsigned int length) @@ -307,9 +284,9 @@ uint32 gmsk_encode(GMSK_MOD mod, BOOL bit, float * buffer, unsigned int length) for (i = 0; i < DSTAR_RADIO_BIT_LENGTH; i++) { if (bit) { - buffer[i] = gmsk_FilterProcessSingle(mod->filter, -1.0f); + buffer[i] = gmsk_FilterProcessSingle(mod->filter, -0.45f); } else { - buffer[i] = gmsk_FilterProcessSingle(mod->filter, 1.0f); + buffer[i] = gmsk_FilterProcessSingle(mod->filter, 0.45f); } } @@ -376,8 +353,6 @@ GMSK_DEMOD gmsk_createDemodulator(void) demod->m_prev = FALSE; demod->m_invert = FALSE; - demod->filter = gmsk_createFilter(DEMOD_COEFFS_TABLE, DEMOD_COEFFS_LENGTH); - return demod; } @@ -398,7 +373,6 @@ void gmsk_destroyDemodulator(GMSK_DEMOD demod ) return; } - gmsk_destroyFilter(demod->filter); safe_free(demod); } diff --git a/DSP_API/ThumbDV/gmsk_modem.h b/DSP_API/ThumbDV/gmsk_modem.h index d70bf64..149c468 100644 --- a/DSP_API/ThumbDV/gmsk_modem.h +++ b/DSP_API/ThumbDV/gmsk_modem.h @@ -48,8 +48,6 @@ typedef struct _gmsk_demod uint32 m_pll; BOOL m_prev; BOOL m_invert; - - FIR_FILTER filter; } gmsk_demod, * GMSK_DEMOD; typedef struct _gmsk_mod diff --git a/DSP_API/ThumbDV/thumbDV.c b/DSP_API/ThumbDV/thumbDV.c index 669d3b2..08aa6b2 100644 --- a/DSP_API/ThumbDV/thumbDV.c +++ b/DSP_API/ThumbDV/thumbDV.c @@ -508,12 +508,14 @@ int thumbDV_encode(int serial_fd, short * speech_in, unsigned char * packet_out, thumbDV_writeSerial(serial_fd, packet, length + AMBE3000_HEADER_LEN); int32 samples_returned = 0; - BufferDescriptor desc = NULL;//_thumbDVEncodedList_UnlinkHead(); + BufferDescriptor desc = _thumbDVEncodedList_UnlinkHead(); if ( desc != NULL ) { - memcpy(packet_out, desc->buf_ptr, desc->sample_size * desc->num_samples); - samples_returned = desc->num_samples; + memcpy(packet_out, desc->buf_ptr + 6, desc->sample_size * (desc->num_samples - 6) ); + samples_returned = desc->num_samples - 6; safe_free(desc); + //thumbDV_dump(ANSI_BLUE "Coded Packet" ANSI_WHITE, packet_out, desc->num_samples - 6); + } else { /* Do nothing for now */ } diff --git a/DSP_API/circular_buffer.c b/DSP_API/circular_buffer.c index 503daf4..97fd08a 100644 --- a/DSP_API/circular_buffer.c +++ b/DSP_API/circular_buffer.c @@ -65,6 +65,7 @@ #include #include "circular_buffer.h" +#include "utils.h" @@ -102,8 +103,10 @@ void cbWriteFloat(Circular_Float_Buffer cb, float sample) { cb->elems[cb->end] = sample; cb->end = (cb->end + 1) % cb->size; - if (cb->end == cb->start) + if (cb->end == cb->start) { cb->start = (cb->start + 1) % cb->size; /* full, overwrite */ + output(ANSI_RED "Overwrite! in Circular Float Buffer - Name %s\n" ANSI_WHITE, cb->name); + } } @@ -194,8 +197,10 @@ void cbWriteShort(Circular_Short_Buffer cb, short sample) { cb->elems[cb->end] = sample; cb->end = (cb->end + 1) % cb->size; - if (cb->end == cb->start) + if (cb->end == cb->start) { cb->start = (cb->start + 1) % cb->size; /* full, overwrite */ + output(ANSI_RED "Overwrite! in Circular Short Buffer - Name %s\n" ANSI_WHITE, cb->name); + } } diff --git a/DSP_API/circular_buffer.h b/DSP_API/circular_buffer.h index dcdcb34..46451c2 100644 --- a/DSP_API/circular_buffer.h +++ b/DSP_API/circular_buffer.h @@ -37,6 +37,7 @@ typedef struct { unsigned int start; // Index of oldest element unsigned int end; // Index at which to write new element short *elems; // Vector of elements + char name[20]; } circular_short_buffer, *Circular_Short_Buffer; typedef struct { @@ -44,6 +45,7 @@ typedef struct { unsigned int start; // Index of oldest element unsigned int end; // Index at which to write new element float *elems; // Vector of elements + char name[20]; } circular_float_buffer, *Circular_Float_Buffer;