ALSA and AQS use floating-point audio output now

This commit is contained in:
Jack Andersen 2016-07-03 17:31:53 -10:00
parent f4dc3626e5
commit befa1a11a2
3 changed files with 16 additions and 10 deletions

View File

@ -135,7 +135,13 @@ struct ALSAAudioVoiceEngine : BaseAudioVoiceEngine
snd_pcm_hw_params_any(m_pcm, hwParams);
snd_pcm_format_t bestFmt;
if (!snd_pcm_hw_params_test_format(m_pcm, hwParams, SND_PCM_FORMAT_S32))
if (!snd_pcm_hw_params_test_format(m_pcm, hwParams, SND_PCM_FORMAT_FLOAT))
{
bestFmt = SND_PCM_FORMAT_FLOAT;
m_mixInfo.m_sampleFormat = SOXR_FLOAT32_I;
m_mixInfo.m_bitsPerSample = 32;
}
else if (!snd_pcm_hw_params_test_format(m_pcm, hwParams, SND_PCM_FORMAT_S32))
{
bestFmt = SND_PCM_FORMAT_S32;
m_mixInfo.m_sampleFormat = SOXR_INT32_I;

View File

@ -56,7 +56,7 @@ struct AQSAudioVoiceEngine : BaseAudioVoiceEngine
engine->m_engineEnterCv.wait(lk);
engine->m_cbWaiting = false;
engine->_pumpAndMixVoices(engine->m_mixInfo.m_periodFrames, reinterpret_cast<int32_t*>(inBuffer->mAudioData));
engine->_pumpAndMixVoices(engine->m_mixInfo.m_periodFrames, reinterpret_cast<float*>(inBuffer->mAudioData));
inBuffer->mAudioDataByteSize = engine->m_frameBytes;
AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, nullptr);
@ -71,7 +71,7 @@ struct AQSAudioVoiceEngine : BaseAudioVoiceEngine
AudioStreamBasicDescription desc = {};
desc.mSampleRate = 96000;
desc.mFormatID = kAudioFormatLinearPCM;
desc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
desc.mFormatFlags = kLinearPCMFormatFlagIsFloat;
desc.mBytesPerPacket = chCount * 4;
desc.mFramesPerPacket = 1;
desc.mBytesPerFrame = chCount * 4;
@ -545,7 +545,7 @@ struct AQSAudioVoiceEngine : BaseAudioVoiceEngine
AudioStreamBasicDescription desc = {};
desc.mSampleRate = 96000;
desc.mFormatID = kAudioFormatLinearPCM;
desc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
desc.mFormatFlags = kLinearPCMFormatFlagIsFloat;
desc.mBytesPerPacket = chCount * 4;
desc.mFramesPerPacket = 1;
desc.mBytesPerFrame = chCount * 4;
@ -579,7 +579,7 @@ struct AQSAudioVoiceEngine : BaseAudioVoiceEngine
}
m_mixInfo.m_sampleRate = actualSampleRate;
m_mixInfo.m_sampleFormat = SOXR_INT32_I;
m_mixInfo.m_sampleFormat = SOXR_FLOAT32_I;
m_mixInfo.m_bitsPerSample = 32;
m_5msFrames = actualSampleRate * 5 / 1000;
@ -676,7 +676,7 @@ struct AQSAudioVoiceEngine : BaseAudioVoiceEngine
for (unsigned i=0 ; i<3 ; ++i)
{
_pumpAndMixVoices(m_mixInfo.m_periodFrames, reinterpret_cast<int32_t*>(m_buffers[i]->mAudioData));
_pumpAndMixVoices(m_mixInfo.m_periodFrames, reinterpret_cast<float*>(m_buffers[i]->mAudioData));
m_buffers[i]->mAudioDataByteSize = m_frameBytes;
AudioQueueEnqueueBuffer(m_queue, m_buffers[i], 0, nullptr);
}

View File

@ -127,7 +127,7 @@ void AudioVoiceMono::_resetSampleRate(double sampleRate)
{
std::vector<float>& scratchFlt = m_root.m_scratchFlt;
if (scratchFlt.size() < m_root.m_5msFrames)
scratchFlt.resize(m_root.m_5msFrames);
scratchFlt.resize(m_root.m_5msFrames + 2);
soxr_output(m_src, scratchFlt.data(), m_root.m_5msFrames);
break;
}
@ -196,7 +196,7 @@ size_t AudioVoiceMono::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
{
std::vector<float>& scratchFlt = m_root.m_scratchFlt;
if (scratchFlt.size() < frames)
scratchFlt.resize(frames);
scratchFlt.resize(frames + 2);
size_t oDone = soxr_output(m_src, scratchFlt.data(), frames);
_midUpdate();
@ -316,7 +316,7 @@ void AudioVoiceStereo::_resetSampleRate(double sampleRate)
{
std::vector<float>& scratchFlt = m_root.m_scratchFlt;
if (scratchFlt.size() < m_root.m_5msFrames * 2)
scratchFlt.resize(m_root.m_5msFrames * 2);
scratchFlt.resize(m_root.m_5msFrames * 2 + 2);
soxr_output(m_src, scratchFlt.data(), m_root.m_5msFrames);
break;
}
@ -389,7 +389,7 @@ size_t AudioVoiceStereo::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
std::vector<float>& scratchFlt = m_root.m_scratchFlt;
size_t samples = frames * 2;
if (scratchFlt.size() < samples)
scratchFlt.resize(samples);
scratchFlt.resize(samples + 4);
size_t oDone = soxr_output(m_src, scratchFlt.data(), frames);
_midUpdate();