mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-21 14:02:57 +02:00
Another case where extra deinterleaving isn't necessary. CopySamples() can do
the job quite nicely...well, given the "stride" information he needs. And in some cases, it will just use memcpy() so it may improve capture performance a bit more.
This commit is contained in:
@@ -3570,44 +3570,10 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
|
||||
|
||||
if (len > 0) {
|
||||
for( t = 0; t < numCaptureChannels; t++) {
|
||||
|
||||
// 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->mCaptureBuffers[t]->Put(((samplePtr)inputBuffer) + (t * SAMPLE_SIZE(gAudioIO->mCaptureFormat)),
|
||||
gAudioIO->mCaptureFormat,
|
||||
len);
|
||||
len,
|
||||
numCaptureChannels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ int RingBuffer::AvailForPut()
|
||||
}
|
||||
|
||||
int RingBuffer::Put(samplePtr buffer, sampleFormat format,
|
||||
int samplesToCopy)
|
||||
int samplesToCopy, int stride /* = 1 */)
|
||||
{
|
||||
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);
|
||||
block, true, stride);
|
||||
|
||||
src += block * SAMPLE_SIZE(format);
|
||||
pos = (pos + block) % mBufferSize;
|
||||
|
@@ -23,7 +23,7 @@ class RingBuffer {
|
||||
//
|
||||
|
||||
int AvailForPut();
|
||||
int Put(samplePtr buffer, sampleFormat format, int samples);
|
||||
int Put(samplePtr buffer, sampleFormat format, int samples, int stride = 1);
|
||||
|
||||
//
|
||||
// For the reader only:
|
||||
|
Reference in New Issue
Block a user