void VoiceBasicApp::mouseDown( MouseEvent event ) { // scale volume and pan from window coordinates to 0:1 float volume = 1.0f - (float)event.getPos().y / (float)getWindowHeight(); float pan = (float)event.getPos().x / (float)getWindowWidth(); mVoice->setVolume( volume ); mVoice->setPan( pan ); // By stopping the Voice first if it is already playing, start will play from the beginning if( mVoice->isPlaying() ) mVoice->stop(); mVoice->start(); }
void box2d_basicApp::play_sound( const char* asset ) { fs::path p = "sound"; try { if (mVoice) mVoice->stop(); mVoice = audio::Voice::create( audio::load(loadAsset(p/asset)) ); float volume = 1.0f; float pan = 0.5f; mVoice->setVolume( volume ); mVoice->setPan( pan ); if( mVoice->isPlaying() ) mVoice->stop(); mVoice->start(); } catch (...) { } }