mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 05:52:31 +02:00
fix scope for input
This commit is contained in:
parent
1f9ca00317
commit
cdc6f33128
3 changed files with 25 additions and 32 deletions
|
@ -309,8 +309,10 @@ void Audio::handleAudioInput() {
|
||||||
_inputFormat, _desiredInputFormat);
|
_inputFormat, _desiredInputFormat);
|
||||||
|
|
||||||
// add input data just written to the scope
|
// add input data just written to the scope
|
||||||
// QMetaObject::invokeMethod(_scope, "addStereoSamples", Qt::QueuedConnection,
|
QMetaObject::invokeMethod(_scope, "addSamples", Qt::QueuedConnection,
|
||||||
// Q_ARG(QByteArray, inputByteArray), Q_ARG(bool, true));
|
Q_ARG(QByteArray, QByteArray((char*) monoAudioSamples,
|
||||||
|
NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL)),
|
||||||
|
Q_ARG(bool, false), Q_ARG(bool, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (Menu::getInstance()->isOptionChecked(MenuOption::EchoLocalAudio)) {
|
// if (Menu::getInstance()->isOptionChecked(MenuOption::EchoLocalAudio)) {
|
||||||
|
@ -420,20 +422,6 @@ void Audio::addReceivedAudioToBuffer(const QByteArray& audioByteArray) {
|
||||||
|
|
||||||
int16_t outputBuffer[numRequiredOutputSamples];
|
int16_t outputBuffer[numRequiredOutputSamples];
|
||||||
|
|
||||||
// linearResampling((int16_t*) inputByteArray.data(),
|
|
||||||
// monoAudioSamples,
|
|
||||||
// inputByteArray.size() / sizeof(int16_t),
|
|
||||||
// numResampledNetworkInputSamples,
|
|
||||||
// _inputFormat, _desiredInputFormat);
|
|
||||||
|
|
||||||
// copy the packet from the RB to the output
|
|
||||||
// linearResampling(monoAudioSamples,
|
|
||||||
// (int16_t*) _outputBuffer.data(),
|
|
||||||
// numResampledNetworkInputSamples,
|
|
||||||
// numResampledOutputBytes / sizeof(int16_t),
|
|
||||||
// _desiredInputFormat, _outputFormat);
|
|
||||||
|
|
||||||
|
|
||||||
// if there is anything in the ring buffer, decide what to do
|
// if there is anything in the ring buffer, decide what to do
|
||||||
if (_ringBuffer.samplesAvailable() > 0) {
|
if (_ringBuffer.samplesAvailable() > 0) {
|
||||||
if (!_ringBuffer.isNotStarvedOrHasMinimumSamples(NETWORK_BUFFER_LENGTH_SAMPLES_STEREO
|
if (!_ringBuffer.isNotStarvedOrHasMinimumSamples(NETWORK_BUFFER_LENGTH_SAMPLES_STEREO
|
||||||
|
|
|
@ -68,24 +68,18 @@ Oscilloscope::~Oscilloscope() {
|
||||||
delete[] _samples;
|
delete[] _samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Oscilloscope::addStereoSamples(const QByteArray& audioByteArray, bool isInput) {
|
void Oscilloscope::addSamples(const QByteArray& audioByteArray, bool isStereo, bool isInput) {
|
||||||
|
|
||||||
if (! enabled || inputPaused) {
|
if (! enabled || inputPaused) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int numSamplesPerChannel = audioByteArray.size() / (sizeof(int16_t) * 2);
|
int numSamplesPerChannel = audioByteArray.size() / (sizeof(int16_t) * (isStereo ? 2 : 1));
|
||||||
int16_t samples[numSamplesPerChannel];
|
int16_t* samples = (int16_t*) audioByteArray.data();
|
||||||
const int16_t* stereoSamples = (int16_t*) audioByteArray.constData();
|
|
||||||
|
|
||||||
for (int channel = 0; channel < (isInput ? 1 : 2); channel++) {
|
for (int channel = 0; channel < (isStereo ? 1 : 2); channel++) {
|
||||||
// add samples for each of the channels
|
// add samples for each of the channels
|
||||||
|
|
||||||
// enumerate the interleaved stereoSamples array and pull out the samples for this channel
|
|
||||||
for (int i = 0; i < audioByteArray.size() / sizeof(int16_t); i += 2) {
|
|
||||||
samples[i / 2] = stereoSamples[i + channel];
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine start/end offset of this channel's region
|
// determine start/end offset of this channel's region
|
||||||
unsigned baseOffs = MAX_SAMPLES_PER_CHANNEL * (channel + !isInput);
|
unsigned baseOffs = MAX_SAMPLES_PER_CHANNEL * (channel + !isInput);
|
||||||
unsigned endOffs = baseOffs + MAX_SAMPLES_PER_CHANNEL;
|
unsigned endOffs = baseOffs + MAX_SAMPLES_PER_CHANNEL;
|
||||||
|
@ -103,10 +97,21 @@ void Oscilloscope::addStereoSamples(const QByteArray& audioByteArray, bool isInp
|
||||||
numSamplesPerChannel -= n2;
|
numSamplesPerChannel -= n2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy data
|
if (!isStereo) {
|
||||||
memcpy(_samples + writePos, samples, numSamplesPerChannel * sizeof(int16_t));
|
// copy data
|
||||||
if (n2 > 0) {
|
memcpy(_samples + writePos, samples, numSamplesPerChannel * sizeof(int16_t));
|
||||||
memcpy(_samples + baseOffs, samples + numSamplesPerChannel, n2 * sizeof(int16_t));
|
if (n2 > 0) {
|
||||||
|
memcpy(_samples + baseOffs, samples + numSamplesPerChannel, n2 * sizeof(int16_t));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// we have interleaved samples we need to separate into two channels
|
||||||
|
for (int i = 0; i < numSamplesPerChannel + n2; i++) {
|
||||||
|
if (i < numSamplesPerChannel - n2) {
|
||||||
|
_samples[writePos] = samples[(i * 2) + channel];
|
||||||
|
} else {
|
||||||
|
_samples[baseOffs] = samples[(i * 2) + channel];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set new write position for this channel
|
// set new write position for this channel
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
// just uses every nTh sample.
|
// just uses every nTh sample.
|
||||||
void setDownsampleRatio(unsigned n) { assert(n > 0); _downsampleRatio = n; }
|
void setDownsampleRatio(unsigned n) { assert(n > 0); _downsampleRatio = n; }
|
||||||
public slots:
|
public slots:
|
||||||
void addStereoSamples(const QByteArray& audioByteArray, bool isInput);
|
void addSamples(const QByteArray& audioByteArray, bool isStereo, bool isInput);
|
||||||
private:
|
private:
|
||||||
// don't copy/assign
|
// don't copy/assign
|
||||||
Oscilloscope(Oscilloscope const&); // = delete;
|
Oscilloscope(Oscilloscope const&); // = delete;
|
||||||
|
|
Loading…
Reference in a new issue