diff options
author | Werner Schweer <ws.seh.de> | 2006-10-13 09:18:59 +0000 |
---|---|---|
committer | Werner Schweer <ws.seh.de> | 2006-10-13 09:18:59 +0000 |
commit | acdc9dde3922777da489aaf2666bbba3a6115956 (patch) | |
tree | 80189c870ca4e65470f1198a23533383dbbe0555 | |
parent | 5aa37077be920d45d6861864f4a6164a0974937b (diff) |
fix buffer handling
-rw-r--r-- | muse/muse/audioinput.cpp | 14 | ||||
-rw-r--r-- | muse/muse/audiooutput.cpp | 37 | ||||
-rw-r--r-- | muse/muse/audiooutput.h | 5 | ||||
-rw-r--r-- | muse/muse/audiotrack.cpp | 2 | ||||
-rw-r--r-- | muse/muse/audiotrack.h | 3 |
5 files changed, 38 insertions, 23 deletions
diff --git a/muse/muse/audioinput.cpp b/muse/muse/audioinput.cpp index 96e3fde6..ef9ce7a2 100644 --- a/muse/muse/audioinput.cpp +++ b/muse/muse/audioinput.cpp @@ -37,6 +37,16 @@ AudioInput::AudioInput() jackPorts[i] = 0; _channels = 0; setChannels(2); + // + // buffers are allocated from AudioTrack() + // and not needed by AudioInput which uses + // the JACK supplied buffers + for (int i = 0; i < MAX_CHANNELS; ++i) { + if (buffer[i]) { + delete[] buffer[i]; + buffer[i] = 0; + } + } } //--------------------------------------------------------- @@ -49,6 +59,10 @@ AudioInput::~AudioInput() if (jackPorts[i]) audioDriver->unregisterPort(jackPorts[i]); } + // AudioInput does not own buffers (they are from JACK) + // make sure ~AudioTrack() does not delete them: + for (int i = 0; i < MAX_CHANNELS; ++i) + buffer[i] = 0; } //--------------------------------------------------------- diff --git a/muse/muse/audiooutput.cpp b/muse/muse/audiooutput.cpp index abde7f5a..acdeeed1 100644 --- a/muse/muse/audiooutput.cpp +++ b/muse/muse/audiooutput.cpp @@ -36,6 +36,18 @@ AudioOutput::AudioOutput() jackPorts[i] = 0; _channels = 0; setChannels(2); + + // + // buffers are allocated from AudioTrack() + // and not needed by AudioOutput which uses + // the JACK supplied buffers + + for (int i = 0; i < MAX_CHANNELS; ++i) { + if (buffer[i]) { + delete[] buffer[i]; + buffer[i] = 0; + } + } } //--------------------------------------------------------- @@ -44,8 +56,14 @@ AudioOutput::AudioOutput() AudioOutput::~AudioOutput() { - for (int i = 0; i < _channels; ++i) - audioDriver->unregisterPort(jackPorts[i]); + for (int i = 0; i < _channels; ++i) { + if (jackPorts[i]) + audioDriver->unregisterPort(jackPorts[i]); + } + // AudioOutput does not own buffers (they are from JACK) + // make sure ~AudioTrack() does not delete them: + for (int i = 0; i < MAX_CHANNELS; ++i) + buffer[i] = 0; } //--------------------------------------------------------- @@ -72,7 +90,6 @@ void AudioOutput::read(QDomNode node) setName(name()); // allocate jack ports } - //--------------------------------------------------------- // setChannels //--------------------------------------------------------- @@ -194,17 +211,11 @@ void AudioOutput::stopRecording(const Pos& /*s*/, const Pos& /*e*/) void AudioOutput::process() { + for (int c = 0; c < channels(); ++c) + buffer[c] = audioDriver->getBuffer(jackPorts[c], segmentSize); + AudioTrack::process(); - for (int c = 0; c < channels(); ++c) { - float* sp = buffer[c]; -if (jackPorts[c] == 0) - abort(); - float* dp = audioDriver->getBuffer(jackPorts[c], segmentSize); - for (unsigned k = 0; k < segmentSize; ++k) - *dp++ = *sp++; - } -#if 0 int n = segmentSize; if (audio->isRecording() && recordFlag() && _recFile) { // bounce to file @@ -213,7 +224,6 @@ if (jackPorts[c] == 0) else putFifo(channels(), n, buffer); } -#endif #if 0 if (audioClickFlag && song->click() && metronome) { @@ -229,4 +239,3 @@ if (jackPorts[c] == 0) #endif } - diff --git a/muse/muse/audiooutput.h b/muse/muse/audiooutput.h index 40eb6362..055929ab 100644 --- a/muse/muse/audiooutput.h +++ b/muse/muse/audiooutput.h @@ -31,10 +31,6 @@ class AudioOutput : public AudioTrack { Q_OBJECT void* jackPorts[MAX_CHANNELS]; -// float* buffer[MAX_CHANNELS]; - unsigned long _nframes; - - float* _monitorBuffer[MAX_CHANNELS]; public: AudioOutput(); @@ -55,7 +51,6 @@ class AudioOutput : public AudioTrack { virtual bool canRecord() const { return true; } virtual void stopRecording(const AL::Pos&, const AL::Pos&); - float** monitorBuffer() { return _monitorBuffer; } void silence(unsigned); virtual void process(); }; diff --git a/muse/muse/audiotrack.cpp b/muse/muse/audiotrack.cpp index 45395d94..65c3f5a1 100644 --- a/muse/muse/audiotrack.cpp +++ b/muse/muse/audiotrack.cpp @@ -60,7 +60,6 @@ AudioTrack::AudioTrack(TrackType t) c->setRange(-1.0f, +1.0f); addController(c); - buffer = new float*[MAX_CHANNELS]; for (int i = 0; i < MAX_CHANNELS; ++i) buffer[i] = new float[segmentSize]; } @@ -77,7 +76,6 @@ AudioTrack::~AudioTrack() if (buffer[i]) delete[] buffer[i]; } - delete[] buffer; } //--------------------------------------------------------- diff --git a/muse/muse/audiotrack.h b/muse/muse/audiotrack.h index 4f05b0ec..b702cf80 100644 --- a/muse/muse/audiotrack.h +++ b/muse/muse/audiotrack.h @@ -43,8 +43,7 @@ class AudioTrack : public Track { void readRecfile(QDomNode); protected: - float** buffer; // this buffer is filled by process() - // _volume and _pan is not applied + float* buffer[MAX_CHANNELS]; // this buffer is filled by process() bool bufferEmpty; // set by process() to optimize // data flow |