mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
repetition-with-fade seems good; continue testing
This commit is contained in:
parent
e276d15ed4
commit
a31d53544b
4 changed files with 25 additions and 14 deletions
|
@ -649,7 +649,6 @@ void AudioMixer::run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// send mixed audio packet
|
// send mixed audio packet
|
||||||
if (nodeData->getOutgoingSequenceNumber() % 100 < 50)
|
|
||||||
nodeList->writeDatagram(clientMixBuffer, dataAt - clientMixBuffer, node);
|
nodeList->writeDatagram(clientMixBuffer, dataAt - clientMixBuffer, node);
|
||||||
nodeData->incrementOutgoingMixedAudioSequenceNumber();
|
nodeData->incrementOutgoingMixedAudioSequenceNumber();
|
||||||
|
|
||||||
|
|
|
@ -740,8 +740,11 @@ void Audio::addStereoSilenceToScope(int silentSamplesPerChannel) {
|
||||||
if (!_scopeEnabled || _scopeEnabledPause) {
|
if (!_scopeEnabled || _scopeEnabledPause) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
printf("\t Audio::addStereoSilenceToScope %d per channel\n", silentSamplesPerChannel);
|
||||||
addSilenceToScope(_scopeOutputLeft, _scopeOutputOffset, silentSamplesPerChannel);
|
addSilenceToScope(_scopeOutputLeft, _scopeOutputOffset, silentSamplesPerChannel);
|
||||||
_scopeOutputOffset = addSilenceToScope(_scopeOutputRight, _scopeOutputOffset, silentSamplesPerChannel);
|
_scopeOutputOffset = addSilenceToScope(_scopeOutputRight, _scopeOutputOffset, silentSamplesPerChannel);
|
||||||
|
|
||||||
|
printf("\t end\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::addStereoSamplesToScope(const QByteArray& samples) {
|
void Audio::addStereoSamplesToScope(const QByteArray& samples) {
|
||||||
|
@ -750,29 +753,35 @@ void Audio::addStereoSamplesToScope(const QByteArray& samples) {
|
||||||
}
|
}
|
||||||
const int16_t* samplesData = reinterpret_cast<const int16_t*>(samples.data());
|
const int16_t* samplesData = reinterpret_cast<const int16_t*>(samples.data());
|
||||||
int samplesPerChannel = samples.size() / sizeof(int16_t) / STEREO_FACTOR;
|
int samplesPerChannel = samples.size() / sizeof(int16_t) / STEREO_FACTOR;
|
||||||
|
printf("\t Audio::addStereoSamplesToScope %d samples per channel\n", samplesPerChannel);
|
||||||
|
|
||||||
addBufferToScope(_scopeOutputLeft, _scopeOutputOffset, samplesData, samplesPerChannel, 0, STEREO_FACTOR);
|
addBufferToScope(_scopeOutputLeft, _scopeOutputOffset, samplesData, samplesPerChannel, 0, STEREO_FACTOR);
|
||||||
_scopeOutputOffset = addBufferToScope(_scopeOutputRight, _scopeOutputOffset, samplesData, samplesPerChannel, 1, STEREO_FACTOR);
|
_scopeOutputOffset = addBufferToScope(_scopeOutputRight, _scopeOutputOffset, samplesData, samplesPerChannel, 1, STEREO_FACTOR);
|
||||||
|
|
||||||
_scopeLastFrame = samples.right(NETWORK_BUFFER_LENGTH_BYTES_STEREO);
|
_scopeLastFrame = samples.right(NETWORK_BUFFER_LENGTH_BYTES_STEREO);
|
||||||
|
|
||||||
|
printf("\t end\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::addLastFrameRepeatedWithFadeToScope(int samplesPerChannel) {
|
void Audio::addLastFrameRepeatedWithFadeToScope(int samplesPerChannel) {
|
||||||
printf("addLastFrameRepeatedWithFadeToScope");
|
printf("addLastFrameRepeatedWithFadeToScope %d per channel\n", samplesPerChannel);
|
||||||
const int16_t* lastFrameData = reinterpret_cast<const int16_t*>(_scopeLastFrame.data());
|
const int16_t* lastFrameData = reinterpret_cast<const int16_t*>(_scopeLastFrame.data());
|
||||||
|
|
||||||
int samplesRemaining = samplesPerChannel;
|
int samplesRemaining = samplesPerChannel;
|
||||||
int indexOfRepeat = 0;
|
int indexOfRepeat = 0;
|
||||||
do {
|
do {
|
||||||
int samplesToWriteThisIteration = std::min(samplesRemaining, (int)NETWORK_SAMPLES_PER_FRAME);
|
int samplesToWriteThisIteration = std::min(samplesRemaining, (int)NETWORK_SAMPLES_PER_FRAME);
|
||||||
float fade = calculateRepeatedFrameFadeFactor(indexOfRepeat);
|
float fade = calculateRepeatedFrameFadeFactor(indexOfRepeat);
|
||||||
printf("%f ", fade);
|
printf("%f ", fade, samplesToWriteThisIteration);
|
||||||
addBufferToScope(_scopeOutputLeft, _scopeOutputOffset, lastFrameData, samplesToWriteThisIteration, 0, STEREO_FACTOR, fade);
|
addBufferToScope(_scopeOutputLeft, _scopeOutputOffset, lastFrameData, samplesToWriteThisIteration, 0, STEREO_FACTOR, fade);
|
||||||
_scopeOutputOffset = addBufferToScope(_scopeOutputRight, _scopeOutputOffset, lastFrameData, samplesToWriteThisIteration, 1, STEREO_FACTOR, fade);
|
_scopeOutputOffset = addBufferToScope(_scopeOutputRight, _scopeOutputOffset, lastFrameData, samplesToWriteThisIteration, 1, STEREO_FACTOR, fade);
|
||||||
|
|
||||||
|
printf("scopeOutputOffset %d\n", _scopeOutputOffset);
|
||||||
|
|
||||||
samplesRemaining -= samplesToWriteThisIteration;
|
samplesRemaining -= samplesToWriteThisIteration;
|
||||||
|
indexOfRepeat++;
|
||||||
} while (samplesRemaining > 0);
|
} while (samplesRemaining > 0);
|
||||||
printf("\n");
|
printf("\t end\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer) {
|
void Audio::processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer) {
|
||||||
|
@ -1755,7 +1764,7 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo)
|
||||||
// setup our general output device for audio-mixer audio
|
// setup our general output device for audio-mixer audio
|
||||||
_audioOutput = new QAudioOutput(outputDeviceInfo, _outputFormat, this);
|
_audioOutput = new QAudioOutput(outputDeviceInfo, _outputFormat, this);
|
||||||
_audioOutput->setBufferSize(AUDIO_OUTPUT_BUFFER_SIZE_FRAMES * _outputFrameSize * sizeof(int16_t));
|
_audioOutput->setBufferSize(AUDIO_OUTPUT_BUFFER_SIZE_FRAMES * _outputFrameSize * sizeof(int16_t));
|
||||||
qDebug() << "Ring Buffer capacity in frames: " << _audioOutput->bufferSize() / sizeof(int16_t) / (float)_outputFrameSize;
|
qDebug() << "Output Buffer capacity in frames: " << _audioOutput->bufferSize() / sizeof(int16_t) / (float)_outputFrameSize;
|
||||||
|
|
||||||
_audioOutputIODevice.start();
|
_audioOutputIODevice.start();
|
||||||
_audioOutput->start(&_audioOutputIODevice);
|
_audioOutput->start(&_audioOutputIODevice);
|
||||||
|
|
|
@ -176,7 +176,6 @@ int InboundAudioStream::parseAudioData(PacketType type, const QByteArray& packet
|
||||||
}
|
}
|
||||||
|
|
||||||
int InboundAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
int InboundAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
||||||
|
|
||||||
// calculate how many silent frames we should drop.
|
// calculate how many silent frames we should drop.
|
||||||
int samplesPerFrame = _ringBuffer.getNumFrameSamples();
|
int samplesPerFrame = _ringBuffer.getNumFrameSamples();
|
||||||
int desiredJitterBufferFramesPlusPadding = _desiredJitterBufferFrames + DESIRED_JITTER_BUFFER_FRAMES_PADDING;
|
int desiredJitterBufferFramesPlusPadding = _desiredJitterBufferFrames + DESIRED_JITTER_BUFFER_FRAMES_PADDING;
|
||||||
|
@ -198,7 +197,9 @@ int InboundAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
||||||
_framesAvailableStat.reset();
|
_framesAvailableStat.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _ringBuffer.addSilentSamples(silentSamples - numSilentFramesToDrop * samplesPerFrame);
|
int ret = _ringBuffer.addSilentSamples(silentSamples - numSilentFramesToDrop * samplesPerFrame);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InboundAudioStream::popSamples(int maxSamples, bool allOrNothing, bool starveIfNoSamplesPopped) {
|
int InboundAudioStream::popSamples(int maxSamples, bool allOrNothing, bool starveIfNoSamplesPopped) {
|
||||||
|
|
|
@ -20,23 +20,25 @@ MixedProcessedAudioStream::MixedProcessedAudioStream(int numFrameSamples, int nu
|
||||||
|
|
||||||
void MixedProcessedAudioStream::outputFormatChanged(int outputFormatChannelCountTimesSampleRate) {
|
void MixedProcessedAudioStream::outputFormatChanged(int outputFormatChannelCountTimesSampleRate) {
|
||||||
_outputFormatChannelsTimesSampleRate = outputFormatChannelCountTimesSampleRate;
|
_outputFormatChannelsTimesSampleRate = outputFormatChannelCountTimesSampleRate;
|
||||||
int deviceOutputFrameSize = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL * _outputFormatChannelsTimesSampleRate / SAMPLE_RATE;
|
int deviceOutputFrameSize = networkToDeviceSamples(NETWORK_BUFFER_LENGTH_SAMPLES_STEREO);
|
||||||
_ringBuffer.resizeForFrameSize(deviceOutputFrameSize);
|
_ringBuffer.resizeForFrameSize(deviceOutputFrameSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MixedProcessedAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
int MixedProcessedAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
||||||
|
|
||||||
int deviceSilentSamplesWritten = InboundAudioStream::writeDroppableSilentSamples(networkToDeviceSamples(silentSamples));
|
int deviceSilentSamplesWritten = InboundAudioStream::writeDroppableSilentSamples(networkToDeviceSamples(silentSamples));
|
||||||
|
|
||||||
emit addedSilence(deviceToNetworkSamples(deviceSilentSamplesWritten) / STEREO_FACTOR);
|
emit addedSilence(deviceToNetworkSamples(deviceSilentSamplesWritten) / STEREO_FACTOR);
|
||||||
|
|
||||||
return deviceSilentSamplesWritten;
|
return deviceSilentSamplesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MixedProcessedAudioStream::writeLastFrameRepeatedWithFade(int samples) {
|
int MixedProcessedAudioStream::writeLastFrameRepeatedWithFade(int samples) {
|
||||||
|
|
||||||
int deviceSamplesWritten = InboundAudioStream::writeLastFrameRepeatedWithFade(networkToDeviceSamples(samples));
|
int deviceSamplesWritten = InboundAudioStream::writeLastFrameRepeatedWithFade(networkToDeviceSamples(samples));
|
||||||
|
|
||||||
emit addedLastFrameRepeatedWithFade(deviceToNetworkSamples(deviceSamplesWritten) / STEREO_FACTOR);
|
emit addedLastFrameRepeatedWithFade(deviceToNetworkSamples(deviceSamplesWritten) / STEREO_FACTOR);
|
||||||
|
|
||||||
return deviceSamplesWritten;
|
return deviceSamplesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,14 +50,14 @@ int MixedProcessedAudioStream::parseAudioData(PacketType type, const QByteArray&
|
||||||
emit processSamples(packetAfterStreamProperties, outputBuffer);
|
emit processSamples(packetAfterStreamProperties, outputBuffer);
|
||||||
|
|
||||||
_ringBuffer.writeData(outputBuffer.data(), outputBuffer.size());
|
_ringBuffer.writeData(outputBuffer.data(), outputBuffer.size());
|
||||||
|
|
||||||
return packetAfterStreamProperties.size();
|
return packetAfterStreamProperties.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int MixedProcessedAudioStream::networkToDeviceSamples(int networkSamples) {
|
int MixedProcessedAudioStream::networkToDeviceSamples(int networkSamples) {
|
||||||
return networkSamples * _outputFormatChannelsTimesSampleRate / (STEREO_FACTOR * SAMPLE_RATE);
|
return (quint64)networkSamples * (quint64)_outputFormatChannelsTimesSampleRate / (quint64)(STEREO_FACTOR * SAMPLE_RATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MixedProcessedAudioStream::deviceToNetworkSamples(int deviceSamples) {
|
int MixedProcessedAudioStream::deviceToNetworkSamples(int deviceSamples) {
|
||||||
return deviceSamples * (STEREO_FACTOR * SAMPLE_RATE) / _outputFormatChannelsTimesSampleRate;
|
return (quint64)deviceSamples * (quint64)(STEREO_FACTOR * SAMPLE_RATE) / (quint64)_outputFormatChannelsTimesSampleRate;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue