diff --git a/FMControl.cpp b/FMControl.cpp index c07c8d4..9a2a78a 100644 --- a/FMControl.cpp +++ b/FMControl.cpp @@ -136,9 +136,8 @@ unsigned int CFMControl::readModem(unsigned char* data, unsigned int space) if (space > 252U) space = 252U; - unsigned short netData[168U]; // Modem can handle up to 168 samples at a time - unsigned int length = m_network->read((unsigned char*)netData, 168U * sizeof(unsigned short)); - length /= sizeof(unsigned short); + float netData[168U]; // Modem can handle up to 168 samples at a time + unsigned int length = m_network->read(netData, 168U); if (length == 0U) return 0U; @@ -147,13 +146,8 @@ unsigned int CFMControl::readModem(unsigned char* data, unsigned int space) unsigned int nData = 0U; for (unsigned int i = 0; i < length; i++) { - unsigned short netSample = SWAP_BYTES_16(netData[i]); - - // Convert the unsigned 16-bit data (+65535 - 0) to float (+1.0 - -1.0) - float sampleFloat = (float(netSample) / 32768.0F) - 1.0F; - - //preemphasis - sampleFloat = m_preemphasis->filter(sampleFloat); + // Pre-emphasis + float sampleFloat = m_preemphasis->filter(netData[i]); // Convert float to 12-bit samples (0 to 4095) unsigned int sample12bit = (unsigned int)((sampleFloat + 1.0F) * 2048.0F + 0.5F); diff --git a/FMNetwork.cpp b/FMNetwork.cpp index afc2014..fd13df4 100644 --- a/FMNetwork.cpp +++ b/FMNetwork.cpp @@ -69,7 +69,7 @@ bool CFMNetwork::open() return m_socket.open(); } -bool CFMNetwork::writeData(const float* data, unsigned int nSamples) +bool CFMNetwork::writeData(float* data, unsigned int nSamples) { assert(m_outgoing != NULL); assert(data != NULL); @@ -193,9 +193,9 @@ unsigned int CFMNetwork::read(float* data, unsigned int nSamples) if (m_sampleRate != 8000U) { float in[750U]; - unsigned int j = 0U; for (unsigned int i = 0U; i < nSamples; i++) { - unsigned short val = ((buffer[j++] & 0xFFU) << 8) + ((buffer[j++] & 0xFFU) << 0); + unsigned short val = ((buffer[i * 2U + 0U] & 0xFFU) << 8) + + ((buffer[i * 2U + 1U] & 0xFFU) << 0); in[i] = (float(val) - 32768.0F) / 32768.0F; } @@ -214,9 +214,9 @@ unsigned int CFMNetwork::read(float* data, unsigned int nSamples) return src.output_frames_gen; } else { - unsigned int j = 0U; for (unsigned int i = 0U; i < nSamples; i++) { - unsigned short val = ((buffer[j++] & 0xFFU) << 8) + ((buffer[j++] & 0xFFU) << 0); + unsigned short val = ((buffer[i * 2U + 0U] & 0xFFU) << 8) + + ((buffer[i * 2U + 1U] & 0xFFU) << 0); data[i] = (float(val) - 32768.0F) / 32768.0F; } diff --git a/FMNetwork.h b/FMNetwork.h index 6dcdaac..f0d5d2a 100644 --- a/FMNetwork.h +++ b/FMNetwork.h @@ -37,11 +37,11 @@ public: void enable(bool enabled); - bool writeData(const float* data, unsigned int nSamples); + bool writeData(float* data, unsigned int nSamples); - bool writeEOT(); + bool writeEOT(); - unsigned int read(float* data, unsigned int nSamples); + unsigned int read(float* data, unsigned int nSamples); void reset(); diff --git a/Makefile b/Makefile index 91fcf2d..2181178 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,11 @@ CXX = c++ # Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -LIBS = -lpthread -lutil +LIBS = -lpthread -lutil -lsamplerate # Use the following CFLAGS and LIBS if you do want to use gpsd. #CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -#LIBS = -lpthread -lgps -lutil +#LIBS = -lpthread -lgps -lutil -lsamplerate LDFLAGS = -g diff --git a/Makefile.Pi b/Makefile.Pi index 62e27aa..7123530 100644 --- a/Makefile.Pi +++ b/Makefile.Pi @@ -4,11 +4,11 @@ CC = gcc CXX = g++ # Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DRASPBERRY_PI -I/usr/local/include -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate # Use the following CFLAGS and LIBS if you do want to use gpsd. #CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DRASPBERRY_PI -I/usr/local/include -#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps -lutil +#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps -lutil -lsamplerate LDFLAGS = -g -L/usr/local/lib diff --git a/Makefile.Pi.Adafruit b/Makefile.Pi.Adafruit index 2915c69..4c5e9f5 100644 --- a/Makefile.Pi.Adafruit +++ b/Makefile.Pi.Adafruit @@ -5,11 +5,11 @@ CC = gcc CXX = g++ # Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHD44780 -DADAFRUIT_DISPLAY -I/usr/local/include -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate # Use the following CFLAGS and LIBS if you do want to use gpsd. #CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DHD44780 -DADAFRUIT_DISPLAY -I/usr/local/include -#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps -lutil +#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps -lutil -lsamplerate LDFLAGS = -g -L/usr/local/lib diff --git a/Makefile.Pi.HD44780 b/Makefile.Pi.HD44780 index c00e58f..186b22f 100644 --- a/Makefile.Pi.HD44780 +++ b/Makefile.Pi.HD44780 @@ -5,11 +5,11 @@ CXX = g++ # Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHD44780 -I/usr/local/include -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate # Use the following CFLAGS and LIBS if you do want to use gpsd. #CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DHD44780 -I/usr/local/include -#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps -lutil +#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps -lutil -lsamplerate LDFLAGS = -g -L/usr/local/lib diff --git a/Makefile.Pi.OLED b/Makefile.Pi.OLED index 41e837e..34b2a9e 100644 --- a/Makefile.Pi.OLED +++ b/Makefile.Pi.OLED @@ -5,11 +5,11 @@ CXX = g++ # Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DOLED -I/usr/local/include -LIBS = -lArduiPi_OLED -lwiringPi -lpthread -lutil +LIBS = -lArduiPi_OLED -lwiringPi -lpthread -lutil -lsamplerate # Use the following CFLAGS and LIBS if you do want to use gpsd. #CFLAGS = -g -O3 -Wall -DUSE_GPS -std=c++0x -pthread -DOLED -I/usr/local/include -#LIBS = -lArduiPi_OLED -lwiringPi -lpthread -lgps -lutil +#LIBS = -lArduiPi_OLED -lwiringPi -lpthread -lgps -lutil -lsamplerate LDFLAGS = -g -L/usr/local/lib diff --git a/Makefile.Pi.PCF8574 b/Makefile.Pi.PCF8574 index 37de0b1..bda859b 100644 --- a/Makefile.Pi.PCF8574 +++ b/Makefile.Pi.PCF8574 @@ -6,11 +6,11 @@ CXX = g++ # Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHD44780 -DPCF8574_DISPLAY -I/usr/local/include -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate # Use the following CFLAGS and LIBS if you do want to use gpsd. #CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DHD44780 -DPCF8574_DISPLAY -I/usr/local/include -#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps -lutil +#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps -lutil -lsamplerate LDFLAGS = -g -L/usr/local/lib