void VoiceBasicApp::keyDown( KeyEvent event )
{
	// space toggles the voice between playing and pausing
	if( event.getCode() == KeyEvent::KEY_SPACE ) {
		if( mVoice->isPlaying() )
			mVoice->pause();
		else
			mVoice->start();
	}
}
void VoiceTestApp::setupScope()
{
	auto sourceFile = audio::load( loadResource( RES_DRAIN_OGG ) );
	mVoice = audio::Voice::create( sourceFile, audio::Voice::Options().connectToMaster( false ) );
	mVoice->setVolume( mVolumeSlider.mValueScaled );

	auto ctx = audio::master();
	mMonitor = ctx->makeNode( new audio::MonitorNode );

	mVoice->getOutputNode() >> mMonitor >> ctx->getOutput();
}
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 VoiceTestApp::setupUI()
{
	mPlayButton = Button( false, "start" );
	mPlayButton.mBounds = Rectf( 0, 0, 200, 60 );
	mWidgets.push_back( &mPlayButton );

	mTestSelector.mSegments.push_back( "basic" );
	mTestSelector.mSegments.push_back( "basic stereo" );
	mTestSelector.mSegments.push_back( "file 2" );
	mTestSelector.mSegments.push_back( "scope" );
	mWidgets.push_back( &mTestSelector );

	mVolumeSlider.mTitle = "Volume";
	mVolumeSlider.mMax = 1;
	mVolumeSlider.set( mVoice->getVolume() );
	mWidgets.push_back( &mVolumeSlider );

//	mEnableSineButton.mIsToggle = true;
//	mEnableSineButton.mTitleNormal = "sine disabled";
//	mEnableSineButton.mTitleEnabled = "sine enabled";
//	mEnableSineButton.mBounds = Rectf( 0, 70, 200, 120 );
//	mWidgets.push_back( &mEnableSineButton );


	getWindow()->getSignalMouseDown().connect( [this] ( MouseEvent &event ) { processTap( event.getPos() ); } );
	getWindow()->getSignalMouseDrag().connect( [this] ( MouseEvent &event ) { processDrag( event.getPos() ); } );
	getWindow()->getSignalTouchesBegan().connect( [this] ( TouchEvent &event ) { processTap( event.getTouches().front().getPos() ); } );
	getWindow()->getSignalTouchesMoved().connect( [this] ( TouchEvent &event ) {
		for( const TouchEvent::Touch &touch : getActiveTouches() )
			processDrag( touch.getPos() );
	} );

	gl::enableAlphaBlending();
}
void VoiceTestApp::processTap( Vec2i pos )
{
	if( mPlayButton.hitTest( pos ) )
		mVoice->start();

	size_t currentIndex = mTestSelector.mCurrentSectionIndex;
	if( mTestSelector.hitTest( pos ) && currentIndex != mTestSelector.mCurrentSectionIndex ) {
		string currentTest = mTestSelector.currentSection();
		CI_LOG_V( "selected: " << currentTest );

		if( currentTest == "basic" )
			setupBasic();
		if( currentTest == "basic stereo" )
			setupBasicStereo();
		else if( currentTest == "scope" )
			setupScope();
		else if( currentTest == "file 2" )
			setupDifferentFile();

		PRINT_GRAPH( audio::master() );
	}
}
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 (...) {
	}
}
void VoiceTestApp::setupDifferentFile()
{
	mVoice = audio::Voice::create( audio::load( loadResource( RES_TONE_440L220R ) ) );
	mVoice->setVolume( mVolumeSlider.mValueScaled );

}
void VoiceTestApp::setupBasicStereo()
{
	mVoice = audio::Voice::create( audio::load( loadResource( RES_DRAIN_OGG ) ), audio::Voice::Options().channels( 2 ) );
	mVoice->setVolume( mVolumeSlider.mValueScaled );
}
void VoiceTestApp::setupBasic()
{
	mVoice = audio::Voice::create( audio::load( loadResource( RES_DRAIN_OGG ) ) );
	mVoice->setVolume( mVolumeSlider.mValueScaled );
}
Exemple #10
0
void VoiceTestApp::processDrag( Vec2i pos )
{
	if( mVolumeSlider.hitTest( pos ) )
		mVoice->setVolume( mVolumeSlider.mValueScaled );
}