Choppy sound with non-44.1khz PCM files
Choppy sound with non-44.1khz PCM files
- Subject: Choppy sound with non-44.1khz PCM files
- From: john <email@hidden>
- Date: Fri, 4 Nov 2005 18:45:59 -0500
Hi,
I'm having weirdness reading and converting audio from a PCM audio
file which has a sample rate other than 44100hz .
After reading using AudioFileReadBytes() and converting using
AudioConverterFillBuffer() (no errors for either) it sounds like very
small chunks of the audio are missing.
I have included a code snippet for anyone willing to take a look.
Thanks.
-- John
<snippet>
- (unsigned long)readData: (NSMutableData*)theAudioData range:
(NSRange)range
{
unsigned long lengthRead = range.length;
unsigned long lengthConverted = 0;
unsigned long totalLengthConverted = 0;
unsigned long size = sizeof(lengthConverted);
float bytesMultiplier = ((float)
theAudioFileStreamDescription.mBytesPerFrame / (float)
standardStreamFormat.mBytesPerFrame);
float sampleRateMultiplier =
(theAudioFileStreamDescription.mSampleRate /
standardStreamFormat.mSampleRate);
OSStatus theStatus;
readPosition = range.location;
bufferFed = NO;
lastReadLength = 0;
if (!AudioConverterGetProperty(theConverterWrite,
kAudioConverterPropertyCalculateOutputBufferSize, &size, &lengthRead))
{
if ([intermediateReadBuffer length] != lengthRead)
[intermediateReadBuffer setLength: lengthRead];
theStatus = AudioFileReadBytes(theAudioFileID, NO, readPosition,
&lengthRead, [intermediateReadBuffer mutableBytes]);
lastReadLength = lengthRead;
if ((theStatus == eofErr) || (theStatus == noErr))
{
if (lengthRead > 0)
{
lengthConverted = range.length;
while ('done' != AudioConverterFillBuffer(theConverterRead,
readFillBufferProc, self, &lengthConverted, [theAudioData
mutableBytes]))
{
totalLengthConverted += lengthConverted;
lengthConverted = range.length;
}
lengthConverted = totalLengthConverted;
}
}
}
if (lengthConverted > 0)
readPosition += (unsigned long)((float)lengthConverted * (float)
bytesMultiplier * (float)sampleRateMultiplier);
return lengthConverted;
}
- (OSStatus)readFillBuffer: (void**)outData ioDataSize: (UInt32*)
ioDataSize
{
OSStatus theResult = noErr;
if (bufferFed != YES)
{
*ioDataSize = lastReadLength;
*outData = (void*)[intermediateReadBuffer bytes];
bufferFed = YES;
}
else
{
ioDataSize = 0;
theResult = 'done';
}
return theResult;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden