Adding buffer and testing demod functionality

This commit is contained in:
Charles J. Cliffe 2014-11-06 01:33:59 -05:00
parent e0344d8efc
commit 2092505e20
5 changed files with 48 additions and 28 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;
}

View File

@ -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<signed char> *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<ALuint> *newBuffer = new std::vector<ALuint>;
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<ALuint> 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<ALuint> *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) {

View File

@ -4,15 +4,22 @@
#include "wx/timer.h"
#include <vector>
#include <queue>
#include "CubicSDRDefs.h"
#include "fftw3.h"
#include "Demodulate.h"
#ifdef WIN32
#include <AL/al.h>
#include <AL/alc.h>
#else
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#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<float> fft_result_ma;
std::vector<float> fft_result_maa;
std::queue< std::vector <ALuint> * > 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();
};