fixe network byte ordering, change audio dump to dumep 16 bit samples

This commit is contained in:
Geoffrey Merck 2020-05-30 19:59:15 +02:00
parent 0b8a9a1a4c
commit 75d5083f8e
2 changed files with 7 additions and 8 deletions

View file

@ -118,21 +118,20 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length)
samples[i] = m_filterStage3->filter(m_filterStage2->filter(m_filterStage1->filter(samples[i])));
}
#if defined(DUMP_RF_AUDIO)
if(audiofile != NULL)
fwrite(samples, sizeof(float), nSamples, audiofile);
#endif
unsigned short out[170U]; // 85 * 2
unsigned int nOut = 0U;
// Repack the data (8-bit unsigned values containing unsigned 16-bit data)
for (unsigned int i = 0U; i < nSamples; i++) {
unsigned short sample = (unsigned short)((samples[i] + 1.0F) * 32767.0F + 0.5F);
out[nOut++] = (sample >> 8) & 0xFFU;
out[nOut++] = (sample >> 0) & 0xFFU;
out[nOut++] = ((sample >> 8) & 0x00FFU) | ((sample << 8) & 0xFF00U);//change endianess to network order, transmit MSB first
}
#if defined(DUMP_RF_AUDIO)
if(audiofile != NULL)
fwrite(out, sizeof(unsigned short), nOut, audiofile);
#endif
#if defined(DUMP_RF_AUDIO)
if(audiofile != NULL)
fclose(audiofile);

View file

@ -25,7 +25,7 @@
// Uncomment this to dump audio to a raw audio file
// The file will be written in same folder as executable
// Toplay the file : aplay -f FLOAT_LE -c1 -r8000 -t raw audiodump.bin
// Toplay the file : ffplay -autoexit -f u16be -ar 8000 audiodump.bin
// #define DUMP_RF_AUDIO
class CFMControl {