File: AQPlayer.h

来源:互联网 发布:淘宝网商女鞋 编辑:程序博客网 时间:2024/06/04 17:47
/*     File: AQPlayer.hAbstract: Helper class for playing audio files via the AudioQueue Version: 2.4Disclaimer: IMPORTANT:  This Apple software is supplied to you by AppleInc. ("Apple") in consideration of your agreement to the followingterms, and your use, installation, modification or redistribution ofthis Apple software constitutes acceptance of these terms.  If you donot agree with these terms, please do not use, install, modify orredistribute this Apple software.In consideration of your agreement to abide by the following terms, andsubject to these terms, Apple grants you a personal, non-exclusivelicense, under Apple's copyrights in this original Apple software (the"Apple Software"), to use, reproduce, modify and redistribute the AppleSoftware, with or without modifications, in source and/or binary forms;provided that if you redistribute the Apple Software in its entirety andwithout modifications, you must retain this notice and the followingtext and disclaimers in all such redistributions of the Apple Software.Neither the name, trademarks, service marks or logos of Apple Inc. maybe used to endorse or promote products derived from the Apple Softwarewithout specific prior written permission from Apple.  Except asexpressly stated in this notice, no other rights or licenses, express orimplied, are granted by Apple herein, including but not limited to anypatent rights that may be infringed by your derivative works or by otherworks in which the Apple Software may be incorporated.The Apple Software is provided by Apple on an "AS IS" basis.  APPLEMAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATIONTHE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESSFOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE ANDOPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTALOR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESSINTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSEDAND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THEPOSSIBILITY OF SUCH DAMAGE.Copyright (C) 2009 Apple Inc. All Rights Reserved. */#include <AudioToolbox/AudioToolbox.h>#include "CAStreamBasicDescription.h"#include "CAXException.h"#define kNumberBuffers 3#define kBufferDurationSeconds 0.5class AQPlayer{public:AQPlayer();~AQPlayer();OSStatusStartQueue(BOOL inResume);OSStatusStopQueue();OSStatusPauseQueue();AudioQueueRefQueue(){ return mQueue; }CAStreamBasicDescriptionDataFormat() const{ return mDataFormat; }BooleanIsRunning()const{ return (mIsRunning) ? true : false; }BooleanIsInitialized()const{ return mIsInitialized; }CFStringRefGetFilePath() const{ return (mFilePath) ? mFilePath : CFSTR(""); }BooleanIsLooping() const{ return mIsLooping; }void SetLooping(Boolean inIsLooping){ mIsLooping = inIsLooping; }void CreateQueueForFile(CFStringRef inFilePath);void DisposeQueue(Boolean inDisposeFile);private:UInt32GetNumPacketsToRead(){ return mNumPacketsToRead; }SInt64GetCurrentPacket(){ return mCurrentPacket; }AudioFileIDGetAudioFileID(){ return mAudioFile; }voidSetCurrentPacket(SInt64 inPacket){ mCurrentPacket = inPacket; }voidSetupNewQueue();AudioQueueRefmQueue;AudioQueueBufferRefmBuffers[kNumberBuffers];AudioFileIDmAudioFile;CFStringRefmFilePath;CAStreamBasicDescriptionmDataFormat;BooleanmIsInitialized;UInt32mNumPacketsToRead;SInt64mCurrentPacket;UInt32mIsRunning;BooleanmIsDone;BooleanmIsLooping;static void isRunningProc(void *              inUserData,AudioQueueRef           inAQ,AudioQueuePropertyID    inID);static void AQBufferCallback(void *inUserData,AudioQueueRefinAQ,AudioQueueBufferRefinCompleteAQBuffer); void CalculateBytesForTime(CAStreamBasicDescription & inDesc, UInt32 inMaxPacketSize, Float64 inSeconds, UInt32 *outBufferSize, UInt32 *outNumPackets);   };


 

原创粉丝点击