1 /* 2 * Copyright 2001-2002, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Author: Christopher ML Zumwalt May (zummy@users.sf.net) 6 */ 7 8 #ifndef _GAMESOUNDBUFFER_H 9 #define _GAMESOUNDBUFFER_H 10 11 12 #include <GameSoundDefs.h> 13 #include <MediaDefs.h> 14 #include <MediaNode.h> 15 16 const int32 kPausedAttribute = B_GS_FIRST_PRIVATE_ATTRIBUTE; 17 18 class GameProducer; 19 struct _gs_ramp; 20 struct Connection 21 { 22 media_node producer, consumer; 23 media_source source; 24 media_destination destination; 25 media_format format; 26 media_node timeSource; 27 }; 28 29 30 class GameSoundBuffer { 31 public: 32 33 GameSoundBuffer(const gs_audio_format* format); 34 virtual ~GameSoundBuffer(); 35 36 virtual status_t Connect(media_node * consumer); 37 status_t StartPlaying(); 38 status_t StopPlaying(); 39 bool IsPlaying(); 40 41 void Play(void * data, int64 frames); 42 void UpdateMods(); 43 virtual void Reset(); 44 45 virtual void * Data() { return NULL; } 46 const gs_audio_format & Format() const; 47 48 bool IsLooping() const; 49 void SetLooping(bool loop); 50 float Gain() const; 51 status_t SetGain(float gain, bigtime_t duration); 52 float Pan() const; 53 status_t SetPan(float pan, bigtime_t duration); 54 55 virtual status_t GetAttributes(gs_attribute * attributes, 56 size_t attributeCount); 57 virtual status_t SetAttributes(gs_attribute * attributes, 58 size_t attributeCount); 59 protected: 60 61 virtual void FillBuffer(void * data, int64 frames) = 0; 62 63 gs_audio_format fFormat; 64 bool fLooping; 65 66 size_t fFrameSize; 67 68 private: 69 70 Connection * fConnection; 71 GameProducer * fNode; 72 bool fIsConnected; 73 bool fIsPlaying; 74 75 float fGain; 76 float fPan, fPanLeft, fPanRight; 77 _gs_ramp* fGainRamp; 78 _gs_ramp* fPanRamp; 79 }; 80 81 82 class SimpleSoundBuffer : public GameSoundBuffer { 83 public: 84 SimpleSoundBuffer(const gs_audio_format* format, 85 const void * data, 86 int64 frames = 0); 87 virtual ~SimpleSoundBuffer(); 88 89 virtual void * Data() { return fBuffer; } 90 virtual void Reset(); 91 92 protected: 93 94 virtual void FillBuffer(void * data, int64 frames); 95 96 private: 97 char * fBuffer; 98 size_t fBufferSize; 99 size_t fPosition; 100 }; 101 102 103 class StreamingSoundBuffer : public GameSoundBuffer { 104 public: 105 StreamingSoundBuffer(const gs_audio_format * format, 106 const void * streamHook); 107 virtual ~StreamingSoundBuffer(); 108 109 protected: 110 111 virtual void FillBuffer(void * data, int64 frames); 112 113 private: 114 115 void * fStreamHook; 116 }; 117 118 #endif 119 120