Add stereo re-sampler

This commit is contained in:
Charles J. Cliffe 2014-12-26 21:55:13 -05:00
parent 0fc47bc916
commit 44602303a7
7 changed files with 26 additions and 7 deletions

View File

@ -112,7 +112,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
srcmix->audio_queue_ptr++;
}
} else {
for (int i = 0, iMax = src->currentInput->channels * nBufferFrames; i < iMax; i++) {
for (int i = 0, iMax = srcmix->currentInput->channels * nBufferFrames; i < iMax; i++) {
if (srcmix->audio_queue_ptr >= srcmix->currentInput->data.size()) {
if (srcmix->currentInput) {
srcmix->currentInput->decRefCount();

View File

@ -73,11 +73,12 @@ public:
int bandwidth;
float audio_resample_ratio;
msresamp_rrrf audio_resampler;
msresamp_rrrf stereo_resampler;
float resample_ratio;
msresamp_crcf resampler;
DemodulatorThreadPostIQData() :
bandwidth(0), audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) {
bandwidth(0), audio_resample_ratio(0), audio_resampler(NULL), stereo_resampler(NULL), resample_ratio(0), resampler(NULL) {
}

View File

@ -9,7 +9,7 @@
DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut,
DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) :
inputQueue(pQueueIn), postInputQueue(pQueueOut), terminated(false), initialized(false), audio_resampler(NULL), resample_ratio(1), audio_resample_ratio(
inputQueue(pQueueIn), postInputQueue(pQueueOut), terminated(false), initialized(false), audio_resampler(NULL), stereo_resampler(NULL), resample_ratio(1), audio_resample_ratio(
1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify), threadQueueControl(
threadQueueControl) {
@ -71,6 +71,12 @@ void DemodulatorPreThread::initialize() {
audio_resampler = msresamp_rrrf_create(audio_resample_ratio, As);
// msresamp_crcf_print(audio_resampler);
if (stereo_resampler) {
msresamp_rrrf_destroy(stereo_resampler);
}
stereo_resampler = msresamp_rrrf_create(audio_resample_ratio, As);
initialized = true;
// std::cout << "inputResampleRate " << params.bandwidth << std::endl;
@ -217,6 +223,7 @@ void DemodulatorPreThread::threadMain() {
resamp->audio_resample_ratio = audio_resample_ratio;
resamp->audio_resampler = audio_resampler;
resamp->stereo_resampler = stereo_resampler;
resamp->resample_ratio = resample_ratio;
resamp->resampler = resampler;
resamp->bandwidth = params.bandwidth;
@ -240,6 +247,7 @@ void DemodulatorPreThread::threadMain() {
fir_filter = result.fir_filter;
resampler = result.resampler;
audio_resampler = result.audio_resampler;
stereo_resampler = result.stereo_resampler;
resample_ratio = result.resample_ratio;
audio_resample_ratio = result.audio_resample_ratio;

View File

@ -57,6 +57,7 @@ protected:
float resample_ratio;
msresamp_rrrf audio_resampler;
msresamp_rrrf stereo_resampler;
float audio_resample_ratio;
DemodulatorThreadParameters params;

View File

@ -31,6 +31,7 @@ void DemodulatorThread::threadMain() {
#endif
msresamp_rrrf audio_resampler = NULL;
msresamp_rrrf stereo_resampler = NULL;
msresamp_crcf resampler = NULL;
agc = agc_crcf_create();
@ -65,11 +66,14 @@ void DemodulatorThread::threadMain() {
if (resampler == NULL) {
resampler = inp->resampler;
audio_resampler = inp->audio_resampler;
stereo_resampler = inp->stereo_resampler;
} else if (resampler != inp->resampler) {
msresamp_crcf_destroy(resampler);
msresamp_rrrf_destroy(audio_resampler);
msresamp_rrrf_destroy(stereo_resampler);
resampler = inp->resampler;
audio_resampler = inp->audio_resampler;
stereo_resampler = inp->stereo_resampler;
}
int out_size = ceil((float) (bufSize) * inp->resample_ratio);
@ -108,7 +112,7 @@ void DemodulatorThread::threadMain() {
for (int i = 0; i < num_written; i++) {
freq_index+=freq;
demod_output_stereo[i] = demod_output[i] * sin(freq_index) + demod_output[i] * cos(freq_index);
demod_output_stereo[i] = demod_output[i] * sin(freq_index);// + demod_output[i] * cos(freq_index);
while (freq_index > (M_PI*2.0)) {
freq_index -= (M_PI*2.0);
}
@ -133,7 +137,7 @@ void DemodulatorThread::threadMain() {
msresamp_rrrf_execute(audio_resampler, &demod_output[0], num_written, &resampled_audio_output[0], &num_audio_written);
if (stereo) {
msresamp_rrrf_execute(audio_resampler, &demod_output_stereo[0], num_written, &resampled_audio_output_stereo[0], &num_audio_written);
msresamp_rrrf_execute(stereo_resampler, &demod_output_stereo[0], num_written, &resampled_audio_output_stereo[0], &num_audio_written);
}
if (audioInputQueue != NULL) {
@ -222,6 +226,9 @@ void DemodulatorThread::threadMain() {
if (audio_resampler != NULL) {
msresamp_rrrf_destroy(audio_resampler);
}
if (stereo_resampler != NULL) {
msresamp_rrrf_destroy(stereo_resampler);
}
agc_crcf_destroy(agc);

View File

@ -59,6 +59,7 @@ void DemodulatorWorkerThread::threadMain() {
result.fir_filter = firfilt_crcf_create(h, h_len);
result.resampler = msresamp_crcf_create(result.resample_ratio, As);
result.audio_resampler = msresamp_rrrf_create(result.audio_resample_ratio, As);
result.stereo_resampler = msresamp_rrrf_create(result.audio_resample_ratio, As);
result.audioSampleRate = filterCommand.audioSampleRate;
result.bandwidth = filterCommand.bandwidth;

View File

@ -22,13 +22,13 @@ public:
};
DemodulatorWorkerThreadResult() :
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio(
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), stereo_resampler(NULL), audio_resample_ratio(
0), inputRate(0), bandwidth(0), audioSampleRate(0) {
}
DemodulatorWorkerThreadResult(DemodulatorThreadResultEnum cmd) :
cmd(cmd), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio(0), inputRate(0), bandwidth(
cmd(cmd), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), stereo_resampler(NULL), audio_resample_ratio(0), inputRate(0), bandwidth(
0), audioSampleRate(0) {
}
@ -39,6 +39,7 @@ public:
msresamp_crcf resampler;
float resample_ratio;
msresamp_rrrf audio_resampler;
msresamp_rrrf stereo_resampler;
float audio_resample_ratio;
unsigned int inputRate;