1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: GameSoundBuffer.h 23 // Author: Christopher ML Zumwalt May (zummy@users.sf.net) 24 // Description: Interface to a single sound, managed by the GameSoundDevice. 25 //------------------------------------------------------------------------------ 26 27 #ifndef _GAMESOUNDBUFFER_H 28 #define _GAMESOUNDBUFFER_H 29 30 // Standard Includes ----------------------------------------------------------- 31 32 // System Includes ------------------------------------------------------------- 33 #include <GameSoundDefs.h> 34 #include <MediaDefs.h> 35 #include <MediaNode.h> 36 37 // Project Includes ------------------------------------------------------------ 38 39 // Local Includes -------------------------------------------------------------- 40 41 // Local Defines --------------------------------------------------------------- 42 43 // Globals --------------------------------------------------------------------- 44 const int32 kPausedAttribute = B_GS_FIRST_PRIVATE_ATTRIBUTE; 45 46 class GameProducer; 47 struct _gs_ramp; 48 struct Connection 49 { 50 media_node producer, consumer; 51 media_source source; 52 media_destination destination; 53 media_format format; 54 media_node timeSource; 55 }; 56 57 // GameSoundBuffer ------------------------------------------------------------- 58 class GameSoundBuffer 59 { 60 public: 61 62 GameSoundBuffer(const gs_audio_format* format); 63 virtual ~GameSoundBuffer(); 64 65 virtual status_t Connect(media_node * consumer); 66 status_t StartPlaying(); 67 status_t StopPlaying(); 68 bool IsPlaying(); 69 70 void Play(void * data, int64 frames); 71 void UpdateMods(); 72 virtual void Reset(); 73 74 virtual void * Data() { return NULL; } 75 const gs_audio_format & Format() const; 76 77 bool IsLooping() const; 78 void SetLooping(bool loop); 79 float Gain() const; 80 status_t SetGain(float gain, bigtime_t duration); 81 float Pan() const; 82 status_t SetPan(float pan, bigtime_t duration); 83 84 virtual status_t GetAttributes(gs_attribute * attributes, 85 size_t attributeCount); 86 virtual status_t SetAttributes(gs_attribute * attributes, 87 size_t attributeCount); 88 protected: 89 90 virtual void FillBuffer(void * data, int64 frames) = 0; 91 92 gs_audio_format fFormat; 93 bool fLooping; 94 95 size_t fFrameSize; 96 97 private: 98 99 Connection * fConnection; 100 GameProducer * fNode; 101 bool fIsConnected; 102 bool fIsPlaying; 103 104 float fGain; 105 float fPan, fPanLeft, fPanRight; 106 _gs_ramp* fGainRamp; 107 _gs_ramp* fPanRamp; 108 }; 109 110 111 class SimpleSoundBuffer : public GameSoundBuffer 112 { 113 public: 114 SimpleSoundBuffer(const gs_audio_format* format, 115 const void * data, 116 int64 frames = 0); 117 virtual ~SimpleSoundBuffer(); 118 119 virtual void * Data() { return fBuffer; } 120 virtual void Reset(); 121 122 protected: 123 124 virtual void FillBuffer(void * data, int64 frames); 125 126 private: 127 char * fBuffer; 128 size_t fBufferSize; 129 size_t fPosition; 130 }; 131 132 class StreamingSoundBuffer : public GameSoundBuffer 133 { 134 public: 135 StreamingSoundBuffer(const gs_audio_format * format, 136 const void * streamHook); 137 virtual ~StreamingSoundBuffer(); 138 139 protected: 140 141 virtual void FillBuffer(void * data, int64 frames); 142 143 private: 144 145 void * fStreamHook; 146 }; 147 148 #endif 149 150