mirror of
https://github.com/n5ac/smartsdr-dsp.git
synced 2026-01-04 23:50:06 +01:00
Buffering working but decode de-stabilizes to FFs and 00s
This commit is contained in:
parent
aabd5424cb
commit
880581d4ea
|
|
@ -375,54 +375,24 @@ static void* _sched_waveform_thread(void* param)
|
|||
} else {
|
||||
/* Nothing to do since we have not "locked" a bit out yet */
|
||||
}
|
||||
}
|
||||
|
||||
if ( ambe_packet_out == TRUE ) {
|
||||
nout = 0;
|
||||
nout = thumbDV_decode(_dv_serial_fd, ambe_out, speech_out, DV_PACKET_SAMPLES);
|
||||
//if (nout) output(" %d \n", speech_out[i]);
|
||||
for( i=0 ; i < nout ; i++)
|
||||
cbWriteShort(RX3_cb, speech_out[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fdmdv_24_to_8(float_out_8k, &float_in_24k[MEM_24], DV_PACKET_SAMPLES);
|
||||
|
||||
for(i=0 ; i< DV_PACKET_SAMPLES ; i++)
|
||||
{
|
||||
cbWriteShort(RX2_cb, (short) (float_out_8k[i]*SCALE_RX_IN));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// // Check for >= 320 samples in RX2_cb and spin vocoder
|
||||
// Move output to RX3_cb.
|
||||
nin = DV_PACKET_SAMPLES;
|
||||
|
||||
if ( csbContains(RX2_cb) >= nin )
|
||||
{
|
||||
//
|
||||
for( i=0 ; i< nin ; i++)
|
||||
{
|
||||
demod_in[i] = cbReadShort(RX2_cb);
|
||||
}
|
||||
nout = DV_PACKET_SAMPLES;
|
||||
/********* ENCODE *///////////////
|
||||
//nout = freedv_rx(_freedvS, speech_out, demod_in);
|
||||
//
|
||||
//nout = thumbDV_encode(_dv_serial_fd, demod_in, packet_out, nin);
|
||||
//nout = 0;
|
||||
// if (nout == 0 ) {
|
||||
// output("x");
|
||||
// } else {
|
||||
// nout = thumbDV_decode(_dv_serial_fd, packet_out, speech_out, nout);
|
||||
// if (nout == 0 ) output("y");
|
||||
// }
|
||||
//nout = thumbDV_decode(_dv_serial_fd, NULL, speech_out, nout);
|
||||
|
||||
|
||||
for( i=0 ; i < nout ; i++)
|
||||
{
|
||||
//cbWriteShort(RX3_cb, speech_out[i]);
|
||||
cbWriteShort(RX3_cb, demod_in[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Check for >= 128 samples in RX3_cb, convert to floats
|
||||
// and spin the upsampler. Move output to RX4_cb.
|
||||
|
||||
|
|
|
|||
|
|
@ -453,8 +453,10 @@ BOOL dstar_stateMachine(DSTAR_MACHINE machine, BOOL in_bit, unsigned char * ambe
|
|||
BOOL found_end_bits = FALSE;
|
||||
static BOOL header[FEC_SECTION_LENGTH_BITS];
|
||||
static BOOL voice_bits[72];
|
||||
//static BOOL data_bits[(24+72) * 50];
|
||||
static BOOL data_bits[24];
|
||||
|
||||
//unsigned char bytes[((24+72) * 50)/8 + 1];
|
||||
unsigned char bytes[FEC_SECTION_LENGTH_BITS/8 + 1];
|
||||
|
||||
switch(machine->state)
|
||||
|
|
@ -513,9 +515,21 @@ BOOL dstar_stateMachine(DSTAR_MACHINE machine, BOOL in_bit, unsigned char * ambe
|
|||
|
||||
if ( machine->bit_count == VOICE_FRAME_LENGTH_BITS ) {
|
||||
gmsk_bitsToBytes(voice_bits, bytes, VOICE_FRAME_LENGTH_BITS);
|
||||
thumbDV_dump("Voice Frame:", bytes, VOICE_FRAME_LENGTH_BITS / 8);
|
||||
memcpy(ambe_out, bytes, VOICE_FRAME_LENGTH_BITS / 8);
|
||||
have_audio_packet = TRUE;
|
||||
//thumbDV_dump("Voice Frame:", bytes, VOICE_FRAME_LENGTH_BITS / 8);
|
||||
|
||||
uint32 f_count = 0;
|
||||
uint32 i = 0;
|
||||
for ( i = 0 ; i < 9 ; i++ ) {
|
||||
if ( bytes[i] == 0xFF )
|
||||
f_count++;
|
||||
}
|
||||
|
||||
if ( f_count < 2 ) {
|
||||
memcpy(ambe_out, bytes, VOICE_FRAME_LENGTH_BITS / 8);
|
||||
have_audio_packet = TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* STATE CHANGE */
|
||||
if ( machine->frame_count % 21 == 0 ) {
|
||||
|
|
@ -538,7 +552,7 @@ BOOL dstar_stateMachine(DSTAR_MACHINE machine, BOOL in_bit, unsigned char * ambe
|
|||
machine->bit_count = 0;
|
||||
} else if ( machine->bit_count == DATA_FRAME_LENGTH_BITS ) {
|
||||
gmsk_bitsToBytes(data_bits, bytes, DATA_FRAME_LENGTH_BITS);
|
||||
thumbDV_dump("Data Frame:", bytes, DATA_FRAME_LENGTH_BITS/8);
|
||||
//thumbDV_dump("Data Frame:", bytes, DATA_FRAME_LENGTH_BITS/8);
|
||||
|
||||
machine->frame_count++;
|
||||
|
||||
|
|
@ -566,7 +580,7 @@ BOOL dstar_stateMachine(DSTAR_MACHINE machine, BOOL in_bit, unsigned char * ambe
|
|||
} else if ( found_end_bits ) {
|
||||
machine->state = END_PATTERN_FOUND;
|
||||
machine->bit_count = 0;
|
||||
} else if ( machine->bit_count > 25 * 2 ) {
|
||||
} else if ( machine->bit_count > ((24+72) * 42) ) {
|
||||
/* Function as a timeout if we don't find the sync bits */
|
||||
output("Could not find SYNC\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@
|
|||
static pthread_t _read_thread;
|
||||
BOOL _readThreadAbort = FALSE;
|
||||
|
||||
static uint32 _buffering_target = 10;
|
||||
static uint32 _buffering_target = 4;
|
||||
|
||||
static pthread_rwlock_t _encoded_list_lock;
|
||||
static BufferDescriptor _encoded_root;
|
||||
|
|
@ -167,11 +167,13 @@ static BufferDescriptor _thumbDVDecodedList_UnlinkHead(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if(_decoded_root->next != _decoded_root)
|
||||
if(_decoded_root->next != _decoded_root) {
|
||||
buf_desc = _decoded_root->next;
|
||||
}
|
||||
|
||||
if(buf_desc != NULL)
|
||||
{
|
||||
//output("0");
|
||||
// make sure buffer exists and is actually linked
|
||||
if(!buf_desc || !buf_desc->prev || !buf_desc->next)
|
||||
{
|
||||
|
|
@ -187,7 +189,8 @@ static BufferDescriptor _thumbDVDecodedList_UnlinkHead(void)
|
|||
if ( _decoded_count > 0 ) _decoded_count--;
|
||||
}
|
||||
} else {
|
||||
if ( !_decoded_buffering ) output("DecodedList now Buffering \n");
|
||||
if ( !_decoded_buffering )
|
||||
output("DecodedList now Buffering \n");
|
||||
_decoded_buffering = TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +382,7 @@ int thumbDV_processSerial(int serial_fd)
|
|||
packet_type = buffer[3];
|
||||
//dump("Serial data", buffer, respLen);
|
||||
if ( packet_type == AMBE3000_CTRL_PKT_TYPE ) {
|
||||
thumbDV_dump("Serial data", buffer, respLen);
|
||||
thumbDV_dump(ANSI_YELLOW "Serial data" ANSI_WHITE, buffer, respLen);
|
||||
} else if ( packet_type == AMBE3000_CHAN_PKT_TYPE ) {
|
||||
desc = hal_BufferRequest(respLen, sizeof(unsigned char) );
|
||||
memcpy(desc->buf_ptr, buffer, respLen);
|
||||
|
|
@ -389,7 +392,7 @@ int thumbDV_processSerial(int serial_fd)
|
|||
} else if ( packet_type == AMBE3000_SPEECH_PKT_TYPE ) {
|
||||
desc = hal_BufferRequest(respLen, sizeof(unsigned char));
|
||||
memcpy(desc->buf_ptr, buffer, respLen);
|
||||
//dump("SPEECH Packet", buffer, respLen);
|
||||
thumbDV_dump("SPEECH Packet", buffer, respLen);
|
||||
/* Speech data */
|
||||
_thumbDVDecodedList_LinkTail(desc);
|
||||
|
||||
|
|
@ -406,19 +409,22 @@ int thumbDV_decode(int serial_fd, unsigned char * packet_in, short * speech_out,
|
|||
{
|
||||
uint32 i = 0;
|
||||
unsigned char full_packet[15] = {0};
|
||||
full_packet[0] = 0x61;
|
||||
full_packet[1] = 0x00;
|
||||
full_packet[2] = 0x0B;
|
||||
full_packet[3] = 0x01;
|
||||
full_packet[4] = 0x01;
|
||||
full_packet[5] = 0x48;
|
||||
for ( i = 0 ; i < 9 ; i++ ) {
|
||||
full_packet[i+6] = packet_in[i];
|
||||
if ( packet_in != NULL ) {
|
||||
full_packet[0] = 0x61;
|
||||
full_packet[1] = 0x00;
|
||||
full_packet[2] = 0x0B;
|
||||
full_packet[3] = 0x01;
|
||||
full_packet[4] = 0x01;
|
||||
full_packet[5] = 0x48;
|
||||
for ( i = 0 ; i < 9 ; i++ ) {
|
||||
full_packet[i+6] = packet_in[i];
|
||||
}
|
||||
|
||||
thumbDV_dump("Encoded packet:", full_packet, 15);
|
||||
thumbDV_writeSerial(serial_fd, full_packet, 15);
|
||||
usleep(1000 * 10);
|
||||
}
|
||||
|
||||
thumbDV_writeSerial(serial_fd, full_packet, 15);
|
||||
|
||||
|
||||
int32 samples_returned = 0;
|
||||
BufferDescriptor desc = _thumbDVDecodedList_UnlinkHead();
|
||||
uint32 samples_in_speech_packet = 0;
|
||||
|
|
@ -609,8 +615,8 @@ void thumbDV_init(const char * serial_device_name, int * serial_fd)
|
|||
unsigned char pkt_compand[6] = { 0x61, 0x00, 0x02, 0x00, 0x32, 0x00 };
|
||||
thumbDV_writeSerial(*serial_fd, pkt_compand, 6);
|
||||
|
||||
unsigned char test_coded[15] = {0x61, 0x00 ,0x0B ,0x01 ,0x01 ,0x48 ,0x5E ,0x83 ,0x12 ,0x3B ,0x98 ,0x79 ,0xDE ,0x13 ,0x90};
|
||||
//unsigned char test_coded[15] = {0x61, 0x00 ,0x0B ,0x01 ,0x01 ,0x48 ,0x5E ,0x83 ,0x12 ,0x3B ,0x98 ,0x79 ,0xDE ,0x13 ,0x90};
|
||||
|
||||
thumbDV_writeSerial(*serial_fd, test_coded, 15);
|
||||
//thumbDV_writeSerial(*serial_fd, test_coded, 15);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue