Use the AudioFileReadBytes function from Audio Services Examples can be found in the Finch sound engine see the Sound+IO category.
Use the AudioFileReadBytes function from Audio Services. Examples can be found in the Finch sound engine, see the Sound+IO category.
As for how the sample code links and builds, it's not finding a prototype (if you turn on -Wall, you'll get an implicit function declaration warning), but OpenAL. Framework--at least in the SDK they are using in the sample project--does in fact export _alutLoadWAVFile, which you can check with nm. What's the exact link error you get, and what SDK are you using?
Thanks for the help. I'm not using the library itself, because Apple's sample code does not use it. Instead, the sample code uses the 10.4 SDK, and links to System/Library/Frameworks/OpenAL.framework.
I am doing the same. Only diff I could see between projects is that my xcode compatibility is 3.1, theirs is 2.4. So, I commented out my and lines, and instead used the the old OpenAL headers. I restored alutLoadWAVFile back in to my code, and voila!
I now have wav support. It's a workaround, but I'll take it!Cheers. – SirRatty Apr 30 '09 at 23:27.
I'm sure you've solved this already, but for people who find this via Google, here's some barely tested WAV loading code. It works but you'd better double check for memory leaks and whatnot before using for something real. Static bool LoadWAVFile(const char* filename, ALenum* format, ALvoid** data, ALsizei* size, ALsizei* freq, Float64* estimatedDurationOut) { CFStringRef filenameStr = CFStringCreateWithCString( NULL, filename, kCFStringEncodingUTF8 ); CFURLRef url = CFURLCreateWithFileSystemPath( NULL, filenameStr, kCFURLPOSIXPathStyle, false ); CFRelease( filenameStr ); AudioFileID audioFile; OSStatus error = AudioFileOpenURL( url, kAudioFileReadPermission, kAudioFileWAVEType, &audioFile ); CFRelease( url ); if ( error!
= noErr ) { fprintf( stderr, "Error opening audio file. %d\n", error ); return false; } AudioStreamBasicDescription basicDescription; UInt32 propertySize = sizeof(basicDescription); error = AudioFileGetProperty( audioFile, kAudioFilePropertyDataFormat, &propertySize, &basicDescription ); if ( error! = noErr ) { fprintf( stderr, "Error reading audio file basic description.
%d\n", error ); AudioFileClose( audioFile ); return false; } if ( basicDescription. MFormatID! = kAudioFormatLinearPCM ) { // Need PCM for Open AL.
WAVs are (I believe) by definition PCM, so this check isn't necessary. It's just here // in case I ever use this with another audio format. Fprintf( stderr, "Audio file is not linear-PCM.
%d\n", basicDescription. MFormatID ); AudioFileClose( audioFile ); return false; } UInt64 audioDataByteCount = 0; propertySize = sizeof(audioDataByteCount); error = AudioFileGetProperty( audioFile, kAudioFilePropertyAudioDataByteCount, &propertySize, &audioDataByteCount ); if ( error! = noErr ) { fprintf( stderr, "Error reading audio file byte count.
%d\n", error ); AudioFileClose( audioFile ); return false; } Float64 estimatedDuration = 0; propertySize = sizeof(estimatedDuration); error = AudioFileGetProperty( audioFile, kAudioFilePropertyEstimatedDuration, &propertySize, &estimatedDuration ); if ( error! = noErr ) { fprintf( stderr, "Error reading estimated duration of audio file. %d\n", error ); AudioFileClose( audioFile ); return false; } ALenum alFormat = 0; if ( basicDescription.
MChannelsPerFrame == 1 ) { if ( basicDescription. MBitsPerChannel == 8 ) alFormat = AL_FORMAT_MONO8; else if ( basicDescription. MBitsPerChannel == 16 ) alFormat = AL_FORMAT_MONO16; else { fprintf( stderr, "Expected 8 or 16 bits for the mono channel but got %d\n", basicDescription.
MBitsPerChannel ); AudioFileClose( audioFile ); return false; } } else if ( basicDescription. MChannelsPerFrame == 2 ) { if ( basicDescription. MBitsPerChannel == 8 ) alFormat = AL_FORMAT_STEREO8; else if ( basicDescription.
MBitsPerChannel == 16 ) alFormat = AL_FORMAT_STEREO16; else { fprintf( stderr, "Expected 8 or 16 bits per channel but got %d\n", basicDescription. MBitsPerChannel ); AudioFileClose( audioFile ); return false; } } else { fprintf( stderr, "Expected 1 or 2 channels in audio file but got %d\n", basicDescription. MChannelsPerFrame ); AudioFileClose( audioFile ); return false; } UInt32 numBytesToRead = audioDataByteCount; void* buffer = malloc( numBytesToRead ); if ( buffer == NULL ) { fprintf( stderr, "Error allocating buffer for audio data of size %u\n", numBytesToRead ); return false; } error = AudioFileReadBytes( audioFile, false, 0, &numBytesToRead, buffer ); AudioFileClose( audioFile ); if ( error!
= noErr ) { fprintf( stderr, "Error reading audio bytes. %d\n", error ); free(buffer); return false; } if ( numBytesToRead! = audioDataByteCount ) { fprintf( stderr, "Tried to read %lld bytes from the audio file but only got %d bytes\n", audioDataByteCount, numBytesToRead ); free(buffer); return false; } *freq = basicDescription.
MSampleRate; *size = audioDataByteCount; *format = alFormat; *data = buffer; *estimatedDurationOut = estimatedDuration; return true; }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.