Skip to content

Commit

Permalink
Removing mInBufCopy since it is no longer necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedickey committed Jan 9, 2024
1 parent 52fd51e commit 9274742
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 53 deletions.
73 changes: 25 additions & 48 deletions src/AudioInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ AudioInterface::~AudioInterface()
i->disconnect();
delete i;
}
for (int i = 0; i < mInBufCopy.size(); i++) {
delete[] mInBufCopy[i];
}
}

//*******************************************************************************
Expand All @@ -126,10 +123,10 @@ void AudioInterface::setup(bool /*verbose*/)
size_audio_output = mSizeInBytesPerChannel * mNumNetRevChans;
}
#endif // endwhere
const size_t audioInputPacketSize = std::max<size_t>(size_audio_input,
mInputChans.size() * sizeof(sample_t) * nframes);
const size_t audioOutputPacketSize = std::max<size_t>(size_audio_output,
mOutputChans.size() * sizeof(sample_t) * nframes);
const size_t audioInputPacketSize = std::max<size_t>(
size_audio_input, mInputChans.size() * sizeof(sample_t) * nframes);
const size_t audioOutputPacketSize = std::max<size_t>(
size_audio_output, mOutputChans.size() * sizeof(sample_t) * nframes);
mAudioInputPacket = new int8_t[audioInputPacketSize];
mAudioOutputPacket = new int8_t[audioOutputPacketSize];

Expand Down Expand Up @@ -168,11 +165,6 @@ void AudioInterface::setup(bool /*verbose*/)
// set memory to 0
std::memset(mOutProcessBuffer[i], 0, sizeof(sample_t) * nframes);
}
mInBufCopy.resize(mInputChans.size());
for (int i = 0; i < mInputChans.size(); i++) {
mInBufCopy[i] =
new sample_t[MAX_AUDIO_BUFFER_SIZE]; // required for processing audio input
}
}

