#include <Nsound/AudioPlayback.h>
Public Member Functions | |
| AudioPlayback (const float64 &sample_rate=44100.0, const uint32 channels=1, const uint32 bits_per_sample=16) | |
| ~AudioPlayback () | |
| uint32 | getBitsPerSample () |
| void | setBitsPerSample (uint32 bits_per_sample) |
| uint32 | getChannels () |
| void | setChannels (uint32 channels) |
| std::string | getError () |
| std::string | getInfo () |
| uint32 | getSampleRate () |
| void | setSampleRate (uint32 sample_rate) |
| AudioBackend::State | getState () |
| std::string | getStateString () |
| std::string | getStateString (const AudioBackend::State &state) |
| void | initialize () |
| void | play (const AudioStream &a) |
| void | play (const Buffer &b) |
| void | scanDevices () |
| void | setOption (const std::string &key, const std::string &value) |
| void | shutdown () |
Static Public Member Functions | |
| static void | setBackendType (const AudioBackendType ab) |
| static AudioBackendType | getBackendType () |
Private Member Functions | |
| AudioPlayback (const AudioPlayback ©) | |
| AudioPlayback & | operator= (const AudioPlayback &rhs) |
Private Attributes | |
| uint32 | sample_rate_ |
| uint32 | channels_ |
| uint32 | bits_per_sample_ |
| AudioBackend * | backend_ |
Static Private Attributes | |
| static AudioBackendType | backend_type_ = BACKEND_TYPE_NONE |
Friends | |
| void | operator>> (const AudioStream &lhs, AudioPlayback &rhs) |
| void | operator>> (const Buffer &lhs, AudioPlayback &rhs) |
Definition at line 50 of file AudioPlayback.h.
| AudioPlayback::AudioPlayback | ( | const float64 & | sample_rate = 44100.0, |
|
| const uint32 | channels = 1, |
|||
| const uint32 | bits_per_sample = 16 | |||
| ) |
Definition at line 119 of file AudioPlayback.cc.
References allocate_backend(), backend_, backend_type_, Nsound::BACKEND_TYPE_NONE, bits_per_sample_, channels_, and sample_rate_.
00124 : 00125 sample_rate_(static_cast<uint32>(sample_rate)), 00126 channels_(channels), 00127 bits_per_sample_(bits_per_sample), 00128 backend_(NULL) 00129 { 00130 backend_ = allocate_backend( 00131 backend_type_, 00132 sample_rate_, 00133 channels_, 00134 bits_per_sample_); 00135 00136 if(BACKEND_TYPE_NONE != backend_type_ && backend_ == NULL) 00137 { 00138 cerr << "Nsound::AudioPlayback::AudioPlayback():" 00139 << __LINE__ 00140 << ": failed to create AudioBackend!" 00141 << endl; 00142 } };
| AudioPlayback::~AudioPlayback | ( | ) |
Definition at line 146 of file AudioPlayback.cc.
References backend_, and Nsound::AudioBackend::shutdown().
| Nsound::AudioPlayback::AudioPlayback | ( | const AudioPlayback & | copy | ) | [inline, private] |
Definition at line 164 of file AudioPlayback.h.
00166 : 00167 sample_rate_(copy.sample_rate_), 00168 channels_(copy.channels_), 00169 bits_per_sample_(copy.bits_per_sample_), backend_(NULL){};
| void AudioPlayback::setBackendType | ( | const AudioBackendType | ab | ) | [static] |
Sets the AudioBackendType.
Definition at line 104 of file AudioPlayback.cc.
References backend_type_.
Referenced by Nsound::use().
00105 { 00106 backend_type_ = ab; 00107 }
| AudioBackendType AudioPlayback::getBackendType | ( | ) | [static] |
Gets the AudioBackendType that is currently set.
Definition at line 112 of file AudioPlayback.cc.
References backend_type_.
00113 { 00114 return backend_type_; 00115 }
| uint32 AudioPlayback::getBitsPerSample | ( | ) |
Definition at line 158 of file AudioPlayback.cc.
References backend_, bits_per_sample_, and Nsound::AudioBackend::getBitsPerSample().
00159 { 00160 if(backend_ != NULL) 00161 { 00162 return backend_->getBitsPerSample(); 00163 } 00164 00165 return bits_per_sample_; 00166 }
| void Nsound::AudioPlayback::setBitsPerSample | ( | uint32 | bits_per_sample | ) | [inline] |
Definition at line 81 of file AudioPlayback.h.
References bits_per_sample_.
00082 {bits_per_sample_ = bits_per_sample_;};
| uint32 AudioPlayback::getChannels | ( | ) |
Definition at line 171 of file AudioPlayback.cc.
References backend_, channels_, and Nsound::AudioBackend::getChannels().
00172 { 00173 if(backend_ != NULL) 00174 { 00175 return backend_->getChannels(); 00176 } 00177 00178 return channels_; 00179 }
| void Nsound::AudioPlayback::setChannels | ( | uint32 | channels | ) | [inline] |
| std::string AudioPlayback::getError | ( | ) |
Returns an error string describing any backend error.
Definition at line 184 of file AudioPlayback.cc.
References backend_, and Nsound::AudioBackend::getError().
| std::string AudioPlayback::getInfo | ( | ) |
Returns information about the backend driver.
Definition at line 204 of file AudioPlayback.cc.
References backend_, and Nsound::AudioBackend::getInfo().
| uint32 AudioPlayback::getSampleRate | ( | ) |
Definition at line 224 of file AudioPlayback.cc.
References backend_, Nsound::AudioBackend::getSampleRate(), and sample_rate_.
00225 { 00226 if(backend_ != NULL) 00227 { 00228 return backend_->getSampleRate(); 00229 } 00230 00231 return sample_rate_; 00232 }
| void Nsound::AudioPlayback::setSampleRate | ( | uint32 | sample_rate | ) | [inline] |
Definition at line 109 of file AudioPlayback.h.
References sample_rate_.
00110 {sample_rate_ = sample_rate;};
| AudioBackend::State AudioPlayback::getState | ( | ) |
Returns the backend state.
Definition at line 237 of file AudioPlayback.cc.
References backend_, Nsound::AudioBackend::BACKEND_NOT_INITIALIZED, and Nsound::AudioBackend::getState().
00238 { 00239 if(backend_ != NULL) 00240 { 00241 return backend_->getState(); 00242 } 00243 00244 return AudioBackend::BACKEND_NOT_INITIALIZED; 00245 }
| std::string AudioPlayback::getStateString | ( | ) |
Returns the backend state string.
Definition at line 250 of file AudioPlayback.cc.
References backend_, Nsound::AudioBackend::BACKEND_NOT_INITIALIZED, and Nsound::AudioBackend::getStateString().
Referenced by getStateString().
00251 { 00252 if(backend_ != NULL) 00253 { 00254 return backend_->getStateString(); 00255 } 00256 00257 return AudioBackend::getStateString(AudioBackend::BACKEND_NOT_INITIALIZED); 00258 }
| std::string AudioPlayback::getStateString | ( | const AudioBackend::State & | state | ) |
Returns the backend state string.
Definition at line 263 of file AudioPlayback.cc.
References getStateString().
00264 { 00265 return AudioBackend::getStateString(state); 00266 }
| void AudioPlayback::initialize | ( | ) |
Initializes the backend and transitions to the BACKEND_READY state on success.
Definition at line 271 of file AudioPlayback.cc.
References allocate_backend(), backend_, Nsound::AudioBackend::BACKEND_READY, backend_type_, Nsound::BACKEND_TYPE_NONE, bits_per_sample_, channels_, Nsound::AudioBackend::getError(), Nsound::AudioBackend::getState(), Nsound::AudioBackend::initialize(), and sample_rate_.
Referenced by _play(), and scanDevices().
00272 { 00273 if(backend_type_ == BACKEND_TYPE_NONE) 00274 { 00275 cerr << "Nsound::AudioPlayback::initialize():" 00276 << __LINE__ 00277 << ": no backend selected or available" 00278 << endl; 00279 return; 00280 } 00281 00282 // If the backend is currently NULL, recreate it with current settings 00283 if(backend_ == NULL) 00284 { 00285 backend_ = allocate_backend( 00286 backend_type_, 00287 sample_rate_, 00288 channels_, 00289 bits_per_sample_); 00290 } 00291 00292 if(backend_ == NULL) 00293 { 00294 cerr << "Nsound::AudioPlayback::initialize():" 00295 << __LINE__ 00296 << ": failed to initialize AudioBackend!" 00297 << endl; 00298 00299 return; 00300 } 00301 00302 backend_->initialize(); 00303 00304 if(AudioBackend::BACKEND_READY != backend_->getState()) 00305 { 00306 cerr << "Nsound::AudioPlayback::initialize():" 00307 << __LINE__ 00308 << ": backend faild to initialize" 00309 << endl 00310 << "Backend error: " 00311 << backend_->getError() 00312 << endl; 00313 } 00314 }
| void AudioPlayback::play | ( | const AudioStream & | a | ) |
Plays the AudioStream throuh the backend.
Definition at line 484 of file AudioPlayback.cc.
References backend_.
Referenced by Nsound::operator>>(), Nsound::AudioBackendLibportaudio::scanDevices(), and Nsound::AudioBackendLibao::scanDevices().
00485 { 00486 _play<AudioStream>(this, &backend_, a); 00487 }
| void AudioPlayback::play | ( | const Buffer & | b | ) |
Plays the Buffer through the backend.
Definition at line 492 of file AudioPlayback.cc.
References backend_.
00493 { 00494 _play<Buffer>(this, &backend_, b); 00495 }
| void AudioPlayback::scanDevices | ( | ) |
Scans for devices and tries to play a test sound.
Definition at line 500 of file AudioPlayback.cc.
References allocate_backend(), backend_, Nsound::AudioBackend::BACKEND_READY, bits_per_sample_, channels_, Nsound::getBackends(), Nsound::getBackendTypes(), Nsound::AudioBackend::getError(), Nsound::AudioBackend::getState(), initialize(), Nsound::GuitarBass::play(), sample_rate_, and Nsound::AudioBackend::scanDevices().
Referenced by main().
00501 { 00502 GuitarBass guitar(sample_rate_); 00503 00504 AudioStream test_clip(sample_rate_, channels_); 00505 00506 test_clip << guitar.play(); 00507 00508 initialize(); 00509 00510 std::vector< std::string > names = Nsound::getBackends(); 00511 std::vector< AudioBackendType > types = Nsound::getBackendTypes(); 00512 00513 cout << "Nsound::AudioPlayback::scanDevices(): starting\n"; 00514 cout.flush(); 00515 00516 if(types.size() == 0) 00517 { 00518 cout << "No backends available\n"; 00519 cout.flush(); 00520 } 00521 00522 for(uint32 i = 0; i < types.size(); ++i) 00523 { 00524 cout << "Selecting backend '" 00525 << names[i] 00526 << "'\n"; 00527 cout.flush(); 00528 00529 AudioBackend * orig = backend_; 00530 00531 backend_ = allocate_backend( 00532 types[i], 00533 sample_rate_, 00534 channels_, 00535 bits_per_sample_); 00536 00537 if(backend_->getState() == AudioBackend::BACKEND_READY) 00538 { 00539 backend_->scanDevices(*this, test_clip); 00540 } 00541 else 00542 { 00543 cout << "Backend '" 00544 << names[i] 00545 << "' failed to initialize\n" 00546 << backend_->getError(); 00547 cout.flush(); 00548 } 00549 00550 delete backend_; 00551 00552 backend_ = orig; 00553 } 00554 00555 cout << "Nsound::AudioPlayback::scanDevices(): finished\n"; 00556 cout.flush(); 00557 }
| void AudioPlayback::setOption | ( | const std::string & | key, | |
| const std::string & | value | |||
| ) |
Sets an options, must be called before initialize().
Definition at line 562 of file AudioPlayback.cc.
References backend_, Nsound::AudioBackend::BACKEND_NOT_INITIALIZED, Nsound::AudioBackend::getState(), and Nsound::AudioBackend::setOption().
00563 { 00564 if(AudioBackend::BACKEND_NOT_INITIALIZED != backend_->getState()) 00565 { 00566 cerr << endl 00567 << "Nsound::AudioPlayback::setOption():" 00568 << __LINE__ 00569 << ": backend already initialized" 00570 << endl; 00571 return; 00572 } 00573 00574 backend_->setOption(key, value); 00575 }
| void AudioPlayback::shutdown | ( | ) |
Shuts down the backend.
Definition at line 580 of file AudioPlayback.cc.
References backend_, and Nsound::AudioBackend::shutdown().
| AudioPlayback& Nsound::AudioPlayback::operator= | ( | const AudioPlayback & | rhs | ) | [inline, private] |
Definition at line 171 of file AudioPlayback.h.
| void operator>> | ( | const AudioStream & | lhs, | |
| AudioPlayback & | rhs | |||
| ) | [friend] |
| void operator>> | ( | const Buffer & | lhs, | |
| AudioPlayback & | rhs | |||
| ) | [friend] |
uint32 Nsound::AudioPlayback::sample_rate_ [private] |
Definition at line 171 of file AudioPlayback.h.
Referenced by AudioPlayback(), getSampleRate(), initialize(), scanDevices(), and setSampleRate().
uint32 Nsound::AudioPlayback::channels_ [private] |
Definition at line 176 of file AudioPlayback.h.
Referenced by AudioPlayback(), getChannels(), initialize(), scanDevices(), and setChannels().
Definition at line 177 of file AudioPlayback.h.
Referenced by AudioPlayback(), getBitsPerSample(), initialize(), scanDevices(), and setBitsPerSample().
AudioBackend* Nsound::AudioPlayback::backend_ [private] |
Definition at line 179 of file AudioPlayback.h.
Referenced by AudioPlayback(), getBitsPerSample(), getChannels(), getError(), getInfo(), getSampleRate(), getState(), getStateString(), initialize(), play(), scanDevices(), setOption(), shutdown(), and ~AudioPlayback().
AudioBackendType AudioPlayback::backend_type_ = BACKEND_TYPE_NONE [static, private] |
Definition at line 181 of file AudioPlayback.h.
Referenced by AudioPlayback(), getBackendType(), initialize(), and setBackendType().
1.6.3