Playing & Recording Audio Audio Queue Services Playback - AQPlayer Class

Similar documents
Playing & Recording Audio Audio Queue Services Recording - AQRecorder Class

Playing & Recording Audio Audio Queue Services Playback

Audio Queue Services. Dave

Contents. Introduction 7. What Is Core Audio? 10. Core Audio Essentials 19. Organization of This Document 8 See Also 8

Audio Unit Properties Reference

AVAudioPlayer. avtouch Application

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

#include <tobii/tobii.h> char const* tobii_error_message( tobii_error_t error );

AVAudioRecorder & System Sound Services

Common Misunderstandings from Exam 1 Material

INTERFACING REAL-TIME AUDIO AND FILE I/O

QNX SDK for Apps and Media 1.1. Multimedia Playlist Library Reference

Mac OS X Server Developer s Kit. Apple Filing Protocol Client

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Process Concept

QNX SDK for Apps and Media 1.0. Multimedia Playlist Library Reference

Opus Generated by Doxygen Thu May :22:05

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

SIMATIC Industrial software Readme SIMATIC S7-PLCSIM Advanced V2.0 SP1 Readme

Building a (Core) Foundation. Rob Napier

PDF Document structure, that need for managing of PDF file. It uses in all functions from EMF2PDF SDK.

As you convert your QuickDraw application to one that uses only Quartz, there are two primary issues you ll face with respect to PICT data:

CS24 Week 4 Lecture 2

Motivation was to facilitate development of systems software, especially OS development.

JAVA MOCK TEST JAVA MOCK TEST II

HikVision Mpeg4 linux Player SDK

elastique efficient time stretching SDK by zplane.development (c) 2017 zplane.development GmbH & Co. KG

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

Graphics & Animation: 2D Drawing

Appendix A Pseudocode of the wlan_mac Process Model in OPNET

CS24 Week 4 Lecture 1

CHAPTER 3 - PROCESS CONCEPT

Concurrency: Mutual Exclusion and Synchronization. Concurrency

Multicast Dissemination Protocol (MDP) Developer's Guide

Kevin van Vechten Core OS

CS 140 Project 4 File Systems Review Session

Chapter 3: Processes. Operating System Concepts 9 th Edition

Call DLL from Limnor Applications

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

CS510 Operating System Foundations. Jonathan Walpole

Compositional C++ Page 1 of 17

When EMG starts, the shared library that contains the plugin is loaded and the API function create_config() is called:

Armide Documentation. Release Kyle Mayes

Anybus CompactCom. Host Application Implementation Guide. Doc.Id. HMSI Doc. Rev Connecting DevicesTM

Pointers, Pointers, Pointers!

G3 PHYSICAL LAYER API SPECIFICATION

Requirements. Left To Implement. Design. Extended Plugin Interface

ECE454 Tutorial. June 16, (Material prepared by Evan Jones)

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory.

Quiz 0 Review Session. October 13th, 2014

Chapter 6: Process Synchronization

int fnvgetconfig(handle h, UINT32 id, const void *cfg, size_t sz);... 4

Dotstack Porting Guide.

CS5460/6460: Operating Systems. Lecture 11: Locking. Anton Burtsev February, 2014

MBS Xojo AudioPlayer Kit

Chapter 1 Getting Started

When EMG starts, the shared library that contains the plugin is loaded and this API function is called:

OptimiData. JPEG2000 Software Development Kit for C/C++ Reference Manual. Version 1.6. from

Auto-Pipe Software Block Interface v2. Interface. Contents. Auto-Pipe Types. From Auto-Pipe Wiki

Motivation was to facilitate development of systems software, especially OS development.

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Suggested Solutions (Midterm Exam October 27, 2005)

Queues. A queue is a special type of structure that can be used to maintain data in an organized way.

CS240: Programming in C

Caching and Buffering in HDF5

Chapter 2. Procedural Programming

UPDATES AND CORRECTIONS JANUARY 2002

What s New in Core Audio

Robot Raconteur using MATLAB Version 0.8 Beta

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

VS1053B PCM Mixer. VSMPG VLSI Solution Audio Decoder. Project Code: Project Name:

Section 10: Device Drivers, FAT, Queuing Theory, Memory Mapped Files

Media Playback and Recording. CS193W - Spring Lecture 3