//*******************************************************************************
Expand All @@ -194,17 +186,11 @@ void AudioInterface::callback(QVarLengthArray<sample_t*>& in_buffer,
void AudioInterface::audioInputCallback(QVarLengthArray<sample_t*>& in_buffer,
unsigned int n_frames)
{
// Send packets to network:
// mAudioTesterP will be nullptr for hub server's JackTripWorker instances:
bool audioTesting = (mAudioTesterP && mAudioTesterP->getEnabled());
if (!audioTesting && mProcessPluginsToNetwork.size() == 0
&& mProcessPluginsToMonitor.size() == 0) {
// copy saved if no plugins and no audio testing in progress:
if (mProcessWithNetwork) {
computeProcessToNetwork(
in_buffer, n_frames); // send processed input audio to network - OUTGOING
}
return;
// in_buffer is "in" from local audio hardware
if (getBufferSizeInSamples() < n_frames) { // allocated in constructor above
std::cerr << "*** AudioInterface::audioInputCallback n_frames = " << n_frames
<< " larger than expected = " << getBufferSizeInSamples() << "\n";
exit(1);
}

#ifndef WAIR
Expand All @@ -218,48 +204,37 @@ void AudioInterface::audioInputCallback(QVarLengthArray<sample_t*>& in_buffer,
}
#endif // not WAIR

// TODO: is this really necessary??

// cannot modify in_buffer, so make a copy
// in_buffer is "in" from local audio hardware
if (mInBufCopy.size() < mInputChans.size()) { // created in constructor above
std::cerr << "*** AudioInterface.cpp: Number of Input Channels changed - "
"insufficient room reserved\n";
exit(1);
}
if (MAX_AUDIO_BUFFER_SIZE < n_frames) { // allocated in constructor above
std::cerr << "*** AudioInterface.cpp: n_frames = " << n_frames
<< " larger than expected max = " << MAX_AUDIO_BUFFER_SIZE << "\n";
exit(1);
}
for (int i = 0; i < mInputChans.size(); i++) {
std::memcpy(mInBufCopy[i], in_buffer[i], sizeof(sample_t) * n_frames);
}

// process incoming signal from audio interface using process plugins
for (auto* p : qAsConst(mProcessPluginsToNetwork)) {
if (p->getInited()) {
p->compute(n_frames, mInBufCopy.data(), mInBufCopy.data());
p->compute(n_frames, in_buffer.data(), in_buffer.data());
}
}

// add audio testing impulse, if enabled
if (audioTesting) {
if (mAudioTesterP && mAudioTesterP->getEnabled()) {
mAudioTesterP->writeImpulse(
mInBufCopy,
n_frames); // writes last channel of mInBufCopy with test impulse
in_buffer,
n_frames); // writes last channel of in_buffer with test impulse
}

// send the final signal to the network
if (mProcessWithNetwork) {
computeProcessToNetwork(mInBufCopy, n_frames);
computeProcessToNetwork(in_buffer, n_frames);
}
}

//*******************************************************************************
void AudioInterface::audioOutputCallback(QVarLengthArray<sample_t*>& out_buffer,
unsigned int n_frames)
{
// in_buffer is "in" from local audio hardware
if (getBufferSizeInSamples() < n_frames) { // allocated in constructor above
std::cerr << "*** AudioInterface::audioOutputCallback n_frames = " << n_frames
<< " larger than expected = " << getBufferSizeInSamples() << "\n";
exit(1);
}

// 1) First, process incoming packets

#ifdef WAIR // WAIR
Expand Down Expand Up @@ -302,7 +277,8 @@ void AudioInterface::audioOutputCallback(QVarLengthArray<sample_t*>& out_buffer,
// mix in the monitor signal
// note that using memory_order_acquire ensures all data written to the buffers
// will be also available be available to this thread before read
std::memset(mAudioOutputPacket, 0, sizeof(sample_t) * n_frames * getNumInputChannels());
std::memset(mAudioOutputPacket, 0,
sizeof(sample_t) * n_frames * getNumInputChannels());
mMonitorQueuePtr->pop(mAudioOutputPacket);
for (int i = 0; i < getNumOutputChannels(); i++) {
// if using mix-to-mono, in_buffer[0] should already contain the mixed
Expand All @@ -311,7 +287,8 @@ void AudioInterface::audioOutputCallback(QVarLengthArray<sample_t*>& out_buffer,
// likewise if using mono, we simply copy the input to every monitor
// channel
int8_t* sample_ptr = mAudioOutputPacket;
if (i > 0 && getNumInputChannels() > i && mInputMixMode == AudioInterface::STEREO) {
if (i > 0 && getNumInputChannels() > i
&& mInputMixMode == AudioInterface::STEREO) {
// otherwise, copy each channel individually
sample_ptr += (i * sizeof(sample_t) * n_frames);
}
Expand Down
8 changes: 3 additions & 5 deletions src/AudioInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,8 @@ class AudioInterface
QVarLengthArray<sample_t*>
mNetInBuffer; ///< Vector of Input buffers/channel read from net
QVarLengthArray<sample_t*>
mAPInBuffer; ///< Vector of Input buffers/channel for AllPass input
#endif // endwhere
QVarLengthArray<sample_t*>
mInBufCopy; ///< needed in callback() to modify JACK audio input
mAPInBuffer; ///< Vector of Input buffers/channel for AllPass input
#endif // endwhere
int mAudioBitResolution; ///< Bit resolution in audio samples
AudioInterface::audioBitResolutionT
mBitResolutionMode; ///< Bit resolution (audioBitResolutionT) mode
Expand All @@ -344,7 +342,7 @@ class AudioInterface
QVarLengthArray<sample_t*>
mOutProcessBuffer; ///< Vector of Output buffers/channel for ProcessPlugin
WaitFreeFrameBuffer<64>*
mMonitorQueuePtr; //< Queue of audio frames from monitor signal
mMonitorQueuePtr; //< Queue of audio frames from monitor signal
int8_t* mAudioInputPacket; ///< Packet containing all the channels to read from the
///< RingBuffer
int8_t* mAudioOutputPacket; ///< Packet containing all the channels to send to the
Expand Down

0 comments on commit 9274742

Please sign in to comment.