diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index f3fc9fe1b..4be8c0703 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -3613,10 +3613,44 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, if (len > 0) { for( t = 0; t < numCaptureChannels; t++) { - gAudioIO->mCaptureBuffers[t]->Put(((samplePtr)inputBuffer) + (t * SAMPLE_SIZE(gAudioIO->mCaptureFormat)), + + // dmazzoni: + // Un-interleave. Ugly special-case code required because the + // capture channels could be in three different sample formats; + // it'd be nice to be able to call CopySamples, but it can't + // handle multiplying by the gain and then clipping. Bummer. + + switch(gAudioIO->mCaptureFormat) { + case floatSample: { + float *inputFloats = (float *)inputBuffer; + for( i = 0; i < len; i++) + tempFloats[i] = + inputFloats[numCaptureChannels*i+t]; + } break; + case int24Sample: + // We should never get here. Audacity's int24Sample format + // is different from PortAudio's sample format and so we + // make PortAudio return float samples when recording in + // 24-bit samples. + wxASSERT(false); + break; + case int16Sample: { + short *inputShorts = (short *)inputBuffer; + short *tempShorts = (short *)tempBuffer; + for( i = 0; i < len; i++) { + float tmp = inputShorts[numCaptureChannels*i+t]; + if (tmp > 32767) + tmp = 32767; + if (tmp < -32768) + tmp = -32768; + tempShorts[i] = (short)(tmp); + } + } break; + } // switch + + gAudioIO->mCaptureBuffers[t]->Put((samplePtr)tempBuffer, gAudioIO->mCaptureFormat, - len, - numCaptureChannels); + len); } } } diff --git a/src/RingBuffer.cpp b/src/RingBuffer.cpp index b31c95eac..5aa234483 100644 --- a/src/RingBuffer.cpp +++ b/src/RingBuffer.cpp @@ -53,7 +53,7 @@ int RingBuffer::AvailForPut() } int RingBuffer::Put(samplePtr buffer, sampleFormat format, - int samplesToCopy, int stride /* = 1 */) + int samplesToCopy) { samplePtr src; int block; @@ -75,7 +75,7 @@ int RingBuffer::Put(samplePtr buffer, sampleFormat format, CopySamples(src, format, mBuffer + pos * SAMPLE_SIZE(mFormat), mFormat, - block, true, stride); + block); src += block * SAMPLE_SIZE(format); pos = (pos + block) % mBufferSize; diff --git a/src/RingBuffer.h b/src/RingBuffer.h index ac06bda79..a1bfc0033 100644 --- a/src/RingBuffer.h +++ b/src/RingBuffer.h @@ -23,7 +23,7 @@ class RingBuffer { // int AvailForPut(); - int Put(samplePtr buffer, sampleFormat format, int samples, int stride = 1); + int Put(samplePtr buffer, sampleFormat format, int samples); // // For the reader only: