void MyCopyEncoderCookieToFile(AudioQueueRef queue, AudioFileID theFile) { OSStatus error; UInt32 propertySize; error = AudioQueueGetPropertySize(queue, kAudioConverterCompressionMagicCookie, &propertySize); if (error == noErr && propertySize > 0) { Byte *magicCookie = (Byte *)malloc(propertySize); CheckError(AudioQueueGetProperty(queue, kAudioQueueProperty_MagicCookie, magicCookie, &propertySize), "Couldn't get audio queue's magic cookie!"); CheckError(AudioFileSetProperty(theFile, kAudioFilePropertyMagicCookieData, propertySize, magicCookie), "Couldn't set audio file's magic cookie"); free(magicCookie); } }
void set_stream() { OSStatus err; UInt32 propertySize; // get the magic cookie, if any, from the converter err = AudioQueueGetPropertySize(d_owner->queue, kAudioConverterCompressionMagicCookie, &propertySize); if (err == noErr && propertySize > 0) { // there is valid cookie data to be fetched; get it Byte *magicCookie = (Byte *)malloc(propertySize); err = AudioQueueGetProperty(d_owner->queue, kAudioConverterCompressionMagicCookie, magicCookie, &propertySize); if (err == 0) { // now set the magic cookie on the output file // even though some formats have cookies, some files don't take them, so we ignore the error /*err =*/ AudioFileSetProperty(d_owner->stm, kAudioFilePropertyMagicCookieData, propertySize, magicCookie); } free(magicCookie); } /* if (err != 0) trace_fmt("failed to set stream, %.4s", &err); */ }
// ____________________________________________________________________________________ // Copy a queue's encoder's magic cookie to an audio file. static void MyCopyEncoderCookieToFile(AudioQueueRef theQueue, AudioFileID theFile) { OSStatus err; UInt32 propertySize; // get the magic cookie, if any, from the converter err = AudioQueueGetPropertySize(theQueue, kAudioConverterCompressionMagicCookie, &propertySize); if (err == noErr && propertySize > 0) { // there is valid cookie data to be fetched; get it Byte *magicCookie = (Byte *)malloc(propertySize); try { XThrowIfError(AudioQueueGetProperty(theQueue, kAudioConverterCompressionMagicCookie, magicCookie, &propertySize), "get audio converter's magic cookie"); // now set the magic cookie on the output file // even though some formats have cookies, some files don't take them, so we ignore the error /*err =*/ AudioFileSetProperty(theFile, kAudioFilePropertyMagicCookieData, propertySize, magicCookie); } catch (CAXException e) { char buf[256]; fprintf(stderr, "MyCopyEncoderCookieToFile: %s (%s)\n", e.mOperation, e.FormatError(buf)); } catch (...) { fprintf(stderr, "MyCopyEncoderCookieToFile: Unexpected exception\n"); } free(magicCookie); } }
OSStatus SetMagicCookieForFile ( AudioQueueRef inQueue, // 1 AudioFileID inFile // 2 ) { OSStatus result = noErr; // 3 UInt32 cookieSize; // 4 if ( AudioQueueGetPropertySize ( // 5 inQueue, kAudioQueueProperty_MagicCookie, &cookieSize ) == noErr ) { char* magicCookie = (char *) malloc (cookieSize); // 6 if ( AudioQueueGetProperty ( // 7 inQueue, kAudioQueueProperty_MagicCookie, magicCookie, &cookieSize ) == noErr ) result = AudioFileSetProperty ( // 8 inFile, kAudioFilePropertyMagicCookieData, cookieSize, magicCookie ); free (magicCookie); // 9 } return result; // 10 }
bool music_obj<audio_queue_driver>::is_playing() const { UInt32 size, is_running; AudioQueueGetPropertySize(queue_, kAudioQueueProperty_IsRunning, &size); AudioQueueGetProperty(queue_, kAudioQueueProperty_IsRunning, &is_running, &size); return is_running && !is_paused_; }
void SoundRecorder::setAudioFileMagicCookie(void) { /* Query the size of the magic cookie: */ UInt32 magicCookieSize; if(AudioQueueGetPropertySize(queue,kAudioQueueProperty_MagicCookie,&magicCookieSize)==noErr) { /* Allocate a buffer for the magic cookie: */ char* magicCookie=new char[magicCookieSize]; /* Copy the magic cookie from the audio queue into the audio file: */ if(AudioQueueGetProperty(queue,kAudioQueueProperty_MagicCookie,magicCookie,&magicCookieSize)==noErr) AudioFileSetProperty(audioFile,kAudioFilePropertyMagicCookieData,magicCookieSize,magicCookie); /* Delete the cookie buffer: */ delete[] magicCookie; } }
// ____________________________________________________________________________________ // Copy a queue's encoder's magic cookie to an audio file. static void MyCopyEncoderCookieToFile(AudioQueueRef theQueue, AudioFileID theFile) { OSStatus err; UInt32 propertySize; // get the magic cookie, if any, from the converter err = AudioQueueGetPropertySize(theQueue, kAudioConverterCompressionMagicCookie, &propertySize); if (err == noErr && propertySize > 0) { // there is valid cookie data to be fetched; get it Byte *magicCookie = (Byte *)malloc(propertySize); CheckError(AudioQueueGetProperty(theQueue, kAudioConverterCompressionMagicCookie, magicCookie, &propertySize), "get audio converter's magic cookie"); // now set the magic cookie on the output file err = AudioFileSetProperty(theFile, kAudioFilePropertyMagicCookieData, propertySize, magicCookie); free(magicCookie); } }