2

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...
just ME
  • 1,817
  • 6
  • 32
  • 53
  • I get the error in : err = AudioFileReadBytes(audioFile, true, offset, &toRead, &pBuffer); when it comes to do the second reading from .aif file – just ME Jun 05 '14 at 09:43
  • Did you ever figure this out? I am getting a 38 error on my second operation on an audio file too. – narco Nov 17 '16 at 15:04
  • Error 38 is a "File not open" error. For me it turned out I hadn't opened it properly. I think your issue may be different. – narco Nov 17 '16 at 16:02
  • @narco Did you find the answer why unable to open file – AMI amitekh May 26 '17 at 13:07
  • @AMIamitekh My answer is directly above your comment – narco May 28 '17 at 17:50

0 Answers0