mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 10:49:33 +02:00
cleanup the callers of the resamplers for mic to net and net to speaker, remove loopback resampler
This commit is contained in:
parent
a48cce2975
commit
c0be9aec6a
2 changed files with 26 additions and 63 deletions
|
@ -102,7 +102,6 @@ AudioClient::AudioClient() :
|
||||||
_reverbOptions(&_scriptReverbOptions),
|
_reverbOptions(&_scriptReverbOptions),
|
||||||
_inputToNetworkResampler(NULL),
|
_inputToNetworkResampler(NULL),
|
||||||
_networkToOutputResampler(NULL),
|
_networkToOutputResampler(NULL),
|
||||||
_loopbackResampler(NULL),
|
|
||||||
_outgoingAvatarAudioSequenceNumber(0),
|
_outgoingAvatarAudioSequenceNumber(0),
|
||||||
_audioOutputIODevice(_receivedAudioStream, this),
|
_audioOutputIODevice(_receivedAudioStream, this),
|
||||||
_stats(&_receivedAudioStream),
|
_stats(&_receivedAudioStream),
|
||||||
|
@ -315,54 +314,35 @@ bool adjustedFormatForAudioDevice(const QAudioDeviceInfo& audioDevice,
|
||||||
|
|
||||||
// FIXME: directly using 24khz has a bug somewhere that causes channels to be swapped.
|
// FIXME: directly using 24khz has a bug somewhere that causes channels to be swapped.
|
||||||
// Continue using our internal resampler, for now.
|
// Continue using our internal resampler, for now.
|
||||||
if (true || !audioDevice.isFormatSupported(desiredAudioFormat)) {
|
qCDebug(audioclient) << "The desired format for audio I/O is" << desiredAudioFormat;
|
||||||
qCDebug(audioclient) << "The desired format for audio I/O is" << desiredAudioFormat;
|
|
||||||
qCDebug(audioclient, "The desired audio format is not supported by this device");
|
|
||||||
|
|
||||||
if (desiredAudioFormat.channelCount() == 1) {
|
const int FORTY_FOUR = 44100;
|
||||||
adjustedAudioFormat = desiredAudioFormat;
|
adjustedAudioFormat = desiredAudioFormat;
|
||||||
adjustedAudioFormat.setChannelCount(2);
|
|
||||||
|
|
||||||
if (false && audioDevice.isFormatSupported(adjustedAudioFormat)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
adjustedAudioFormat.setChannelCount(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const int FORTY_FOUR = 44100;
|
|
||||||
|
|
||||||
adjustedAudioFormat = desiredAudioFormat;
|
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
adjustedAudioFormat.setSampleRate(FORTY_FOUR);
|
adjustedAudioFormat.setSampleRate(FORTY_FOUR);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
const int HALF_FORTY_FOUR = FORTY_FOUR / 2;
|
const int HALF_FORTY_FOUR = FORTY_FOUR / 2;
|
||||||
|
|
||||||
if (audioDevice.supportedSampleRates().contains(AudioConstants::SAMPLE_RATE * 2)) {
|
if (audioDevice.supportedSampleRates().contains(AudioConstants::SAMPLE_RATE * 2)) {
|
||||||
// use 48, which is a sample downsample, upsample
|
// use 48, which is a sample downsample, upsample
|
||||||
adjustedAudioFormat.setSampleRate(AudioConstants::SAMPLE_RATE * 2);
|
adjustedAudioFormat.setSampleRate(AudioConstants::SAMPLE_RATE * 2);
|
||||||
} else if (audioDevice.supportedSampleRates().contains(HALF_FORTY_FOUR)) {
|
} else if (audioDevice.supportedSampleRates().contains(HALF_FORTY_FOUR)) {
|
||||||
// use 22050, resample but closer to 24
|
// use 22050, resample but closer to 24
|
||||||
adjustedAudioFormat.setSampleRate(HALF_FORTY_FOUR);
|
adjustedAudioFormat.setSampleRate(HALF_FORTY_FOUR);
|
||||||
} else if (audioDevice.supportedSampleRates().contains(FORTY_FOUR)) {
|
} else if (audioDevice.supportedSampleRates().contains(FORTY_FOUR)) {
|
||||||
// use 48000, resample
|
// use 48000, resample
|
||||||
adjustedAudioFormat.setSampleRate(FORTY_FOUR);
|
adjustedAudioFormat.setSampleRate(FORTY_FOUR);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (adjustedAudioFormat != desiredAudioFormat) {
|
if (adjustedAudioFormat != desiredAudioFormat) {
|
||||||
// return the nearest in case it needs 2 channels
|
// return the nearest in case it needs 2 channels
|
||||||
adjustedAudioFormat = audioDevice.nearestFormat(adjustedAudioFormat);
|
adjustedAudioFormat = audioDevice.nearestFormat(adjustedAudioFormat);
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// set the adjustedAudioFormat to the desiredAudioFormat, since it will work
|
|
||||||
adjustedAudioFormat = desiredAudioFormat;
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,11 +447,6 @@ void AudioClient::stop() {
|
||||||
// "switch" to invalid devices in order to shut down the state
|
// "switch" to invalid devices in order to shut down the state
|
||||||
switchInputToAudioDevice(QAudioDeviceInfo());
|
switchInputToAudioDevice(QAudioDeviceInfo());
|
||||||
switchOutputToAudioDevice(QAudioDeviceInfo());
|
switchOutputToAudioDevice(QAudioDeviceInfo());
|
||||||
|
|
||||||
if (_loopbackResampler) {
|
|
||||||
delete _loopbackResampler;
|
|
||||||
_loopbackResampler = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::handleAudioEnvironmentDataPacket(QSharedPointer<ReceivedMessage> message) {
|
void AudioClient::handleAudioEnvironmentDataPacket(QSharedPointer<ReceivedMessage> message) {
|
||||||
|
@ -675,16 +650,10 @@ void AudioClient::handleLocalEchoAndReverb(QByteArray& inputByteArray) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// do we need to setup a resampler?
|
// NOTE: we assume the inputFormat and the outputFormat are the same, since on any modern
|
||||||
if (_inputFormat.sampleRate() != _outputFormat.sampleRate() && !_loopbackResampler) {
|
// multimedia OS they should be. If there is a device that this is not true for, we can
|
||||||
qCDebug(audioclient) << "Attemping to create a resampler for input format to output format for audio loopback.";
|
// add back support to do resampling.
|
||||||
|
Q_ASSERT(_inputFormat.sampleRate() == _outputFormat.sampleRate());
|
||||||
assert(_inputFormat.sampleSize() == 16);
|
|
||||||
assert(_outputFormat.sampleSize() == 16);
|
|
||||||
int channelCount = (_inputFormat.channelCount() == 2 && _outputFormat.channelCount() == 2) ? 2 : 1;
|
|
||||||
|
|
||||||
_loopbackResampler = new AudioSRC(_inputFormat.sampleRate(), _outputFormat.sampleRate(), channelCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QByteArray loopBackByteArray;
|
static QByteArray loopBackByteArray;
|
||||||
|
|
||||||
|
@ -696,7 +665,8 @@ void AudioClient::handleLocalEchoAndReverb(QByteArray& inputByteArray) {
|
||||||
int16_t* inputSamples = reinterpret_cast<int16_t*>(inputByteArray.data());
|
int16_t* inputSamples = reinterpret_cast<int16_t*>(inputByteArray.data());
|
||||||
int16_t* loopbackSamples = reinterpret_cast<int16_t*>(loopBackByteArray.data());
|
int16_t* loopbackSamples = reinterpret_cast<int16_t*>(loopBackByteArray.data());
|
||||||
|
|
||||||
possibleResampling(_loopbackResampler,
|
auto NO_RESAMPLER = nullptr;
|
||||||
|
possibleResampling(NO_RESAMPLER,
|
||||||
inputSamples, loopbackSamples,
|
inputSamples, loopbackSamples,
|
||||||
numInputSamples, numLoopbackSamples,
|
numInputSamples, numLoopbackSamples,
|
||||||
_inputFormat, _outputFormat);
|
_inputFormat, _outputFormat);
|
||||||
|
@ -1039,12 +1009,6 @@ bool AudioClient::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDevice
|
||||||
_networkToOutputResampler = NULL;
|
_networkToOutputResampler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_loopbackResampler) {
|
|
||||||
// if we were using an input to output resample, delete it here
|
|
||||||
delete _loopbackResampler;
|
|
||||||
_loopbackResampler = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!outputDeviceInfo.isNull()) {
|
if (!outputDeviceInfo.isNull()) {
|
||||||
qCDebug(audioclient) << "The audio output device " << outputDeviceInfo.deviceName() << "is available.";
|
qCDebug(audioclient) << "The audio output device " << outputDeviceInfo.deviceName() << "is available.";
|
||||||
_outputAudioDeviceName = outputDeviceInfo.deviceName().trimmed();
|
_outputAudioDeviceName = outputDeviceInfo.deviceName().trimmed();
|
||||||
|
|
|
@ -260,7 +260,6 @@ private:
|
||||||
// possible streams needed for resample
|
// possible streams needed for resample
|
||||||
AudioSRC* _inputToNetworkResampler;
|
AudioSRC* _inputToNetworkResampler;
|
||||||
AudioSRC* _networkToOutputResampler;
|
AudioSRC* _networkToOutputResampler;
|
||||||
AudioSRC* _loopbackResampler;
|
|
||||||
|
|
||||||
// Adds Reverb
|
// Adds Reverb
|
||||||
void configureReverb();
|
void configureReverb();
|
||||||
|
|
Loading…
Reference in a new issue