I have a .aif file which I try to read and add to a char* buffer. After the first read, I get the -38 error. What does it mean and how to solve this? Here is my code:
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *filename = [NSString stringWithFormat:@"test-1"];
NSString *path = [mainBundle pathForResource:filename ofType:@"aif"];
if (!path)
return;
NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
AudioFileID audioFile;
OSStatus err = AudioFileOpenURL((__bridge CFURLRef)(aFileURL), kAudioFileReadPermission, 0, &audioFile);
// get the number of audio data bytes
UInt64 numBytes = 0;
UInt32 dataSize = sizeof(numBytes);
err = AudioFileGetProperty(audioFile, kAudioFilePropertyAudioDataByteCount, &dataSize, &numBytes);
unsigned char *audioBuffer = (unsigned char *)malloc(numBytes);
UInt32 toRead = numBytes;
UInt64 offset = 0;
unsigned char *pBuffer = audioBuffer;
while(true) {
err = AudioFileReadBytes(audioFile, true, offset, &toRead, &pBuffer); //!! I GET ERROR HERE
if (kAudioFileEndOfFileError == err) {
// cool, we're at the end of the file
break;
} else if (noErr != err) {
// uh-oh, some error other than eof
break;
}
// advance the next read offset
offset += toRead;
// advance the read buffer's pointer
pBuffer += toRead;
toRead = numBytes - offset;
if (0 == toRead) {
// got to the end of file but no eof err
break;
}
}
//work with audioBuffer...