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 Connection * fConnection; 69 GameProducer * fNode; 70 71 private: 72 73 bool fIsConnected; 74 bool fIsPlaying; 75 76 float fGain; 77 float fPan, fPanLeft, fPanRight; 78 _gs_ramp* fGainRamp; 79 _gs_ramp* fPanRamp; 80 }; 81 82 83 class SimpleSoundBuffer : public GameSoundBuffer { 84 public: 85 SimpleSoundBuffer(const gs_audio_format* format, 86 const void * data, 87 int64 frames = 0); 88 virtual ~SimpleSoundBuffer(); 89 90 virtual void * Data() { return fBuffer; } 91 virtual void Reset(); 92 93 protected: 94 95 virtual void FillBuffer(void * data, int64 frames); 96 97 private: 98 char * fBuffer; 99 size_t fBufferSize; 100 size_t fPosition; 101 }; 102 103 104 class StreamingSoundBuffer : public GameSoundBuffer { 105 public: 106 StreamingSoundBuffer(const gs_audio_format * format, 107 const void * streamHook, 108 size_t inBufferFrameCount, 109 size_t inBufferCount); 110 virtual ~StreamingSoundBuffer(); 111 112 protected: 113 114 virtual void FillBuffer(void * data, int64 frames); 115 116 private: 117 118 void * fStreamHook; 119 }; 120 121 #endif 122 123