Initialize some pointers properly, and redesign to reallocate the converter buffer instead of freeing it every time
This commit is contained in:
parent
2997033e6b
commit
a52c54a12c
1 changed files with 9 additions and 5 deletions
|
@ -37,6 +37,11 @@ void PrintStreamDesc (AudioStreamBasicDescription *inDesc)
|
|||
{
|
||||
rgInfo = nil;
|
||||
|
||||
converterFloat = NULL;
|
||||
converter = NULL;
|
||||
floatBuffer = NULL;
|
||||
callbackBuffer = NULL;
|
||||
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.volumeScaling" options:0 context:nil];
|
||||
}
|
||||
|
||||
|
@ -119,11 +124,7 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter,
|
|||
|
||||
amountToWrite = (*ioNumberDataPackets)*(converter->inputFormat.mBytesPerPacket);
|
||||
|
||||
if (converter->callbackBuffer != NULL)
|
||||
{
|
||||
free(converter->callbackBuffer);
|
||||
}
|
||||
converter->callbackBuffer = malloc(amountToWrite);
|
||||
converter->callbackBuffer = realloc(converter->callbackBuffer, amountToWrite);
|
||||
|
||||
amountRead = [converter readData:converter->callbackBuffer amount:amountToWrite];
|
||||
if (amountRead == 0 && [converter endOfStream] == NO)
|
||||
|
@ -330,6 +331,9 @@ static float db_to_scale(float db)
|
|||
floatFormat.mBytesPerFrame = (32/8)*floatFormat.mChannelsPerFrame;
|
||||
floatFormat.mBytesPerPacket = floatFormat.mBytesPerFrame * floatFormat.mFramesPerPacket;
|
||||
|
||||
floatOffset = 0;
|
||||
floatSize = 0;
|
||||
|
||||
stat = AudioConverterNew( &inputFormat, &floatFormat, &converterFloat );
|
||||
if (stat != noErr)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue