0

For my special scenario, i want to read an audio file< MP3, AAC...> by buffer, like 512Kb for each buffer, and convert this buffer to PCM data and pass to AudioQueue's play callback. Just like when recording, we have callback like this:

static OSStatus recordingCallback(void *inRefCon,
                                  AudioUnitRenderActionFlags *ioActionFlags,
                                  const AudioTimeStamp *inTimeStamp,
                                  UInt32 inBusNumber,
                                  UInt32 inNumberFrames,
                                  AudioBufferList *ioData)

And we can use AudioBufferList *ioData to play, How can i convert my buffer above to this type? Many thanks.

Edit: I have a method to get audio buffer like this :

-(NSData *) readAudioFile:(NSString *)filePath fromOffset:(long long) offset readSize:(long)readSize {
    NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];

    NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
    long long fileSize = [fileSizeNumber longLongValue];
    if(offset >= fileSize)
        return nil;

    NSFileHandle *fReadHandle = [NSFileHandle fileHandleForReadingAtPath:filePath];
    [fReadHandle seekToFileOffset:offset];
    NSData *data = [fReadHandle readDataOfLength:readSize];
[fReadHandle closeFile];
    return data;
}

and NSData *audioData = [self readAudioFile:@"aa.mp3" fromOffset:0 readSize:512 * 1024]; Now i have the buffer: audioData, how do pass this buffer to AudioQueue or other service to play it.

The Bird
  • 397
  • 2
  • 8
  • 19

0 Answers0