Deadlock. Lecture 4: Synchronization & Communication - Part 2. Necessary conditions. Deadlock handling. Hierarchical resource allocation

/Users/Bruce/Documents/Devel/LocalizeString/main.c

Lecture 8 Dynamic Memory Allocation

// Initially NULL, points to the dynamically allocated array of bytes. uint8_t *data;

Discovering the ios Instruments Server

CLD SC58x CDC Library v.1.00 Users Guide Users Guide Revision For Use With Analog Devices ADSP-SC58x Series Processors. Closed Loop Design, LLC

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology

PRINCIPLES OF OPERATING SYSTEMS

This document contains the questions and solutions to the CS107 midterm given in Winter 2018 by instructor Chris Gregg. This was a 120-minute exam.

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

LAB 5, THE HIDDEN DELIGHTS OF LINKED LISTS

Pointers, Dynamic Data, and Reference Types

Project 5: File Systems

APPENDIX A : Example Standard <--Prev page Next page -->

Logical disks. Bach 2.2.1

ADTs Stack and Queue. Outline

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL II)

Vive Input Utility Developer Guide

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Parallel System Architectures 2016 Lab Assignment 1: Cache Coherency

µroar Manual Philipp ph3-der-loewe Schafft

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

Transcription:

Playing & Recording Audio Audio Queue Services Playback - AQPlayer Class 11 2010-2 iphone Application Index 1. AQPlayer 2. SpeakHere Classes & Resources 3. SpeakHere Class 4. AQPlayer Class 5. AQPlayer.h 6. Ready for Playback Flow 7. Start Playback Flow 8. Stop Playback Flow

iphone Application AQPlayer Sound Playback SpeakHere iphone Application Classes & Resources AQPlayer :

SpeakHere avtouch Application SpeakHereAppDelegate AQRecorder SpeakHereController SpeakHereViewController AQPlayer... AQPlayer,,! AQRecorder avtouch Classes Class & Resources AQPlayer 9 SetupNewQueue StartQueue AQBufferCallback isrunningproc DisposeQueue CreateQueueForFile CalculateBytesForTime StopQueue

