Hello all,
I've been staring at this code for three days now trying to figure out what I'm doing wrong. I am attempting to open a WAVE file (2-channel, 44.1 KHz 16-bit signed integer), seek to a point in it, and extract some of the audio to a separate file after some processing. I have done this numerous times in the past without problems, but for some reason my new code isn't working properly. Here is what I have (I'm using 10.5 with gc enabled, although compiling with gc off has no effect on this particular issue):
// Open the file for reading ExtAudioFileRef file = NULL; OSStatus status = ExtAudioFileOpenURL((CFURLRef)[NSURL fileURLWithPath:path], &file); if(noErr != status) goto cleanup; // Determine the total number of audio frames in the file (for debugging output) SInt64 totalFrames = -1; dataSize = sizeof(totalFrames); status = ExtAudioFileGetProperty(file, kExtAudioFileProperty_FileLengthFrames, &dataSize, &totalFrames); if(noErr != status) goto cleanup; NSLog(@"Total frames in file = %qi", totalFrames); // Seek to the desired starting sector SInt64 frame = AUDIO_FRAMES_PER_CDDA_SECTOR * firstSector; NSLog(@"Seeking to frame %qi", frame); status = ExtAudioFileSeek(file, frame); NSLog(@"ExtAudioFileSeek = %i", status); if(noErr != status) goto cleanup;
Here is the output I'm seeing:
Total frames in file = 20599404 Seeking to frame 10783332 ExtAudioFileSeek = -66568
I've also tried using the FSRef version of ExtAudioFileOpen, but that didn't make a difference.
I know the file is valid and can be opened by Core Audio, because afinfo and afplay work correctly:
Macintosh:Release-Tiger+ me$ ./afinfo /tmp/Disc\ Image.wav File: /tmp/Disc Image.wav File type ID: WAVE Data format: 2 ch, 44100 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer no channel layout. estimated duration: 467.107 sec audio bytes: 82397616 audio packets: 20599404 bit rate: 1411200 bits per second maximum packet size: 4 packet size upper bound: 4 audio data file offset: 4096 optimized Source Has Channel Layout: FALSE Source Has Region List: FALSE Source Has Marker List: FALSE ----
and the kicker is that
Macintosh:Release-Tiger+ me$ ./afplay -f 10783332 /tmp/Disc\ Image.wav
works perfectly as well! So surely there is a mistake in my code somewhere, but I can' see it.
Stephen |