Added mono to stereo conversion to fix Linux audio. Closes #2508.

This commit is contained in:
Andrzej Kapolka 2014-03-26 11:01:58 -07:00
parent 0d0784ef4b
commit b88708a991
2 changed files with 26 additions and 10 deletions

View file

@ -4,22 +4,22 @@
<context> <context>
<name>Application</name> <name>Application</name>
<message> <message>
<location filename="src/Application.cpp" line="1368"/> <location filename="src/Application.cpp" line="1380"/>
<source>Export Voxels</source> <source>Export Voxels</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="src/Application.cpp" line="1369"/> <location filename="src/Application.cpp" line="1381"/>
<source>Sparse Voxel Octree Files (*.svo)</source> <source>Sparse Voxel Octree Files (*.svo)</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="src/Application.cpp" line="3596"/> <location filename="src/Application.cpp" line="3597"/>
<source>Open Script</source> <source>Open Script</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="src/Application.cpp" line="3597"/> <location filename="src/Application.cpp" line="3598"/>
<source>JavaScript Files (*.js)</source> <source>JavaScript Files (*.js)</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -113,18 +113,18 @@
<context> <context>
<name>Menu</name> <name>Menu</name>
<message> <message>
<location filename="src/Menu.cpp" line="455"/> <location filename="src/Menu.cpp" line="457"/>
<source>Open .ini config file</source> <source>Open .ini config file</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="src/Menu.cpp" line="457"/> <location filename="src/Menu.cpp" line="459"/>
<location filename="src/Menu.cpp" line="469"/> <location filename="src/Menu.cpp" line="471"/>
<source>Text files (*.ini)</source> <source>Text files (*.ini)</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="src/Menu.cpp" line="467"/> <location filename="src/Menu.cpp" line="469"/>
<source>Save .ini config file</source> <source>Save .ini config file</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View file

@ -215,6 +215,20 @@ void linearResampling(int16_t* sourceSamples, int16_t* destinationSamples,
} }
} else { } else {
if (sourceAudioFormat.sampleRate() == destinationAudioFormat.sampleRate()) {
// mono to stereo, same sample rate
if (!(sourceAudioFormat.channelCount() == 1 && destinationAudioFormat.channelCount() == 2)) {
qWarning() << "Unsupported format conversion" << sourceAudioFormat << destinationAudioFormat;
return;
}
for (const int16_t* sourceEnd = sourceSamples + numSourceSamples; sourceSamples != sourceEnd;
sourceSamples++) {
*destinationSamples++ = *sourceSamples;
*destinationSamples++ = *sourceSamples;
}
return;
}
// upsample from 24 to 48 // upsample from 24 to 48
// for now this only supports a stereo to stereo conversion - this is our case for network audio to output // for now this only supports a stereo to stereo conversion - this is our case for network audio to output
int sourceIndex = 0; int sourceIndex = 0;
@ -551,12 +565,14 @@ void Audio::handleAudioInput() {
// send whatever procedural sounds we want to locally loop back to the _proceduralOutputDevice // send whatever procedural sounds we want to locally loop back to the _proceduralOutputDevice
QByteArray proceduralOutput; QByteArray proceduralOutput;
proceduralOutput.resize(NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 4 * sizeof(int16_t)); proceduralOutput.resize(NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL * _outputFormat.sampleRate() *
_outputFormat.channelCount() * sizeof(int16_t) / (_desiredInputFormat.sampleRate() *
_desiredInputFormat.channelCount()));
linearResampling(_localProceduralSamples, linearResampling(_localProceduralSamples,
reinterpret_cast<int16_t*>(proceduralOutput.data()), reinterpret_cast<int16_t*>(proceduralOutput.data()),
NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL, NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL,
NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 4, proceduralOutput.size() / sizeof(int16_t),
_desiredInputFormat, _outputFormat); _desiredInputFormat, _outputFormat);
if (_proceduralOutputDevice) { if (_proceduralOutputDevice) {