avtouch AQRecorder.h Classes & Resources AQPlayer 1. public &! AQPlayer(! ~AQPlayer(! OSStatus!!!!!! StartQueue(BOOL inresume! OSStatus!!!!!! StopQueue(!!! OSStatus!!!!!! PauseQueue(!!! AudioQueueRef!!!! Queue()!!!! { return mqueue; }! CAStreamBasicDescription!! DataFormat() const!! { return mdataformat; }!!! Boolean!!!!!! IsRunning()!const!! { return (misrunning)? true : false; }! Boolean!!!!!! IsInitialized()! const! { return misinitialized; }!!! CFStringRef!!!!!! GetFilePath() const!! { return (mfilepath)? mfilepath : CFSTR("" }! Boolean!!!!!! IsLooping() const!! { return mislooping; }!!! void SetLooping(Boolean inislooping)!{ mislooping = inislooping; }! void CreateQueueForFile(CFStringRef infilepath! void DisposeQueue(Boolean indisposefile! 2. private &! UInt32!!! GetNumPacketsToRead()!!!! { return mnumpacketstoread; }! SInt64!!! GetCurrentPacket()!!!! { return mcurrentpacket; }! AudioFileID!! GetAudioFileID()!!!!! { return maudiofile; }! void!!! SetCurrentPacket(SInt64 inpacket)! { mcurrentpacket = inpacket; }!!! void!!! SetupNewQueue(!!! AudioQueueRef! mqueue;! AudioQueueBufferRef!mBuffers[kNumberBuffers];! AudioFileID!! maudiofile;! CFStringRef!! mfilepath;! CAStreamBasicDescription!! mdataformat;! Boolean!! misinitialized;! UInt32!!! mnumpacketstoread;! SInt64!!! mcurrentpacket;! UInt32!!! misrunning;! Boolean!! misdone;! Boolean!! mislooping; static void isrunningproc( void * inuserdata,!!!! AudioQueueRef inaq,!!!! AudioQueuePropertyID inid static void AQBufferCallback(!void *!! inuserdata,!!!!! AudioQueueRef!!! inaq,!!!!! AudioQueueBufferRef!! incompleteaqbuffer void CalculateBytesForTime( CAStreamBasicDescription & indesc,!!!! UInt32 inmaxpacketsize,!!!! Float64 inseconds,!!!! UInt32 *outbuffersize,!!!! UInt32 *outnumpackets! Ready for Playback Flow

1. avtouch Queue Classes &( ) Resources 1. AQPlayer - main() misrunning=false AQPlayer - AQPlayer::AQPlayer AQPlayer::AQPlayer() :! mqueue(0),! maudiofile(0),! mfilepath(null),! misrunning(false),! misinitialized(false),! mnumpacketstoread(0),! mcurrentpacket(0),! misdone(false),! mislooping(false) { } 2. Stop(Record) SpeakHereController StopRecord 1) stoprecord recorder AQRecorder::StopRecord ( ) 2) player AQPlayer::DisposeQueue(Boolean indisposefile) SpeakHereController::stopRecord - (void)stoprecord {... recorder->stoprecord( } player->disposequeue(true... // dispose the previous playback queue 1. avtouch Queue Classes &( ) Resources 3. 1) AudioQueueRef mqueue AQPlayer::DisposeQueue! if (mqueue)! {!! AudioQueueDispose(mQueue, true!! mqueue = NULL;! } 2) indisposefile( ) Dispose AQPlayer::DisposeQueue ( )! if (indisposefile)! {!! if (maudiofile)!! {!!!!! AudioFileClose(mAudioFile!!! maudiofile = 0;!! }!! if (mfilepath)!! {!!! CFRelease(mFilePath!!! mfilepath = NULL;!! }! }

void AQPlayer::DisposeQueue() AudioQueueDispose Disposes of an audio queue. OSStatus AudioQueueDispose ( AudioQueueRef inaq, Boolean inimmediate inaq The audio queue you want to dispose of. inimmediate If you pass true, the audio queue is disposed of immediately (that is, synchronously). If you pass false, disposal does not take place until all enqueued buffers are processed (that is, asynchronously). void AQPlayer::DisposeQueue() AudioFileClose Closes an audio file. OSStatus AudioFileClose ( AudioFileID inaudiofile inaudiofile The file you want to close.

void AQPlayer::DisposeQueue() CFRelease Releases a Core Foundation object. void CFRelease ( CFTypeRef cf cf A CFType object to release. This value must not be NULL. 1. avtouch Queue Classes &( ) Resources SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord AQPlayer DisposeQueue mqueue maudio mfilepath}

2. avtouch Audio Classes Queue & Resources 1. SpeakHereController StopRecord AQPlayer::CreateQueueForFile(CFStringRef infilepath) 1) recordfilepath SpeakHereController::stopRecord! // now create a new queue for the recorded file! recordfilepath = (CFStringRef)[NSTemporaryDirectory() stringbyappendingpathcomponent: @"recordedfile.caf"]; 2) recordfilepath player AQPlayer::CreateQueueForFile SpeakHereController::stopRecord ( )! player->createqueueforfile(recordfilepath 2. avtouch Audio Classes Queue & Resources ( ) 2. infilepath mfilepath 1) CFStringRef mfilepath NULL, infilepath 2) mfilepath 3) mfilepath SetupNewQueue AQPlayer::CreateQueueForFile void AQPlayer::CreateQueueForFile(CFStringRef infilepath) {!! CFURLRef sndfile = NULL;...!if (mfilepath == NULL)!! //! {!! mislooping = false;!!!! sndfile = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, infilepath, kcfurlposixpathstyle, false!! if (!sndfile) { printf("can't parse file path\n" return; }!!!!! XThrowIfError(AudioFileOpenURL(sndFile, kaudiofilereadpermission, 0/*inFileTypeHint*/, &maudiofile), "can't open file"!!!! UInt32 size = sizeof(mdataformat!! XThrowIfError(AudioFileGetProperty(mAudioFile, kaudiofilepropertydataformat, &size, &mdataformat), "couldn't get file's data format"!! mfilepath = CFStringCreateCopy(kCFAllocatorDefault, infilepath! } SetupNewQueue(!!... }

void AQPlayer::CreateQueueForFile() CFURLCreateWithFileSystemPath Creates a CFURL object using a local file system path string. CFURLRef CFURLCreateWithFileSystemPath ( CFAllocatorRef allocator, CFStringRef filepath, CFURLPathStyle pathstyle, Boolean isdirectory allocator The allocator to use to allocate memory for the new CFURL object. Pass NULL or kcfallocatordefault to use the current default allocator. filepath The path string to convert to a CFURL object. pathstyle isdirectory The operating system path style used in filepath. A Boolean value that specifies whether filepath is treated as a directory path when resolving against relative path components. Pass true if the pathname indicates a directory, false otherwise. void AQPlayer::CreateQueueForFile() AudioFileOpenURL Open an existing audio file specified by a URL. OSStatus AudioFileOpenURL ( CFURLRef infileref, SInt8 inpermissions, AudioFileTypeID infiletypehint, AudioFileID *outaudiofile infileref The URL of an existing audio file. inpermissions infiletypehint outaudiofile The read-write permissions you want to assign to the file. A hint for the file type of the designated file. For files without filename extensions and with types not easily or uniquely determined from the data (such as ADTS or AC3), use this hint to indicate the file type. Otherwise, pass 0. On output, a pointer to the newly opened audio file.

void AQPlayer::CreateQueueForFile() AudioFileGetProperty Gets the value of an audio file property. OSStatus AudioFileGetProperty ( AudioFileID inaudiofile, AudioFilePropertyID inpropertyid, UInt32 *iodatasize, void *outpropertydata inaudiofile inpropertyid iodatasize outpropertydata The audio file you want to obtain a property value from. The property whose value you want. On input, the size of the buffer passed in the outpropertydata parameter. On output, the number of bytes written to the buffer. Use the AudioFileGetPropertyInfo function to obtain the size of the property value. On output, the value of the property specified in the inpropertyid parameter. void AQPlayer::CreateQueueForFile() CFStringCreateCopy Creates an immutable copy of a string. CFStringRef CFStringCreateCopy ( CFAllocatorRef alloc, CFStringRef thestring alloc The allocator to use to allocate memory for the new string. Pass NULL or kcfallocatordefault to use the current default allocator. thestring The string to copy.

2. avtouch Audio Classes Queue & Resources ( ) SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord AQPlayer DisposeQueue mqueue recordfilepath maudio mfilepath} CreateQueueForFile 2. avtouch Audio Classes Queue & Resources ( ) 3. Queue 1) Queue AQPlayer::SetupNewQueue! XThrowIfError(AudioQueueNewOutput(&mDataFormat, AQPlayer::AQBufferCallback, this,!!!!!!!! CFRunLoopGetCurrent(), kcfrunloopcommonmodes, 0, &mqueue), "AudioQueueNew failed" 2) AQPlayer::SetupNewQueue! UInt32 maxpacketsize;! UInt32 size = sizeof(maxpacketsize! XThrowIfError(AudioFileGetProperty(mAudioFile, kaudiofilepropertypacketsizeupperbound, &size, &maxpacketsize), "couldn't get file's max packet size" 3) CalculateBytesForTime AQPlayer::SetupNewQueue! // adjust buffer size to represent about a half second of audio based on this format! UInt32 bufferbytesize;! CalculateBytesForTime (mdataformat, maxpacketsize, kbufferdurationseconds, &bufferbytesize, &mnumpacketstoread

void AQPlayer::SetupNewQueue() AudioQueueNewOutput Creates a new playback audio queue object. OSStatus AudioQueueNewOutput ( const AudioStreamBasicDescription AudioQueueOutputCallback void CFRunLoopRef CFStringRef UInt32 AudioQueueRef *informat, incallbackproc, *inuserdata, incallbackrunloop, incallbackrunloopmode, inflags, *outaq informat incallbackproc inuserdata incallbackrunloop incallbackrunloopm ode The data format of the audio to play. For linear PCM, only interleaved formats are supported. Compressed formats are also supported. A callback function to use with the playback audio queue. The audio queue invokes the callback when the audio queue has finished acquiring a buffer A custom data structure for use with the callback function. The event loop on which the callback function pointed to by the incallbackproc parameter is to be called. If you specify NULL, the callback is invoked on one of the audio queue s internal threads. The run loop mode in which to invoke the callback function specified in the incallbackproc parameter. inflags Reserved for future use. Must be 0. outaq On output, the newly created playback audio queue object. void AQPlayer::SetupNewQueue() AudioFileGetProperty Gets the value of an audio file property. OSStatus AudioFileGetProperty ( AudioFileID inaudiofile, AudioFilePropertyID inpropertyid, UInt32 *iodatasize, void *outpropertydata inaudiofile inpropertyid iodatasize outpropertydata The audio file you want to obtain a property value from. The property whose value you want. On input, the size of the buffer passed in the outpropertydata parameter. On output, the number of bytes written to the buffer. Use the AudioFileGetPropertyInfo function to obtain the size of the property value. On output, the value of the property specified in the inpropertyid parameter.

2. avtouch Audio Classes Queue & Resources ( ) SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord AQPlayer DisposeQueue mqueue recordfilepath maudio mfilepath} CreateQueueForFile SetupNewQueue 2. avtouch Audio Classes Queue & Resources ( ) 4. 1). 16K~64K ( ) AQPlayer::CalculateBytesForTime // we only use time here as a guideline // we're really trying to get somewhere between 16K and 64K buffers, // but not allocate too much if we don't need it static const int maxbuffersize = 0x10000; // limit size to 64K static const int minbuffersize = 0x4000; // limit size to 16K 2) AQPlayer:: CalculateBytesForTime! if (indesc.mframesperpacket) {!! Float64 numpacketsfortime = indesc.msamplerate / indesc.mframesperpacket * inseconds;!! *outbuffersize = numpacketsfortime * inmaxpacketsize;! } else {!! *outbuffersize = maxbuffersize > inmaxpacketsize? maxbuffersize : inmaxpacketsize;! } 3) AQPlayer:: CalculateBytesForTime! // we're going to limit our size to our default! if (*outbuffersize > maxbuffersize && *outbuffersize > inmaxpacketsize)!! *outbuffersize = maxbuffersize;! else {!! // also make sure we're not too small - we don't want to go the disk for too small chunks!! if (*outbuffersize < minbuffersize)!!! *outbuffersize = minbuffersize;! } *outnumpackets = *outbuffersize / inmaxpacketsize;

2. avtouch Audio Classes Queue & Resources ( ) SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord AQPlayer DisposeQueue mqueue recordfilepath maudio mfilepath} CreateQueueForFile SetupNewQueue CalculateBytesForTime 2. avtouch Audio Classes Queue & Resources ( ) 5. Queue 1), Queue AQPlayer::SetupNewQueue! // (2) If the file has a cookie, we should get it and set it on the AQ! size = sizeof(uint32! OSStatus result = AudioFileGetPropertyInfo (maudiofile, kaudiofilepropertymagiccookiedata, &size, NULL!! if (!result && size) {!! char* cookie = new char [size];!!!! XThrowIfError (AudioFileGetProperty (maudiofile, kaudiofilepropertymagiccookiedata, &size, cookie), "get cookie from file"!! XThrowIfError (AudioQueueSetProperty(mQueue, kaudioqueueproperty_magiccookie, cookie, size), "set cookie on queue"!! delete [] cookie;! } 2) AQPlayer::SetupNewQueue! // channel layout?! result = AudioFileGetPropertyInfo(mAudioFile, kaudiofilepropertychannellayout, &size, NULL! if (result == noerr && size > 0) {!! AudioChannelLayout *acl = (AudioChannelLayout *)malloc(size!! XThrowIfError(AudioFileGetProperty(mAudioFile, kaudiofilepropertychannellayout, &size, acl), "get audio file's channel layout"!! XThrowIfError(AudioQueueSetProperty(mQueue, kaudioqueueproperty_channellayout, acl, size), "set channel layout on queue"!! free(acl! }

void AQPlayer::SetupNewQueue() AudioFileGetPropertyInfo Gets information about an audio file property, including the size of the property value and whether the value is writable. OSStatus AudioFileGetPropertyInfo ( AudioFileID inaudiofile, AudioFilePropertyID inpropertyid, UInt32 *outdatasize, UInt32 *iswritable inaudiofile The audio file you want to obtain property value information from. inpropertyid The property whose value information you want. outdatasize On output, the size in bytes of the property value. iswritable On output, equals 1 if the property is writable, or 0 if it is read-only. void AQPlayer::SetupNewQueue() AudioQueueSetProperty Sets an audio queue property value. OSStatus AudioQueueSetProperty ( AudioQueueRef inaq, AudioQueuePropertyID inid, const void *indata, UInt32 indatasize inaq inid indata The audio queue that you want to set a property value on. The ID of the property whose value you want to set. The property value to set. iodatasize The size of the property data.

void AQPlayer::SetupNewQueue() AudioChannelLayout Specifies a channel layout in a file or in hardware. struct AudioChannelLayout { AudioChannelLayoutTag mchannellayouttag; UInt32 mchannelbitmap; UInt32 mnumberchanneldescriptions; AudioChannelDescription mchanneldescriptions[1]; }; typedef struct AudioChannelLayout AudioChannelLayout; mchannellayouttag The AudioChannelLayoutTag value that indicates the layout. mchannelbitmap If mchannellayouttag is set to kaudiochannellayouttag_usechannelbitmap, this field is the channel-use bitmap. mnumberchanneldescriptions The number of items in the mchanneldescriptions array. mchanneldescriptions A variable length array of mnumberchanneldescription elements that describes a layout. If the mchannellayouttag field is set to kaudiochannellayouttag_usechanneldescriptions, use this field to describe the layout. 2. avtouch Audio Classes Queue & Resources ( ) SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord AQPlayer DisposeQueue mqueue recordfilepath maudio mfilepath} CreateQueueForFile SetupNewQueue CalculateBytesForTime

2. avtouch Audio Classes Queue & Resources ( ) 3) Queue AQPlayer::SetupNewQueue! XThrowIfError(AudioQueueAddPropertyListener(mQueue, kaudioqueueproperty_isrunning, isrunningproc, this),!!!! "adding property listener"!! bool isformatvbr = (mdataformat.mbytesperpacket == 0 mdataformat.mframesperpacket == 0! for (int i = 0; i < knumberbuffers; ++i) {!! XThrowIfError(AudioQueueAllocateBufferWithPacketDescriptions(mQueue, bufferbytesize, (isformatvbr? mnumpacketstoread : 0), &mbuffers[i]), "AudioQueueAllocateBuffer failed" 6. ( / ) :. AQPlayer::isRunningProc AQPlayer *THIS = (AQPlayer *)inuserdata; UInt32 size = sizeof(this->misrunning OSStatus result = AudioQueueGetProperty (inaq, kaudioqueueproperty_isrunning, &THIS->mIsRunning, &size! if ((result == noerr) && (!THIS->mIsRunning))! [[NSNotificationCenter defaultcenter] postnotificationname: @"playbackqueuestopped" object: nil]; 7. Queue ( ) AQPlayer::SetupNewQueue! // set the volume of the queue! XThrowIfError (AudioQueueSetParameter(mQueue, kaudioqueueparam_volume, 1.0), "set queue volume"!! misinitialized = true; void AQPlayer::SetupNewQueue() AudioQueueAddPropertyListener Adds a property listener callback to an audio queue. OSStatus AudioQueueAddPropertyListener ( AudioQueueRef inaq, AudioQueuePropertyID inid, AudioQueuePropertyListenerProc inproc, void *inuserdata inaq inid inproc The audio queue that you want to assign a property listener callback to. The ID of the property whose changes you want to respond to. The callback to be invoked when the property value changes. inuserdata Custom data for the property listener callback.

void AQPlayer::SetupNewQueue() AudioQueueAllocateBufferWithPacketDescriptions Asks an audio queue object to allocate an audio queue buffer with space for packet descriptions. AudioQueueAllocateBufferWithPacketDescriptions( AudioQueueRef inaq, UInt32 inbufferbytesize, UInt32 innumberpacketdescriptions, AudioQueueBufferRef *outbuffer inaq inbufferbytesize innumberpacketdesc riptions outbuffer The audio queue you want to allocate a buffer. The desired data capacity of the new buffer, in bytes. Appropriate capacity depends on the processing you will perform on the data as well as on the audio data format. The desired size of the packet description array in the new audio queue buffer. On output, points to the newly allocated audio queue buffer. void AQPlayer::SetupNewQueue() AudioQueueSetParameter Sets a playback audio queue parameter value. OSStatus AudioQueueSetParameter ( AudioQueueRef inaq, AudioQueueParameterID inparamid, AudioQueueParameterValue invalue inaq The playback audio queue that you want to set a parameter value on. inparamid The ID of the parameter you want to set. invalue The parameter value to set.

2. avtouch Audio Classes Queue & Resources ( ) SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord AQPlayer DisposeQueue mqueue recordfilepath maudio mfilepath} CreateQueueForFile SetupNewQueue CalculateBytesForTime isrunningproc Playback Flow

1. StartQueue avtouch Classes & Resources 1. Play SpeakHereController IBAction play SpeakHereController::play - (IBAction)play:(id)sender {... } 2. AQPlayer StartQueue SpeakHereController::play recorder->startrecord(cfstr("recordedfile.caf") 1. StartQueue avtouch Classes & Resources SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord play AQPlayer recordfilepath DisposeQueue mqueue maudio mfilepath} CreateQueueForFile SetupNewQueue StartQueue CalculateBytesForTime isrunningproc

2. avtouch Queue Classes & Resources 1. (mfilepath) (mqueue) - mfilepath CreateQueueForFile - 2-1 AQPlayer::StartQueue! // if we have a file but no queue, create one now! if ((mqueue == NULL) && (mfilepath!= NULL))!! CreateQueueForFile(mFilePath 2. AQPlayer::StartQueue! // if we are not resuming, we also should restart the file read index! if (!inresume)!! mcurrentpacket = 0;! 2. avtouch Queue Classes & Resources SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord play AQPlayer recordfilepath DisposeQueue mqueue maudio mfilepath} CreateQueueForFile SetupNewQueue StartQueue mfilepath CalculateBytesForTime isrunningproc

2. avtouch Queue Classes & Resources 3., AQBufferCallback AQPlayer::StartQueue! // prime the queue with some data before starting! for (int i = 0; i < knumberbuffers; ++i) {!! AQBufferCallback (this, mqueue, mbuffers[i]!!!! }! 4. Queue AQPlayer::AQBufferCallback! if (THIS->mIsDone) return;! UInt32 numbytes;! UInt32 npackets = THIS->GetNumPacketsToRead(! OSStatus result = AudioFileReadPackets(THIS->GetAudioFileID(), false, &numbytes, incompleteaqbuffer->mpacketdescriptions, THIS->GetCurrentPacket(), &npackets, incompleteaqbuffer->maudiodata! if (result)!! printf("audiofilereadpackets failed: %d", result! if (npackets > 0) {!! incompleteaqbuffer->maudiodatabytesize = numbytes;!!!! incompleteaqbuffer->mpacketdescriptioncount = npackets;!!!! AudioQueueEnqueueBuffer(inAQ, incompleteaqbuffer, 0, NULL!! THIS->mCurrentPacket = (THIS->GetCurrentPacket() + npackets! } void AQPlayer::AQBufferCallback() AudioFileReadPackets Reads a fixed duration of audio data from an audio file. OSStatus AudioFileReadPackets ( AudioFileID inaudiofile, Boolean inusecache, UInt32 *outnumbytes, AudioStreamPacketDescription *outpacketdescriptions, SInt64 instartingpacket, UInt32 *ionumpackets, void *outbuffer inaudiofile inusecache outnumbytes outpacketdescripti ons instartingpacket ionumpackets outbuffer The audio file whose audio packets you want to read. Set to true to cache the data. Otherwise, set to false. On output, the number of bytes actually read. On output, an array of packet descriptions for the packets that were read. The array that you pass must be large enough to accommodate descriptions for the number of packets requested in the ionumpackets parameter. This parameter applies only to variable bit-rate data. If the file being read contains constant bit-rate (CBR) data, such as linear PCM, this parameter does not get filled. Pass NULL if the file s data format is CBR. The packet index of the first packet you want to read. On input, the number of packets to read. On output, the number of packets actually read. Memory that you allocate to hold the read packets. Determine an appropriate size by multiplying the number of packets requested (in the ionumpackets parameter) by the maximum (or upper bound for) packet size of the audio file. For uncompressed audio formats, a packet is equal to a frame.

void AQPlayer::AQBufferCallback() AudioQueueEnqueueBuffer Adds a buffer to the buffer queue of a recording or playback audio queue. OSStatus AudioQueueEnqueueBuffer ( AudioQueueRef inaq, AudioQueueBufferRef inbuffer, UInt32 innumpacketdescs, const AudioStreamPacketDescription *inpacketdescs inaq The audio queue that owns the audio queue buffer. inbuffer innumpacketdescs inpacketdescs The audio queue buffer to add to the buffer queue. The number of packets of audio data in the inbuffer parameter. Use a value of 0 for any of the following situations: When playing a constant bit rate (CBR) format. When the audio queue is a recording (input) audio queue. When the buffer you are reenqueuing was allocated with the AudioQueueAllocateBufferWithPacketDescriptions function. An array of packet descriptions. Use a value of NULL for any of the following situations: When playing a constant bit rate (CBR) format. When the audio queue is an input (recording) audio queue. When the buffer you are reenqueuing was allocated with the AudioQueueAllocateBufferWithPacketDescriptions function. 2. avtouch Queue Classes & Resources SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord play AQPlayer recordfilepath DisposeQueue mqueue maudio mfilepath} CreateQueueForFile SetupNewQueue StartQueue mfilepath CalculateBytesForTime AQBufferCallback isrunningproc

avtouch 3. Classes & Resources 1. AQPlayer::StartQueue return AudioQueueStart(mQueue, NULL void AQPlayer::StartRecord() AudioQueueStart Begins playing or recording audio. OSStatus AudioQueueStart ( AudioQueueRef inaq, const AudioTimeStamp *instarttime inaq The audio queue to start. instarttime The time at which the audio queue should start.

Stop Playback Flow 1. PauseQueue avtouch Classes & Resources 1. 1) Stop SpeakHereController pauseplayqueue 2) AQPlayer PauseQueue SpeakHereController::pausePlayQueue -(void)pauseplayqueue {! player->pausequeue(! playbackwaspaused = YES; } 2. mqueue return AQPlayer::PauseQueue OSStatus AQPlayer::PauseQueue() {! OSStatus result = AudioQueuePause(mQueue! return result; }

void AQPlayer::PauseQueue() AudioQueuePause Pauses audio playback or recording. OSStatus AudioQueuePause ( AudioQueueRef inaq inaq The audio queue to pause. Discussion Pausing an audio queue does not affect buffers or reset the audio queue. To resume playback or recording, call AudioQueueStart. 2. StopQueue avtouch Classes & Resources 1. 1) SpeakHereController stopplayqueue 2) AQPlayer StopQueue SpeakHereController::stopPlayQueue -(void)stopplayqueue {! player->stopqueue(! [lvlmeter_in setaq: nil];! btn_record.enabled = YES; } 2. mqueue return AQPlayer::PauseQueue OSStatus AQPlayer::StopQueue() {! OSStatus result = AudioQueueStop(mQueue, true! if (result) printf("error STOPPING QUEUE!\n"! return result; }

void AQPlayer::StopQueue() AudioQueueStop Stops playing or recording audio. OSStatus AudioQueueStop ( AudioQueueRef inaq, Boolean inimmediate inaq The audio queue to stop. inimmediate If you pass true, stopping occurs immediately (that is, synchronously). If you pass false, the function returns immediately, but the audio queue does not stop until its queued buffers are played or recorded (that is, the stop occurs asynchronously). Discussion This function resets an audio queue, stops the audio hardware associated with the queue if it is not in use by other audio services, and stops the audio queue. When recording, this function is typically invoked by a user. When playing back, a playback audio queue callback should call this function when there is no more audio to play. 2. avtouch Queue Classes & Resources SpeakHereController stop recorder : AQRecorder stoprecord player : AQPlayer AQRecorder StopRecord play pauseplayqueue stopplayqueue AQPlayer PauseQueue StopQueue recordfilepath DisposeQueue mqueue maudio mfilepath} CreateQueueForFile SetupNewQueue StartQueue mfilepath CalculateBytesForTime AQBufferCallback isrunningproc

avtouch 3. Classes & Resources 1. SpeakHereController::dealloc - (void)dealloc {! [btn_record release];! [btn_play release];! [filedescription release];! [lvlmeter_in release];!! delete player;! delete recorder;!! [super dealloc]; } 2. AQPlayer AQPlayer::~AQPlayer AQPlayer::~AQPlayer() {! DisposeQueue(true }