00001 /************************************************************************************ 00002 00003 Filename : WavPlayer_OSX.h 00004 Content : An Apple OSX audio handler. 00005 Created : March 5, 2013 00006 Authors : Robotic Arm Software - Peter Hoff, Dan Goodman, Bryan Croteau 00007 00008 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved. 00009 00010 Use of this software is subject to the terms of the Oculus LLC license 00011 agreement provided at the time of installation or download, or which 00012 otherwise accompanies this software in either electronic or hard copy form. 00013 00014 ************************************************************************************/ 00015 00016 #ifndef OVR_WavPlayer_h 00017 #define OVR_WavPlayer_h 00018 00019 #include <stdio.h> 00020 #include <stdlib.h> 00021 #include <errno.h> 00022 #include <sys/stat.h> 00023 #include <AudioToolbox/AudioQueue.h> 00024 00025 #define AUDIO_BUFFERS 4 00026 00027 namespace OVR { namespace Platform { namespace OSX { 00028 00029 typedef struct AQCallbackStruct 00030 { 00031 AudioQueueRef Queue; 00032 UInt32 FrameCount; 00033 AudioQueueBufferRef Buffers[AUDIO_BUFFERS]; 00034 AudioStreamBasicDescription DataFormat; 00035 UInt32 PlayPtr; 00036 UInt32 SampleLen; 00037 unsigned char* PCMBuffer; 00038 } AQCallbackStruct; 00039 00040 class WavPlayer 00041 { 00042 public: 00043 WavPlayer(const char* fileName); 00044 int PlayAudio(); 00045 private: 00046 bool isDataChunk(unsigned char* buffer, int index); 00047 int getWord(unsigned char* buffer, int index); 00048 short getHalf(unsigned char* buffer, int index); 00049 void *LoadPCM(const char *filename, unsigned long *len); 00050 int PlayBuffer(void *pcm, unsigned long len); 00051 static void aqBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB); 00052 00053 short AudioFormat; 00054 short NumChannels; 00055 int SampleRate; 00056 int ByteRate; 00057 short BlockAlign; 00058 short BitsPerSample; 00059 const char* FileName; 00060 }; 00061 00062 }}} 00063 00064 #endif