diff --git a/CMakeLists.txt b/CMakeLists.txt index 7418396..3f4cdfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ else (DEFINED WIN32) link_directories(${RTLSDR_LIB}) set(FFTW_LIB fftw3) find_package (OpenAL) + include_directories ( ${OPENAL_INCLUDE_DIR} ) endif (DEFINED WIN32) diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index 94a2a04..649a715 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -1,8 +1,8 @@ #pragma once -#define BUF_SIZE (16 * 32 * 512) +#define BUF_SIZE (16 * 32 * 256) #define SRATE 2500000 -#define FFT_SIZE 8192 +#define FFT_SIZE 4096 #define DEFAULT_FREQ 105700000 diff --git a/src/Demodulate.cpp b/src/Demodulate.cpp index 984d30c..6ea7ee3 100644 --- a/src/Demodulate.cpp +++ b/src/Demodulate.cpp @@ -538,8 +538,8 @@ Demodulate::Demodulate() { mode_demod = &fm_demod; rate_in = 170000; rate_out = 170000; - rate_out2 = 32000; - output.rate = 32000; + rate_out2 = 44000; + output.rate = 44000; custom_atan = 1; // post_downsample = 4; deemph = 1; @@ -547,6 +547,7 @@ Demodulate::Demodulate() { int capture_freq; + // downsample = (SRATE / rate_in) + 1; downsample = (SRATE / rate_in) + 1; if (downsample_passes) { downsample_passes = (int) log2(downsample) + 1; @@ -589,6 +590,7 @@ Demodulate::Demodulate() { output.results[1].trycond = 1; output.results[1].buf = NULL; + // controller.freqs[0] = 100000000; // controller.freq_len = 0; // controller.edge = 0; @@ -615,7 +617,7 @@ Demodulate::Demodulate() { // } // break; - rate_in *= post_downsample; + // rate_in *= post_downsample; if (!output.rate) { output.rate = rate_out; } diff --git a/src/PrimaryGLContext.cpp b/src/PrimaryGLContext.cpp index e71461c..cd1c960 100644 --- a/src/PrimaryGLContext.cpp +++ b/src/PrimaryGLContext.cpp @@ -132,16 +132,16 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent, int *attribList) : alGenSources(1, &source); // prime the buffers - ALuint buffer_init[AL_BUFFER_SIZE]; + int16_t buffer_init[AL_BUFFER_SIZE]; for (int i = 0; i < AL_BUFFER_SIZE; i++) { - buffer_init[i] = 32767; + buffer_init[i] = 0; } format = AL_FORMAT_MONO16; - alBufferData(buffers[0], format, buffer_init, AL_BUFFER_SIZE, 32000); - alBufferData(buffers[1], format, buffer_init, AL_BUFFER_SIZE, 32000); - alBufferData(buffers[2], format, buffer_init, AL_BUFFER_SIZE, 32000); + for (int i = 0; i < AL_NUM_BUFFERS; i++) { + alBufferData(buffers[i], format, buffer_init, AL_BUFFER_SIZE, demod.output.rate); + } if (alGetError() != AL_NO_ERROR) { std::cout << "Error priming :(\n"; } @@ -228,30 +228,39 @@ void TestGLCanvas::setData(std::vector *data) { ALint val; ALuint buffer; + alGetSourcei(source, AL_SOURCE_STATE, &val); + if (val != AL_PLAYING) { + alSourcePlay(source); + } + + // std::cout << "buffer: " << demod.output_target->len << "@" << frequency << std::endl; + std::vector *newBuffer = new std::vector; + newBuffer->resize(demod.output_target->len); + memcpy(&(*newBuffer)[0],demod.output_target->buf,demod.output_target->len*2); + audio_queue.push(newBuffer); + + frequency = demod.output.rate; - alGetSourcei(source, AL_BUFFERS_PROCESSED, &val); - if (val > 0) { - std::cout << "buffer: " << demod.output_target->len << "@" << frequency << std::endl; -// std::vector al_buffer; -// al_buffer.resize(demod.lp_len); - -// for (int i = 0, iMax = demod.lp_len; i < iMax; i++) { -// al_buffer[i] = demod.lowpassed[i] + 32767.0; -// } - + while (audio_queue.size()>8) { + alGetSourcei(source, AL_BUFFERS_PROCESSED, &val); + if (val <= 0) { + break; + } + + std::vector *nextBuffer = audio_queue.front(); + alSourceUnqueueBuffers(source, 1, &buffer); - alBufferData(buffer, format, demod.output_target->buf, demod.output_target->len*2, frequency); + alBufferData(buffer, format, &(*nextBuffer)[0], nextBuffer->size()*2, frequency); alSourceQueueBuffers(source, 1, &buffer); + audio_queue.pop(); + + delete nextBuffer; + if (alGetError() != AL_NO_ERROR) { std::cout << "Error buffering :(\n"; } - - } - alGetSourcei(source, AL_SOURCE_STATE, &val); - if (val != AL_PLAYING) { - alSourcePlay(source); } if (spectrum_points.size() < FFT_SIZE * 2) { diff --git a/src/PrimaryGLContext.h b/src/PrimaryGLContext.h index be814d4..8c30aeb 100644 --- a/src/PrimaryGLContext.h +++ b/src/PrimaryGLContext.h @@ -4,15 +4,22 @@ #include "wx/timer.h" #include +#include + #include "CubicSDRDefs.h" #include "fftw3.h" #include "Demodulate.h" +#ifdef WIN32 #include #include +#else +#include +#include +#endif -#define AL_NUM_BUFFERS 3 +#define AL_NUM_BUFFERS 16 #define AL_BUFFER_SIZE 4096 class PrimaryGLContext: public wxGLContext { @@ -52,6 +59,8 @@ private: std::vector fft_result_ma; std::vector fft_result_maa; + std::queue< std::vector * > audio_queue; + Demodulate demod; ALCdevice *dev; @@ -60,7 +69,6 @@ private: ALuint source, buffers[AL_NUM_BUFFERS]; ALuint frequency; ALenum format; - unsigned char *buf; wxDECLARE_EVENT_TABLE(); };