diff options
author | RJ Ryan <rryan@mixxx.org> | 2013-12-19 17:49:49 -0500 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2013-12-21 00:50:16 -0500 |
commit | 40e1e0eb903ee26dad3a03523675bd59f9c74d7a (patch) | |
tree | a7aeb7f2e6aee4f701586bda5d8220ed48dfacd4 /src/vinylcontrol/vinylcontrolxwax.cpp | |
parent | af42c885bf538fc05b6bbd8780c3c59abcb9a94b (diff) |
Refactor the engine to process samples in the range of [-1.0, 1.0]. Fixes Bug #1204039.
* Move Vinyl Control pre-amp to VinylControlXwax (no longer affects
microphone/passthrough).
* Switch PortAudio input sample format to paFloat32.
* Remove SHRT_MAX conversions on input and output samples.
* Update VUMeters, clipping, and dithering code to deal with the new ranges.
* Clean up EngineMicrophone/EnginePassthrough/EngineDeck handling of inputs.
* Update tests to deal with the new sample ranges.
This does not change SoundSource. SoundSources still read 16-bit samples and we
simply divide by SHRT_MAX in AnalyserQueue and CachingReaderWorker. A future
performance improvement can remove this and use the native decoder API to
request normalized samples directly.
Diffstat (limited to 'src/vinylcontrol/vinylcontrolxwax.cpp')
-rw-r--r-- | src/vinylcontrol/vinylcontrolxwax.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/vinylcontrol/vinylcontrolxwax.cpp b/src/vinylcontrol/vinylcontrolxwax.cpp index 2a8bbfd57f..1ae09a83b4 100644 --- a/src/vinylcontrol/vinylcontrolxwax.cpp +++ b/src/vinylcontrol/vinylcontrolxwax.cpp @@ -187,15 +187,29 @@ bool VinylControlXwax::writeQualityReport(VinylSignalQualityReport* pReport) { } -void VinylControlXwax::analyzeSamples(const short *samples, size_t nFrames) -{ +void VinylControlXwax::analyzeSamples(CSAMPLE* pSamples, size_t nFrames) { ScopedTimer t("VinylControlXwax::analyzeSamples"); + CSAMPLE gain = m_pVinylControlInputGain->get(); + const int kChannels = 2; + + // Convert CSAMPLE samples to shorts, preventing overflow. + for (int i = 0; i < nFrames * kChannels; ++i) { + double sample = pSamples[i] * gain * SHRT_MAX; + + if (sample > SHRT_MAX) { + m_pWorkBuffer[i] = SHRT_MAX; + } else if (sample < SHRT_MIN) { + m_pWorkBuffer[i] = SHRT_MIN; + } else { + m_pWorkBuffer[i] = static_cast<short>(sample); + } + } // Submit the samples to the xwax timecode processor. The size argument is // in stereo frames. - timecoder_submit(&timecoder, samples, nFrames); + timecoder_submit(&timecoder, m_pWorkBuffer, nFrames); - bool bHaveSignal = fabs((float)samples[0]) + fabs((float)samples[1]) > MIN_SIGNAL; + bool bHaveSignal = fabs(pSamples[0]) + fabs(pSamples[1]) > MIN_SIGNAL; //qDebug() << "signal?" << bHaveSignal; //TODO: Move all these config object get*() calls to an "updatePrefs()" function, |