Ejemplo n.º 1
0
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();
	}
}
Ejemplo n.º 2
0
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();
}
Ejemplo n.º 3
0
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();
}
Ejemplo n.º 4
0
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();
}
Ejemplo n.º 5
0
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() );
	}
}
Ejemplo n.º 6
0
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 (...) {
	}
}
Ejemplo n.º 7
0
void VoiceTestApp::setupDifferentFile()
{
	mVoice = audio::Voice::create( audio::load( loadResource( RES_TONE_440L220R ) ) );
	mVoice->setVolume( mVolumeSlider.mValueScaled );

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