/************************************************************************ * * FILENAME : cdecoder.c * * DESCRIPTION : Main program for speech channel decoding * ************************************************************************ * * USAGE : cdecoder input_file output_file * (Executable_File Input1 Output1) * * INPUT FILE(S) : * * INPUT1 : - Description : channel encoded serial stream * - Format : binary file 16 bit-samples * each 16 bit-sample represents one encoded bit * - 1 channel frame = 432 bits * * OUTPUT FILE(S) : * * OUTPUT1 : - Description : serial stream output file * - Format : binary file 16 bit-samples * each 16 bit-sample represents one encoded bit * - 1 output frame includes 2 speech frames with BFI * = 2 * (137 + 1) = 276 bits * * COMMENTS : - Values of channel encoded samples are * either -127 or +127 * ************************************************************************ * * INCLUDED FILES : channel.h * stdlib.h * ************************************************************************/ /* LIBRARIES USED */ #include #include "channel.h" #ifndef TRUE # define TRUE (1==1) # define FALSE (1==0) #endif static short first_pass = TRUE; static Word16 Frame_stealing = 0; /* Frame Stealing Flag : 0 = Inactive, !0 = First Frame in time-slot stolen This flag is set/reset by external world */ void csdec(Word16 audio[], Word16 Interleaved_coded_array[]) /* 480 432 */ { Word16 i; Word16 bfi1 = 0; Word16 bfi2 = 0; /* Reset Bad Frame Indicator : 0 = correct data, 1 = Corrupted frame */ Word16 Reordered_array[286]; /* 2 frames vocoder + 8 + 4 */ Word16 Coded_array[432]; Word16 Reordered_bfi[138]; /* read Input_array (1 TETRA frame = 2 speech frames) from input file */ if (Frame_stealing) { Desinterleaving_Signalling(Interleaved_coded_array + 216, Coded_array + 216); /* When Frame Stealing occurs, recopy first half slot : */ for (i = 0; i < 216; i++) Coded_array[i] = Interleaved_coded_array[i]; } else Desinterleaving_Speech(Interleaved_coded_array, Coded_array); bfi1 = Frame_stealing; /* "Interleaved_coded_array" has been desinterleaved and result put in "Coded_array" */ /* Message in case the Frame was stolen */ /* if (bfi1) fprintf(stderr,"Frame Nb %ld was stolen\n",Loop_counter+1); */ /* Channel Decoding */ bfi2 = Channel_Decoding(first_pass,Frame_stealing, Coded_array,Reordered_array); first_pass = FALSE; if ((Frame_stealing==0) && (bfi2==1)) bfi1=1; /* Increment Loop counter */ /* Message in case the Bad Frame Indicator was set */ /* if (bfi2) fprintf(stderr,"Frame Nb %ld Bfi active\n\n",Loop_counter); */ /* writing Reordered_array to output file */ Reordered_bfi[0] = bfi1; for (i = 1; i < 138; i++) Reordered_bfi[i] = Reordered_array[i-1]; sdec(&audio[0], Reordered_bfi); Reordered_bfi[0] = bfi2; for (i = 1; i < 138; i++) Reordered_bfi[i] = Reordered_array[i+136]; sdec(&audio[240], Reordered_bfi); }