00001 /* 00002 $Id: soundbuffer_stream.cpp,v 1.2 2001/03/13 21:43:03 sphair Exp $ 00003 00004 ------------------------------------------------------------------------ 00005 ClanLib, the platform independent game SDK. 00006 00007 This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE 00008 version 2. See COPYING for details. 00009 00010 For a total list of contributers see CREDITS. 00011 00012 ------------------------------------------------------------------------ 00013 */ 00014 00015 #ifdef WIN32 00016 #pragma warning (disable:4786) 00017 #endif 00018 00019 #include <API/Core/System/error.h> 00020 #include <API/Sound/sound.h> 00021 #include <API/Sound/soundbuffer.h> 00022 #include <API/Sound/soundbuffer_session.h> 00023 #include <API/Sound/stream_soundprovider.h> 00024 #include <Sound/Sound/Generic/cardsession_manager.h> 00025 #include <Sound/Sound/Generic/cardsoundbuffer_playback.h> 00026 #include <Sound/Sound/Generic/soundbuffer_stream.h> 00027 #include <Sound/Sound/Generic/soundcard_generic.h> 00028 00029 CL_SoundBuffer_Generic_Stream::CL_SoundBuffer_Generic_Stream( 00030 CL_StreamSoundProvider *_provider, 00031 bool _delete_provider, 00032 CL_Resource *resource) 00033 : 00034 CL_SoundBuffer_Generic(resource) 00035 { 00036 provider = _provider; 00037 delete_provider = _delete_provider; 00038 00039 volume = -1; 00040 pan = -1; 00041 frequency = -1; 00042 } 00043 00044 CL_SoundBuffer_Generic_Stream::~CL_SoundBuffer_Generic_Stream() 00045 { 00046 int num = CL_Sound::cards.size(); 00047 for (int i=0; i<num; i++) 00048 { 00049 CL_SoundCard_Generic *gen = (CL_SoundCard_Generic *) CL_Sound::cards[i]; 00050 gen->manager->remove_soundbuffer_playbacks(this); 00051 } 00052 00053 if (delete_provider) delete provider; 00054 } 00055 00056 CL_StreamSoundProvider *CL_SoundBuffer_Generic_Stream::get_stream_provider() const 00057 { 00058 return provider; 00059 } 00060 00061 int CL_SoundBuffer_Generic_Stream::get_length() const 00062 { 00063 return -1; 00064 } 00065 00066 int CL_SoundBuffer_Generic_Stream::get_num_samples() const 00067 { 00068 return -1; 00069 } 00070 00071 int CL_SoundBuffer_Generic_Stream::get_frequency() const 00072 { 00073 return frequency; 00074 } 00075 00076 bool CL_SoundBuffer_Generic_Stream::set_frequency(int new_freq) 00077 { 00078 frequency = new_freq; 00079 return true; 00080 } 00081 00082 float CL_SoundBuffer_Generic_Stream::get_volume() const 00083 { 00084 return volume; 00085 } 00086 00087 bool CL_SoundBuffer_Generic_Stream::set_volume(float new_volume) 00088 { 00089 volume = new_volume; 00090 return true; 00091 } 00092 00093 float CL_SoundBuffer_Generic_Stream::get_pan() const 00094 { 00095 return pan; 00096 } 00097 00098 bool CL_SoundBuffer_Generic_Stream::set_pan(float new_pan) 00099 { 00100 pan = new_pan; 00101 return true; 00102 } 00103 00104 bool CL_SoundBuffer_Generic_Stream::is_playing(CL_SoundBuffer_Session **session, CL_SoundCard *card) const 00105 { 00106 if (session != NULL) 00107 { 00108 return (*session)->is_playing(); 00109 } 00110 else 00111 { 00112 if (card != NULL) 00113 { 00114 return ((CL_SoundCard_Generic *) card)->manager->is_soundbuffer_playing((CL_SoundBuffer *) this); 00115 } 00116 else 00117 { 00118 if (CL_Sound::get_current_card() != NULL) 00119 { 00120 return ((CL_SoundCard_Generic *) CL_Sound::get_current_card())->manager->is_soundbuffer_playing((CL_SoundBuffer *) this); 00121 } 00122 else 00123 { 00124 return false; 00125 } 00126 } 00127 } 00128 return true; 00129 } 00130 00131 void CL_SoundBuffer_Generic_Stream::stop(CL_SoundCard *card) 00132 { 00133 if (card != NULL) 00134 { 00135 ((CL_SoundCard_Generic *) card)->manager->remove_soundbuffer_playbacks(this); 00136 } 00137 else 00138 { 00139 if (CL_Sound::get_current_card() != NULL) 00140 { 00141 ((CL_SoundCard_Generic *) CL_Sound::get_current_card())->manager->remove_soundbuffer_playbacks(this); 00142 } 00143 } 00144 } 00145 00146 CL_SoundBuffer_Session CL_SoundBuffer_Generic_Stream::play(bool looping, CL_SoundCard *card) 00147 { 00148 if (card == NULL) card = CL_Sound::get_current_card(); 00149 00150 CL_SoundBuffer_Session ret(prepare(looping, card)); 00151 ret.set_looping(looping); 00152 ret.play(); 00153 00154 return ret; 00155 } 00156 00157 CL_SoundBuffer_Session CL_SoundBuffer_Generic_Stream::prepare(bool looping, CL_SoundCard *card) 00158 { 00159 if(card == NULL) card = CL_Sound::get_current_card(); 00160 if(card == NULL) 00161 { // If it's NULL then we can't do jack shit 00162 throw CL_Error("Cannot access sound card. Please make sure it's not in use"); 00163 } 00164 CL_CardSoundBuffer_Playback *playback = 00165 ((CL_SoundCard_Generic *) card)-> 00166 create_cardsoundbuffer_playback_streamed(this); 00167 00168 CL_SoundBuffer_Session ret( 00169 CL_SoundBuffer_Session( 00170 ((CL_SoundCard_Generic *) card)->manager->add_playback(playback), card)); 00171 00172 if (pan == -1) pan = 0; 00173 if (volume == -1) volume = 1; 00174 00175 ret.set_volume(volume); 00176 ret.set_pan(pan); 00177 ret.set_looping(looping); 00178 if (frequency != -1) ret.set_frequency(frequency); 00179 00180 return ret; 00181 }
1.2.6 written by Dimitri van Heesch,
© 1997-2001