Beispiel #1
0
    // Initializes FMOD Studio and loads all sound banks.
    Audio() :
      Listener(system)
    {
      // Create the FMOD Studio system.
      FmodCall(fmod::System::create(&system));
      // Initialize the system.
      FmodCall(system->initialize(
        maxChannels,               // max channels capable of playing audio
        FMOD_STUDIO_INIT_NORMAL,   // studio-specific flags
        FMOD_INIT_3D_RIGHTHANDED,  // regular flags
        nullptr));                 // extra driver data

      vector<fmod::Bank*> banks;

      // For each file in the Sounds directory with a *.bank extension:
      for (const string& file : PathInfo(config::Sounds).FilesWithExtension("bank"))
      {
        // Load the sound bank from file.
        fmod::Bank* bank = nullptr;
        FmodCall(system->loadBankFile(file.c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &bank));

        banks.push_back(bank);
      }

      for (fmod::Bank* bank : banks)
      {
        // Get the number of events in the bank.
        int eventCount = 0;
        FmodCall(bank->getEventCount(&eventCount));
        if (eventCount == 0) continue;

        // Get the list of event descriptions from the bank.
        auto eventArray = vector<fmod::EventDescription*>(static_cast<size_t>(eventCount), nullptr);
        FmodCall(bank->getEventList(eventArray.data(), eventArray.size(), nullptr));

        // For each event description:
        for (fmod::EventDescription* eventDescription : eventArray)
        {
          // Get the path to the event, e.g. "event:/Ambience/Country"
          auto path = string(512, ' ');
          int retrieved = 0;
          FmodCall(eventDescription->getPath(&path[0], path.size(), &retrieved));
          path.resize(static_cast<size_t>(retrieved - 1)); // - 1 to account for null character

          // Save the event description in the event map.
          eventDescriptionMap.emplace(path, EventDescription(eventDescription, path));
        }
      }

      Note(*this);
    }
void StepTwoApp::mouseDown( MouseEvent event )
{
    int n;
	FMODErrorCheck( mSystem->getChannelsPlaying(&n) );
	if(n>=32) {
        console() << "Too many sounds playing!" << endl;
        return;
    }

    
    FMOD::Sound* sound = mSounds[Rand::randInt(mSounds.size())];
    
    // Channels inherit the modes of sounds.
    FMOD::Channel* channel;
    mSystem->playSound( FMOD_CHANNEL_FREE, sound, false, &channel );
}
void AudioVisualizerApp::update()
{
	// update FMOD so it can notify us of events
	mFMODSystem->update();

	// handle signal: if audio has ended, play next file
	if(mIsAudioPlaying && signalChannelEnd)
		playAudio( nextAudio( mAudioPath ) );

	// reset FMOD signals
	signalChannelEnd= false;

	// get spectrum for left and right channels and copy it into our channels
	float* pDataLeft = mChannelLeft.getData() + kBands * mOffset;
	float* pDataRight = mChannelRight.getData() + kBands * mOffset;

	mFMODSystem->getSpectrum( pDataLeft, kBands, 0, FMOD_DSP_FFT_WINDOW_HANNING );	
	mFMODSystem->getSpectrum( pDataRight, kBands, 1, FMOD_DSP_FFT_WINDOW_HANNING );

	// increment texture offset
	mOffset = (mOffset+1) % kHistory;

	// clear the spectrum for this row to avoid old data from showing up
	pDataLeft = mChannelLeft.getData() + kBands * mOffset;
	pDataRight = mChannelRight.getData() + kBands * mOffset;
	memset( pDataLeft, 0, kBands * sizeof(float) );
	memset( pDataRight, 0, kBands * sizeof(float) );

	// animate camera if mouse has not been down for more than 30 seconds
	if(!mIsMouseDown && (getElapsedSeconds() - mMouseUpTime) > mMouseUpDelay)
	{
		float t = float( getElapsedSeconds() );
		float x = 0.5f + 0.5f * math<float>::cos( t * 0.07f );
		float y = 0.1f - 0.2f * math<float>::sin( t * 0.09f );
		float z = 0.25f * math<float>::sin( t * 0.05f ) - 0.25f;
		Vec3f eye = Vec3f(kWidth * x, kHeight * y, kHeight * z);

		x = 1.0f - x;
		y = -0.3f;
		z = 0.6f + 0.2f *  math<float>::sin( t * 0.12f );
		Vec3f interest = Vec3f(kWidth * x, kHeight * y, kHeight * z);

		// gradually move to eye position and center of interest
		mCamera.setEyePoint( eye.lerp(0.995f, mCamera.getEyePoint()) );
		mCamera.setCenterOfInterestPoint( interest.lerp(0.990f, mCamera.getCenterOfInterestPoint()) );
	}
}
void AudioVisualizerApp::shutdown()
{
	// properly shut down FMOD
	stopAudio();

	if( mFMODSystem )
		mFMODSystem->release();
}
void FmodExMultiple3DSoundPlayerApp::update()
{
	
	
	//Update camera
	Vec3f camDirection = camCenter;
	camDirection.normalize();
	camEye = camInitialEye + camDistance * camDirection;
	cam.setViewDirection(camCenter);
	cam.setEyePoint(camEye);
	gl::setMatrices( cam );
	gl::rotate( sceneRotation );
	
	//Update 3D Sounds
	
	Vec3f up = cam.getWorldUp();
	up.invert();
	
	listenerUp.x = up.x;
	listenerUp.y = up.y; 
	listenerUp.z = up.z;
	listenerPos.x = camEye.x; 
	listenerPos.y = camEye.y;  
	listenerPos.z = camEye.z;
	//forward = camCenter - camEye;
	//forward.normalize();
	listenerForward.x = camCenter.x; 
	listenerForward.y = camCenter.y; 
	listenerForward.z = camCenter.z;
	sys->set3DListenerAttributes( 0, &listenerPos, &listenerVelocity, &listenerForward, &listenerUp);
	
	if(!player1.getIsPlaying())
		player1.play();
	
	if(!player2.getIsPlaying())
		player2.play();	
	
	player1.channel->set3DAttributes( &sound3DPosition1, &sound3DVelocity1);
	player2.channel->set3DAttributes( &sound3DPosition2, &sound3DVelocity2);
	
	//we update the fmod sound system
	sys->update();
	//FmodexUpdate();
	
}
Beispiel #6
0
	int Game::playEnvironment()
	{
			bool soundDone=false;
			FMOD::System* system;
			FMOD_RESULT result = FMOD::System_Create(&system);
			system->init(32, FMOD_INIT_NORMAL, NULL);
			FMOD::Sound* sound;
			
			result = system->createSound("Ocean.WAV",FMOD_LOOP_NORMAL,NULL, &sound);
			FMOD::Channel* channel = 0;
			bool pauseSound = false;


			channel->isPlaying(&pauseSound);

			result = system->playSound(FMOD_CHANNEL_FREE, sound,false, &channel);
			soundDone=true;


			while (soundDone!=true)
			{
			channel->setPaused(false);
			system->update();

			result = sound->release();
			result = system->close();
			result = system->release();
			}
			return 0;
	}
Beispiel #7
0
void			playBackground(void)
{
	FMOD::System *		Syst = NULL;
	FMOD::Channel *		Chan = NULL;
	FMOD::Sound *		s;

	if (Syst == NULL)
	{
		if (FMOD::System_Create(&Syst) != FMOD_OK)
			fmod_exit();
		if (Syst->init(32, FMOD_INIT_NORMAL, 0) != FMOD_OK)
			fmod_exit();
	}
	if (Syst->createSound("mp3/background.mp3", FMOD_LOOP_NORMAL, 0, &s) != FMOD_OK)
		fmod_exit();
	if (Syst->playSound(s, NULL, false, &Chan) != FMOD_OK)
		fmod_exit();
	Syst->update();
}
void cinderFFmpegApp::setup()
{
	m_Font = ci::Font("Consolas", 48);
	setupGui();
	gl::enableAlphaBlending();

	std::shared_ptr<_2RealFFmpegWrapper::FFmpegWrapper> testFile = std::shared_ptr<_2RealFFmpegWrapper::FFmpegWrapper>(new _2RealFFmpegWrapper::FFmpegWrapper());
	testFile->dumpFFmpegInfo();
	//if(testFile->open(".\\data\\morph.avi"))
	if(testFile->open("d:\\vjing\\Wildlife.wmv"))
	{
		m_Players.push_back(testFile);
		m_VideoTextures.push_back(gl::Texture());
		m_Players.back()->play();
	}

	m_dLastTime = 0;
	m_iCurrentVideo = 0;
	m_fSpeed = 1;
	m_iLoopMode = _2RealFFmpegWrapper::eLoop;
	m_iTilesDivisor = 1;
	m_fSeekPos = m_fOldSeekPos = 0;

	//setup fmod
	FMOD::System_Create(&m_pSystem);
    m_pSystem->init(32, FMOD_INIT_NORMAL, 0);
   
	memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    createsoundexinfo.cbsize            = sizeof(FMOD_CREATESOUNDEXINFO);              /* required. */
    createsoundexinfo.decodebuffersize  = 1024;                                       /* Chunk size of stream update in samples.  This will be the amount of data passed to the user callback. */
    createsoundexinfo.numchannels       = 2;                        /* Number of channels in the sound. */
    createsoundexinfo.length            = -1;                     /* Length of PCM data in bytes of whole song.  -1 = infinite. */
    createsoundexinfo.defaultfrequency  = (int)44100;                       /* Default playback rate of sound. */
	createsoundexinfo.format            = FMOD_SOUND_FORMAT_PCM16;                    /* Data format of sound. */
	createsoundexinfo.pcmreadcallback   =  pcmreadcallback;                             /* User callback for reading. */

	result = m_pSystem->createStream(0, FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_OFF, &createsoundexinfo, &m_pSound);
	result = m_pSystem->playSound(FMOD_CHANNEL_FREE, m_pSound, 0, &m_pChannel);

	//std::shared_ptr<audio::Callback<cinderFFmpegApp,unsigned short>> audioCallback = audio::createCallback( this, &cinderFFmpegApp::audioCallback );
	//audio::Output::play( audioCallback );
}
Beispiel #9
0
    // Updates the FMOD Studio system.
    void Update()
    {
      // Invoke the AudioUpdate event to allow
      //  EventInstance objects to update.
      EventData eventData;
      eventData["Audio"] = this;
      InvokeEvent("AudioUpdate", eventData);

      // Update the FMOD Studio system.
      FmodCall(system->update());
    }
Beispiel #10
0
	void FMOD_System::PlayRollSound()
	{
		if( roll != nullptr )
		{
			if( !IsPlaying( rollChannel ) && !IsPlaying( collisionChannel ) )
			{
				system->playSound( FMOD_CHANNEL_FREE, roll, true, &rollChannel );
				rollChannel->set3DAttributes( &ballPosition, nullptr );
				rollChannel->setPaused( false );
			}
		}
	}
Beispiel #11
0
	void FMOD_System::PlayJetSound()
	{
		if( jet != nullptr )
		{
			if( !IsPlaying( jetChannel ) )
			{
				system->playSound( FMOD_CHANNEL_FREE, jet, true, &jetChannel );
				jetChannel->set3DAttributes( &ballPosition, nullptr );
				jetChannel->setPaused( false );
			}
		}
	}
Beispiel #12
0
	void FMOD_System::PlayCollisionSound()
	{
		if( collision != nullptr )
		{
			if( !IsPlaying( collisionChannel ) )
			{
				system->playSound( FMOD_CHANNEL_FREE, collision, true, &collisionChannel );
				collisionChannel->set3DAttributes( &ballPosition, nullptr );
				collisionChannel->setPaused( false );
			}
		}
	}
Beispiel #13
0
    ~Audio()
    {
      // Invoke the AudioShutdown event. This lets the EventListener objects
      //  release so that they don't try to release after the FMOD Studio
      //  system is released below.
      EventData eventData;
      eventData["Audio"] = this;
      InvokeEvent("AudioShutdown", eventData);

      // Destroy the FMOD Studio system.
      FmodCall(system->release());
    }
void initializeSound()
{
	FMOD::System     *system;
    unsigned int      version;
	
	result = FMOD::System_Create(&system);
    ERRCHECK(result);
	
    result = system->getVersion(&version);
    ERRCHECK(result);
	
	if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        exit(-3);
    }
	
	result = system->init(32, FMOD_INIT_NORMAL, NULL);
    ERRCHECK(result);
	
	result = system->createSound("/Users/adrtwin/Music/What You Know (Mustang Remix).mp3", FMOD_SOFTWARE, 0, &sound1);
    ERRCHECK(result);
	
	
	
	/*
	result = system->createSound("CALIBRATING", FMOD_SOFTWARE, 0, &sound2);
    ERRCHECK(result);
	
    result = system->createSound("SHOT", FMOD_SOFTWARE, 0, &sound3);
    ERRCHECK(result);
	
    result = system->createSound("SHOT_NO_AMMO", FMOD_SOFTWARE, 0, &sound4);
    ERRCHECK(result);
	
	result = system->createSound("RELOADING", FMOD_SOFTWARE, 0, &sound5);
    ERRCHECK(result);
	*/
	globalSystem = system;
}
	FMOD::Sound* FMODAudioClip::createStreamingSound() const
	{
		if(getReadMode() != AudioReadMode::Stream || mStreamData == nullptr)
		{
			LOGERR("Invalid audio stream data.");
			return nullptr;
		}

		FMOD_MODE flags = FMOD_CREATESTREAM;

		FMOD_CREATESOUNDEXINFO exInfo;
		memset(&exInfo, 0, sizeof(exInfo));
		exInfo.cbsize = sizeof(exInfo);
		
		// Streaming from memory not supported.
		assert(mStreamData->isFile());

		exInfo.length = mStreamSize;
		exInfo.fileoffset = mStreamOffset;

		SPtr<FileDataStream> fileStream = std::static_pointer_cast<FileDataStream>(mStreamData);
		String pathStr = fileStream->getPath().toString();

		if (is3D())
			flags |= FMOD_3D;
		else
			flags |= FMOD_2D;

		FMOD::Sound* sound = nullptr;
		FMOD::System* fmod = gFMODAudio()._getFMOD();
		if (fmod->createSound(pathStr.c_str(), flags, &exInfo, &sound) != FMOD_OK)
		{
			LOGERR("Failed creating a streaming sound.");
			return nullptr;
		}

		sound->setMode(FMOD_LOOP_OFF);
		return sound;
	}
Beispiel #16
0
MicrophoneRecorder::MicrophoneRecorder(int frequency, int channels, FMOD_SOUND_FORMAT format)
    : m_fmodsnd(nullptr)
    , m_fmodsys(nullptr)
    , m_dataLength(0)
    , m_byteSize(0)
    , m_frequency(frequency)
    , m_channels(channels)
{
    switch (format)
    {
        case FMOD_SOUND_FORMAT_PCM8: m_byteSize = 1; break;
        case FMOD_SOUND_FORMAT_PCM16: m_byteSize = 2; break;
        case FMOD_SOUND_FORMAT_PCM24: m_byteSize = 3; break;
        case FMOD_SOUND_FORMAT_PCM32: m_byteSize = 4; break;
        case FMOD_SOUND_FORMAT_PCMFLOAT: m_byteSize = 4; break;
    }

    CHECK(m_byteSize > 0);

	FMOD::System * fmodSys = SoundMngr::Get()->GetSys();

	FMOD_CREATESOUNDEXINFO exinfo;
	memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
	exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
	exinfo.numchannels      = channels;
	exinfo.format           = format;
	exinfo.defaultfrequency = frequency;
	exinfo.length           = exinfo.defaultfrequency * m_byteSize * exinfo.numchannels * 2;

	unsigned int flags = FMOD_SOFTWARE | FMOD_2D | FMOD_OPENUSER;
	FMOD_ERRCHECK(fmodSys->createSound(0, flags, &exinfo, &m_fmodsnd));

	m_fmodsys = fmodSys;

    m_data.resize(channels);
}
void StepTwoApp::setup()
{
    FMODListDevices();
    FMODErrorCheck(FMOD::System_Create( &mSystem ));
    FMODErrorCheck(mSystem->setDriver(0));
	FMOD_INITFLAGS flags = FMOD_INIT_NORMAL; // right-click, Go To Definition
	FMODErrorCheck(mSystem->init( 32, flags, NULL ));

    vector<fs::path> paths;
    paths.push_back( getAssetPath("gong-loud-hit.mp3") );
    paths.push_back( getAssetPath("orch-hit.wav") );
    paths.push_back( getAssetPath("trumpethit07.wav") );
    
    for(auto& path: paths) {
        FMOD::Sound* sound;
        mSystem->createSound( path.string().c_str(), FMOD_SOFTWARE, NULL, &sound );
        
        // You can change the mode of sounds at any time.
        FMOD_MODE mode = FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_OFF;
        FMODErrorCheck( sound->setMode( mode ) );
        
        mSounds.push_back(sound);
    }
}
void _TBOX_PREFIX_App::draw()
{
	gl::clear();
	
	// grab 512 samples of the wave data
	float waveData[512];
	mSystem->getWaveData( waveData, 512, 0 );
	
	// render the 512 samples to a VertBatch
	gl::VertBatch vb( GL_LINE_STRIP );
	for( int i = 0; i < 512; ++i )
		vb.vertex( getWindowWidth() / 512.0f * i, getWindowCenter().y + 100 * waveData[i] );

	// draw the points as a line strip
	gl::color( Color( 1.0f, 0.5f, 0.25f ) );
	vb.draw();
}
Beispiel #19
0
	void FMOD_System::StartPlayingLoopingSounds()
	{
		if( bgmusic != nullptr )
		{
			system->playSound( FMOD_CHANNEL_FREE, bgmusic, false, nullptr );
		}

		if( ventSound != nullptr )
		{
			std::for_each( vents.begin(), vents.end(), [&]( VentPoint v )
			{
				FMOD::Channel *vent_channel;
				FMOD_System::system->playSound( FMOD_CHANNEL_FREE, ventSound, true, &vent_channel );
				FMOD_VECTOR position = { v.x, v.y, v.z };
				vent_channel->set3DAttributes( &position, nullptr );
				vent_channel->setPaused( false );
			});
		}
	}
Beispiel #20
0
void DuckHuntMain::UpdateScene(float dt)
{
	//
	// Control the camera.
	//
	if (GetAsyncKeyState('W') & 0x8000)
		mCam.Walk(10.0f*dt);

	if (GetAsyncKeyState('S') & 0x8000)
		mCam.Walk(-10.0f*dt);

	if (GetAsyncKeyState('A') & 0x8000)
		mCam.Strafe(-10.0f*dt);

	if (GetAsyncKeyState('D') & 0x8000)
		mCam.Strafe(10.0f*dt);

	//
	// Animate the lights (and hence shadows).
	//

	////
	//// Walk/fly mode
	////
	//if (GetAsyncKeyState('2') & 0x8000)
	//	mWalkCamMode = true;
	//if (GetAsyncKeyState('3') & 0x8000)
	//	mWalkCamMode = false;

	//// 
	//// Clamp camera to terrain surface in walk mode.
	////
		XMFLOAT3 camPos = mCam.GetPosition();
		float y = mTerrain.GetHeight(camPos.x, camPos.z);
		mCam.SetPosition(camPos.x, y + 2.0f, camPos.z);
	

	BuildShadowTransform();

	mCam.UpdateViewMatrix();
	mSystem->update();
}
Beispiel #21
0
	int Game::playSound(bool Sound)
	{

			bool soundDone= false;
			//declare variable for FMOD system object
			FMOD::System* system;
			//allocate memory for the FMOD system object
			FMOD_RESULT result = FMOD::System_Create(&system);
			//initialize the FMOD system object
			system->init(32, FMOD_INIT_NORMAL, NULL);
			//declare variable for the sound object
			FMOD::Sound* sound;
			//created sound object and specify the sound 
			
			result = system->createSound("Cathedral_of_Light.mp3",FMOD_LOOP_NORMAL,NULL, &sound);
			// play sound - 1st parameter can be combined flags (| separator)
			FMOD::Channel* channel = 0;

			//start sound

			bool pauseSound=false;

			channel->isPlaying(&pauseSound);

			result = system->playSound(FMOD_CHANNEL_FREE, sound, Sound, &channel);
			soundDone=true;


			while (soundDone!=true)
			{
			channel->setPaused(false);
			system->update();

			//}
			// release resources
			result = sound->release();
			result = system->close();
			result = system->release();
			}
			return 0;

	}
int FMOD_Main()
{
    FMOD::System    *system;
    FMOD::Channel   *channel = 0;
    FMOD::DSP       *dsp;
    FMOD_RESULT      result;
    unsigned int     version;
    void            *extradriverdata = 0;

    Common_Init(&extradriverdata);
    
    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        Common_Fatal("FMOD lib version %08x doesn't match header version %08x", version, FMOD_VERSION);
    }

    result = system->init(32, FMOD_INIT_NORMAL, extradriverdata);
    ERRCHECK(result);

    /*
        Create an oscillator DSP units for the tone.
    */
    result = system->createDSPByType(FMOD_DSP_TYPE_OSCILLATOR, &dsp);
    ERRCHECK(result);
    result = dsp->setParameterFloat(FMOD_DSP_OSCILLATOR_RATE, 440.0f); /* Musical note 'A' */
    ERRCHECK(result);

    /*
        Main loop
    */
    do
    {
        Common_Update();

        if (Common_BtnPress(BTN_ACTION1))
        {
            if (channel)
            {
                result = channel->stop();
                ERRCHECK(result);
            }

            result = system->playDSP(dsp, 0, true, &channel);
            ERRCHECK(result);
            result = channel->setVolume(0.5f);
            ERRCHECK(result);
            result = dsp->setParameterInt(FMOD_DSP_OSCILLATOR_TYPE, 0);
            ERRCHECK(result);
            result = channel->setPaused(false);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION2))
        {
            if (channel)
            {
                result = channel->stop();
                ERRCHECK(result);
            }

            result = system->playDSP(dsp, 0, true, &channel);
            ERRCHECK(result);
            result = channel->setVolume(0.125f);
            ERRCHECK(result);
            result = dsp->setParameterInt(FMOD_DSP_OSCILLATOR_TYPE, 1);
            ERRCHECK(result);
            result = channel->setPaused(false);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION3))
        {
            if (channel)
            {
                result = channel->stop();
                ERRCHECK(result);
            }

            result = system->playDSP(dsp, 0, true, &channel);
            ERRCHECK(result);
            result = channel->setVolume(0.125f);
            ERRCHECK(result);
            result = dsp->setParameterInt(FMOD_DSP_OSCILLATOR_TYPE, 2);
            ERRCHECK(result);
            result = channel->setPaused(false);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION4))
        {
            if (channel)
            {
                result = channel->stop();
                ERRCHECK(result);
            }

            result = system->playDSP(dsp, 0, true, &channel);
            ERRCHECK(result);
            result = channel->setVolume(0.5f);
            ERRCHECK(result);
            result = dsp->setParameterInt(FMOD_DSP_OSCILLATOR_TYPE, 4);
            ERRCHECK(result);
            result = channel->setPaused(false);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_MORE))
        {
            if (channel)
            {
                result = channel->stop();
                ERRCHECK(result);
                channel = 0;
            }
        }

        if (channel)
        {
            if (Common_BtnDown(BTN_UP) || Common_BtnDown(BTN_DOWN))
            {
                float volume;
            
                result = channel->getVolume(&volume);
                ERRCHECK(result);
            
                volume += (Common_BtnDown(BTN_UP) ? +0.1f : -0.1f);
                volume = (volume > 1.0f) ? 1.0f : volume;
                volume = (volume < 0.0f) ? 0.0f : volume;
           
                result = channel->setVolume(volume);
                ERRCHECK(result);
            }

            if (Common_BtnDown(BTN_LEFT) || Common_BtnDown(BTN_RIGHT))
            {
                float frequency;
            
                result = channel->getFrequency(&frequency);
                ERRCHECK(result);
            
                frequency += (Common_BtnDown(BTN_RIGHT) ? +500.0f : -500.0f);
            
                result = channel->setFrequency(frequency);
                ERRCHECK(result);
            }
        }

        result = system->update();
        ERRCHECK(result);

        {
            float frequency = 0.0f, volume = 0.0f;
            bool playing = false;

            if (channel)
            {
                result = channel->getFrequency(&frequency);
                ERRCHECK(result);
                result = channel->getVolume(&volume);
                ERRCHECK(result);
                result = channel->isPlaying(&playing);
                ERRCHECK(result);
            }

            Common_Draw("==================================================");
            Common_Draw("Generate Tone Example.");
            Common_Draw("Copyright (c) Firelight Technologies 2004-2015.");
            Common_Draw("==================================================");
            Common_Draw("");
            Common_Draw("Press %s to play a sine wave", Common_BtnStr(BTN_ACTION1));
            Common_Draw("Press %s to play a square wave", Common_BtnStr(BTN_ACTION2));
            Common_Draw("Press %s to play a saw wave", Common_BtnStr(BTN_ACTION3));
            Common_Draw("Press %s to play a triangle wave", Common_BtnStr(BTN_ACTION4));
            Common_Draw("Press %s to stop the channel", Common_BtnStr(BTN_MORE));
            Common_Draw("Press %s and %s to change volume", Common_BtnStr(BTN_UP), Common_BtnStr(BTN_DOWN));
            Common_Draw("Press %s and %s to change frequency", Common_BtnStr(BTN_LEFT), Common_BtnStr(BTN_RIGHT));
            Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
            Common_Draw("");
            Common_Draw("Channel is %s", playing ? "playing" : "stopped");
            Common_Draw("Volume %0.2f", volume);
            Common_Draw("Frequency %0.2f", frequency);
        }

        Common_Sleep(50);
    } while (!Common_BtnPress(BTN_QUIT));

    /*
        Shut down
    */
    result = dsp->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    Common_Close();

    return 0;
}
void AudioVisualizerApp::setup()
{
	// initialize signals
	signalChannelEnd = false;

	// make a list of valid audio file extensions and initialize audio variables
	const char* extensions[] = { "mp3", "wav", "ogg" };
	mAudioExtensions = vector<string>( extensions, extensions + 2 );
	mAudioPath = getAssetPath( "" );
	mIsAudioPlaying = false;

	// setup camera
	mCamera.setPerspective( 50.0f, 1.0f, 1.0f, 10000.0f );
	mCamera.lookAt( vec3( -kWidth / 4, kHeight / 2, -kWidth / 8 ), vec3( kWidth / 4, -kHeight / 8, kWidth / 4 ) );

	mCameraUi.setCamera( &mCamera );

	// create channels from which we can construct our textures
	mChannelLeft = Channel32f( kBands, kHistory );
	mChannelRight = Channel32f( kBands, kHistory );
	memset( mChannelLeft.getData(), 0, mChannelLeft.getRowBytes() * kHistory );
	memset( mChannelRight.getData(), 0, mChannelRight.getRowBytes() * kHistory );

	// create texture format (wrap the y-axis, clamp the x-axis)
	mTextureFormat.setWrapS( GL_CLAMP_TO_BORDER );
	mTextureFormat.setWrapT( GL_REPEAT );
	mTextureFormat.setMinFilter( GL_LINEAR );
	mTextureFormat.setMagFilter( GL_LINEAR );
	mTextureFormat.loadTopDown( true );

	// compile shader
	try {
		mShader = gl::GlslProg::create( loadAsset( "shaders/spectrum.vert" ), loadAsset( "shaders/spectrum.frag" ) );
	}
	catch( const std::exception& e ) {
		console() << e.what() << std::endl;
		quit();
		return;
	}

	// create static mesh (all animation is done in the vertex shader)
	std::vector<vec3>		positions;
	std::vector<Colorf>		colors;
	std::vector<vec2>		coords;
	std::vector<uint32_t>	indices;

	for( size_t h = 0; h < kHeight; ++h ) {
		for( size_t w = 0; w < kWidth; ++w ) {
			// add polygon indices
			if( h < kHeight - 1 && w < kWidth - 1 ) {
				size_t offset = positions.size();

				indices.emplace_back( offset );
				indices.emplace_back( offset + kWidth );
				indices.emplace_back( offset + kWidth + 1 );
				indices.emplace_back( offset );
				indices.emplace_back( offset + kWidth + 1 );
				indices.emplace_back( offset + 1 );
			}

			// add vertex
			positions.emplace_back( vec3( float( w ), 0, float( h ) ) );

			// add texture coordinates
			// note: we only want to draw the lower part of the frequency bands,
			//  so we scale the coordinates a bit
			const float part = 0.5f;
			float s = w / float( kWidth - 1 );
			float t = h / float( kHeight - 1 );
			coords.emplace_back( vec2( part - part * s, t ) );

			// add vertex colors
			colors.emplace_back( Color( CM_HSV, s, 0.5f, 0.75f ) );
		}
	}

	gl::VboMesh::Layout layout;
	layout.usage( GL_STATIC_DRAW );
	layout.attrib( geom::Attrib::POSITION, 3 );
	layout.attrib( geom::Attrib::COLOR, 3 );
	layout.attrib( geom::Attrib::TEX_COORD_0, 2 );

	mMesh = gl::VboMesh::create( positions.size(), GL_TRIANGLES, { layout }, indices.size(), GL_UNSIGNED_INT );
	mMesh->bufferAttrib( geom::POSITION, positions.size() * sizeof( vec3 ), positions.data() );
	mMesh->bufferAttrib( geom::COLOR, colors.size() * sizeof( vec3 ), colors.data() );
	mMesh->bufferAttrib( geom::TEX_COORD_0, coords.size() * sizeof( vec2 ), coords.data() );
	mMesh->bufferIndices( indices.size() * sizeof( uint32_t ), indices.data() );

	// play audio using the Cinder FMOD block
	FMOD::System_Create( &mFMODSystem );
	mFMODSystem->init( 32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL );
	mFMODSound = nullptr;
	mFMODChannel = nullptr;

	playAudio( findAudio( mAudioPath ) );

	mIsMouseDown = false;
	mMouseUpDelay = 30.0;
	mMouseUpTime = getElapsedSeconds() - mMouseUpDelay;

	// the texture offset has two purposes:
	//  1) it tells us where to upload the next spectrum data
	//  2) we use it to offset the texture coordinates in the shader for the scrolling effect
	mOffset = 0;
}
Beispiel #24
0
int main(int argc, char *argv[])
{
    FMOD::System       *system;
    FMOD::Sound        *sound;
    FMOD::Channel      *channel;
    FMOD::DSP          *mydsp;
    FMOD_RESULT         result;
    int                 key;
    unsigned int        version;
    float               pan = 0;

    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }

    result = system->init(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound);
    ERRCHECK(result);

    printf("===============================================================================\n");
    printf("Custom DSP example. Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===============================================================================\n");
    printf("Press 'f' to activate, deactivate user filter\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
    ERRCHECK(result);

    /*
        Create the DSP effects.
    */  
    { 
        FMOD_DSP_DESCRIPTION  dspdesc; 

        memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION)); 

        strcpy(dspdesc.name, "My first DSP unit"); 
        dspdesc.channels     = 0;                   // 0 = whatever comes in, else specify. 
        dspdesc.read         = myDSPCallback; 
        dspdesc.userdata     = (void *)0x12345678; 

        result = system->createDSP(&dspdesc, &mydsp); 
        ERRCHECK(result); 
    } 

    /*
        Inactive by default.
    */
    mydsp->setBypass(true);

    /*
        Main loop.
    */
    result = system->addDSP(mydsp, 0); 


    /*
        Main loop.
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case 'f' : 
                case 'F' : 
                {
                    static bool active = false;

                    mydsp->setBypass(active);

                    active = !active;
                    break;
                }
            }
        }

        system->update();

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = sound->release();
    ERRCHECK(result);

    result = mydsp->release();
    ERRCHECK(result);

    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}
int main(int argc, char *argv[])
{
    FMOD::System           *system;
    FMOD::Sound            *sound;
    FMOD::Channel          *channel = 0;
    FMOD_RESULT             result;
    FMOD_MODE               mode = FMOD_2D | FMOD_HARDWARE | FMOD_CREATESTREAM;
    unsigned int version;

    if (argc != 3) {
        std::cout << "unpacker.exe fsbPath outdirPath" << std::endl;
        return 1;
    }

    auto fsbPath = std::string(argv[1]);
    auto outPath = std::string(argv[2]);

    //fsbPath = "LoL_SFX_ziggs.fsb";
    //fsbPath = "LoL_SFX_karma_base.fsb";
    //fsbPath = "LoL_SFX_fiddlesticks.fsb";


    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }

    //system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER);
    result = system->init(1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    auto codecHandle = registerLeagueCodec(system, 50);

    int numsubsounds;
    FMOD::Sound *subSound = nullptr;
    char name[256];
    int soundNum = 0;

    try {
        result = system->createSound(fsbPath.c_str(), mode, nullptr, &sound);
        ERRCHECK(result);

        result = sound->getNumSubSounds(&numsubsounds);
        ERRCHECK(result);
        soundNum = 0;


        sound->getSubSound(0, &subSound);
        subSound->getName(name, 256);
        subSound->release();

        makePath(outPath.c_str());
        sound->release();
        system->close();
        system->release();

        std::set<std::string> writtenFiles;

        FMOD::Channel* channel;
        bool playing;
        for (int sndIdx = 0; sndIdx < numsubsounds; sndIdx++) {
            ERRCHECK(FMOD::System_Create(&system));
            ERRCHECK(system->getVersion(&version));
            system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER_NRT);
            auto outFilePath = outPath + "\\" + std::string(name) + ".wav";
            if (writtenFiles.find(outFilePath) != writtenFiles.end()) {
                int cnt = 1;
                char arr[80];
                do {
                    _itoa_s(cnt, arr, 10);
                    outFilePath = outPath + "\\" + std::string(name) + "_" + std::string(arr) + ".wav";
                    cnt++;
                } while (writtenFiles.find(outFilePath) != writtenFiles.end());
            }
            writtenFiles.insert(outFilePath);
            ERRCHECK(system->init(1, FMOD_INIT_STREAM_FROM_UPDATE, (void*)outFilePath.c_str()));
            auto codecHandle = registerLeagueCodec(system, 50);
            system->createSound(fsbPath.c_str(), mode, nullptr, &sound);
            sound->getSubSound(sndIdx, &subSound);
            system->playSound(FMOD_CHANNEL_FREE, subSound, false, &channel);
            do {
                
                system->update();
                channel->isPlaying(&playing);
            } while (playing);
            subSound->release();


            if (sndIdx < numsubsounds - 1) {
                sound->getSubSound(sndIdx+1, &subSound);
                subSound->getName(name, 256);
                subSound->release();
                outFilePath = outPath + "\\" + std::string(name) + ".wav";
            }
            sound->release();
            system->close();
            system->release();
        }
    }
    catch (const std::runtime_error& error) {
        std::cout << "Exception caught:" << std::endl;
        std::cout << "   " << error.what() << std::endl;
    }

    return 0;
}
Beispiel #26
0
int main(int argc, char *argv[])
{
    FMOD::System           *system;
    FMOD::Sound            *sound;
    FMOD::Channel          *channel = 0;
    FMOD_RESULT             result;
    FMOD_MODE               mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_HARDWARE;
    int                     key;
    int                     channels = 2;
    FMOD_CREATESOUNDEXINFO  createsoundexinfo;
    unsigned int            version;

    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }

    result = system->init(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);
        
    printf("============================================================================\n");
    printf("User Created Sound Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("============================================================================\n");
    printf("Sound played here is generated in realtime.  It will either play as a stream\n");
    printf("which means it is continually filled as it is playing, or it will play as a \n");
    printf("static sample, which means it is filled once as the sound is created, then  \n");
    printf("when played it will just play that short loop of data.                      \n");
    printf("============================================================================\n");
    printf("\n");

    do
    {
        printf("Press 1 to play as a runtime decoded stream. (will carry on infinitely)\n");
        printf("Press 2 to play as a static in memory sample. (loops a short block of data)\n");
        printf("Press Esc to quit.\n\n");
        key = _getch();

    } while (key != 27 && key != '1' && key != '2');

    if (key == 27)
    {
        return 0;
    }
    else if (key == '1')
    {
        mode |= FMOD_CREATESTREAM;
    }

    memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    createsoundexinfo.cbsize            = sizeof(FMOD_CREATESOUNDEXINFO);              /* required. */
    createsoundexinfo.decodebuffersize  = 44100;                                       /* Chunk size of stream update in samples.  This will be the amount of data passed to the user callback. */
    createsoundexinfo.length            = 44100 * channels * sizeof(signed short) * 5; /* Length of PCM data in bytes of whole song (for Sound::getLength) */
    createsoundexinfo.numchannels       = channels;                                    /* Number of channels in the sound. */
    createsoundexinfo.defaultfrequency  = 44100;                                       /* Default playback rate of sound. */
    createsoundexinfo.format            = FMOD_SOUND_FORMAT_PCM16;                     /* Data format of sound. */
    createsoundexinfo.pcmreadcallback   = pcmreadcallback;                             /* User callback for reading. */
    createsoundexinfo.pcmsetposcallback = pcmsetposcallback;                           /* User callback for seeking. */

    result = system->createSound(0, mode, &createsoundexinfo, &sound);
    ERRCHECK(result);

    printf("Press space to pause, Esc to quit\n");
    printf("\n");

    /*
        Play the sound.
    */

    result = system->playSound(FMOD_CHANNEL_FREE, sound, 0, &channel);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        if (_kbhit())
        {
            key = _getch();

            switch (key)
            {
                case ' ' :
                {
                    bool paused;
                    channel->getPaused(&paused);
                    channel->setPaused(!paused);
                    break;
                }
            }
        }

        system->update();

        if (channel)
        {
            unsigned int ms;
            unsigned int lenms;
            bool         playing;
            bool         paused;

            channel->isPlaying(&playing);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = channel->getPaused(&paused);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
        }

        Sleep(20);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = sound->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}
Beispiel #27
0
int main(int argc, char *argv[])
{
	int numSounds = 1;
    FMOD::System        *system;
    FMOD::Sound         *sound[numSounds];
	FMOD::Sound         *applause;
    FMOD::Channel       *channel[numSounds];
	FMOD::Channel       *applauseChannel;
    FMOD::DSP           *dsppitch;
	FMOD::DSP        *dsplowpass    = 0;
    FMOD::DSP        *dsphighpass   = 0;
    FMOD::DSP        *dspecho       = 0;
    FMOD::DSP        *dspflange     = 0;
    FMOD::DSP        *dspdistortion = 0;
    FMOD::DSP        *dspchorus     = 0;
    FMOD::DSP        *dspparameq    = 0;
    FMOD_RESULT          result;
    int                  key;
    unsigned int         version;
    float                pan = 0;
	float                volume;
	float                frequency;
	int					tempFrequency = 0;
	int					tempPitch = 0;
	int					frequencyCount = 0;
	int					pitchCount = 0;
	int					tempoChange = 0;
	float                speed;
	float				pitch = 1;
	float				originalFrequency;
	string				line;
	int					lineCount = 0;
	int inc = 0;
	int count;
	
	float frequencyArray[numSounds];
	float frequencyCountArray[numSounds];
	float pitchfArray[numSounds];
	float volumeArray[numSounds];
	float panArray[numSounds];
	
	float pitchf = 1.0f;
	
    /*
	 Create a System object and initialize.
	 */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);
	
    result = system->getVersion(&version);
    ERRCHECK(result);
	
    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }
	
    result = system->init(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);
	
	result = system->createSound("../Config/Seven Nation Army Drum.mp3", FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound[0]);
    ERRCHECK(result);
		
    printf("===============================================================================\n");
    printf("									Maestro									   \n");
    printf("===============================================================================\n");
	printf("Press '1' to play left speaker only\n");
    printf("Press '2' to play right speaker only\n");
	printf("Press '3' to play from both speakers\n");
    printf("Press '[' to pan sound left\n");
    printf("Press ']' to pan sound right\n");
	printf("Press 'v/V' to increase volume\n");
	printf("Press 'd/D' to decrease volume\n");
	printf("Press '6' pitch octave down\n");
	printf("Press '7' pitch semitone down\n");
	printf("Press '8' pitch semitone up\n");
	printf("Press '9' pitch octave up\n");
    printf("Press 'Esc' to quit\n");
	printf("Press 'n' pitch scale down\n");
    printf("Press 'm' pitch scale up\n");
    printf("\n");
	
	for (count = 0; count < numSounds; count++)
    {
		result = system->playSound(FMOD_CHANNEL_FREE, sound[count], false, &channel[count]);
		ERRCHECK(result);
		
		bool paused;
		
		channel[0]->getPaused(&paused);
		ERRCHECK(result);
		
		paused = !paused;
		
		result = channel[0]->setPaused(paused);
		ERRCHECK(result);
	}

	
	//Create the DSP effects.
	result = system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsppitch);
    ERRCHECK(result);
	result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_HIGHPASS, &dsphighpass);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_ECHO, &dspecho);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_FLANGE, &dspflange);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_DISTORTION, &dspdistortion);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_CHORUS, &dspchorus);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_PARAMEQ, &dspparameq);
    ERRCHECK(result);
	
	for (count = 0; count < numSounds; count++)
    {
		channel[count]->getVolume(&volume);
		channel[count]->setVolume(.3);
		channel[count]->getVolume(&volume);
		
	}
	printf("Initial Volume: %f \n", volume);
	
	channel[0]->getFrequency(&frequency);
	channel[0]->getFrequency(&originalFrequency);
	printf("Initial Frequency: %f \n", frequency);
	
	
    /*
	 Main loop.
	 */
    do
    {
		ifstream myfile;
		myfile.open("../../Config/groupb.txt");
		while ( myfile.good() )
		{
			//printf("Line Count: %d \n", lineCount);
			for(int i = 0; i < lineCount; i++){
				getline (myfile,line);
			}
			getline (myfile,line);
			if (line.compare("start") == 0){
				bool paused;
				
				channel[0]->getPaused(&paused);
				ERRCHECK(result);
				
				paused = !paused;
				
				result = channel[0]->setPaused(paused);
				ERRCHECK(result);
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			if (line.compare("iVol") == 0){
				channel[0]->getVolume(&volume);
				channel[0]->setVolume(1.0f);
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			if (line.compare("dVol") == 0){
				channel[0]->getVolume(&volume);
				channel[0]->setVolume(.1);
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			if (line.compare("iPitch") == 0){
				
				result = dsppitch->remove();
				ERRCHECK(result);
				
				result = system->addDSP(dsppitch, 0);
				ERRCHECK(result);
				
				inc++;
				pitch = pow(1.059f,inc);
				
				result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, pitch);
				ERRCHECK(result);
				
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			if (line.compare("dPitch") == 0){
				result = dsppitch->remove();
				ERRCHECK(result);
				
				result = system->addDSP(dsppitch, 0);
				ERRCHECK(result);
				
				inc--;
				pitch = pow(1.059,inc);
				
				result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, pitch);
				ERRCHECK(result);
				
				
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			if (line.compare("left") == 0){
				result = channel[0]->setSpeakerMix(1.0f, 0, 0, 0, 0, 0, 0, 0);
				ERRCHECK(result);
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			if (line.compare("right") == 0){
				result = channel[0]->setSpeakerMix(0, 1.0f, 0, 0, 0, 0, 0, 0);
				ERRCHECK(result);
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			if (line.compare("forward") == 0){
				result = channel[0]->setSpeakerMix(1.0f, 1.0f, 0, 0, 0, 0, 0, 0);
				ERRCHECK(result);
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			if (line.compare("pitch") == 0){
				bool active;
				
				result = dsppitch->getActive(&active);
				ERRCHECK(result);
				
				if (active)
				{
					result = dsppitch->remove();
					ERRCHECK(result);
				}
				else
				{
					result = system->addDSP(dsppitch, 0);
					ERRCHECK(result);
					
					result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, 1.2f);
					ERRCHECK(result);
					
				}
				
				lineCount++;
				break;
				
			}
			if (line.compare("pause") == 0){
				bool paused;
				
				channel[0]->getPaused(&paused);
				ERRCHECK(result);
				
				paused = !paused;
				
				result = channel[0]->setPaused(paused);
				ERRCHECK(result);
				lineCount++;
				break;
				
			}
			
			if (line.compare("lowpass") == 0){
				bool active;
				
				result = dsplowpass->getActive(&active);
				ERRCHECK(result);
				
				if (active)
				{
					result = dsplowpass->remove();
					ERRCHECK(result);
				}
				else
				{
					result = system->addDSP(dsplowpass, 0);
					ERRCHECK(result);
				}
				lineCount++;
				break;
				
			}
			
			if (line.compare("highpass") == 0){
				bool active;
				
				result = dsphighpass->getActive(&active);
				ERRCHECK(result);
				
				if (active)
				{
					result = dsphighpass->remove();
					ERRCHECK(result);
				}
				else
				{
					result = system->addDSP(dsphighpass, 0);
					ERRCHECK(result);
				}
				lineCount++;
				break;
				
			}
			
			if (line.compare("echo") == 0){
				bool active;
				
				result = dspecho->getActive(&active);
				ERRCHECK(result);
				
				if (active)
				{
					result = dspecho->remove();
					ERRCHECK(result);
				}
				else
				{
					result = system->addDSP(dspecho, 0);
					ERRCHECK(result);
					
					result = dspecho->setParameter(FMOD_DSP_ECHO_DELAY, 50.0f);
					ERRCHECK(result);
				}
				lineCount++;
				break;
				
			}
			
			if (line.compare("flange") == 0){
				bool active;
				
				result = dspflange->getActive(&active);
				ERRCHECK(result);
				
				if (active)
				{
					result = dspflange->remove();
					ERRCHECK(result);
				}
				else
				{
					result = system->addDSP(dspflange, 0);
					ERRCHECK(result);
				}
				lineCount++;
				break;
				
			}
			
			if (line.compare("distortion") == 0){
				bool active;
				
				result = dspdistortion->getActive(&active);
				ERRCHECK(result);
				
				if (active)
				{
					result = dspdistortion->remove();
					ERRCHECK(result);
				}
				else
				{
					result = system->addDSP(dspdistortion, 0);
					ERRCHECK(result);
					
					result = dspdistortion->setParameter(FMOD_DSP_DISTORTION_LEVEL, 0.8f);
					ERRCHECK(result);
				}
				lineCount++;
				break;
				
			}
			
			if (line.compare("chorus") == 0){
				bool active;
				
				result = dspchorus->getActive(&active);
				ERRCHECK(result);
				
				if (active)
				{
					result = dspchorus->remove();
					ERRCHECK(result);
				}
				else
				{
					result = system->addDSP(dspchorus, 0);
					ERRCHECK(result);
				}
				lineCount++;
				break;
				
			}
			
			if (line.compare("parameq") == 0){
				bool active;
				
				result = dspparameq->getActive(&active);
				ERRCHECK(result);
				
				if (active)
				{
					result = dspparameq->remove();
					ERRCHECK(result);
				}
				else
				{
					result = system->addDSP(dspparameq, 0);
					ERRCHECK(result);
					
					result = dspparameq->setParameter(FMOD_DSP_PARAMEQ_CENTER, 5000.0f);
					ERRCHECK(result);
					result = dspparameq->setParameter(FMOD_DSP_PARAMEQ_GAIN, 0.0f);
					ERRCHECK(result);
				}
				lineCount++;
				break;					
			}
			
			if (line.compare("iTempo") == 0){
				
				//44100
				//62366.816406
				
				channel[0]->getFrequency(&frequency);
				
				float base = 2.0f;
				float newTempo = frequency * pow(base,(6.0f/12.0f));
				
				float pitchf = 1.0f;
				pitchf = pow(.9438f,6);
				
				
				result = dsppitch->remove();
				ERRCHECK(result);
				
				result = system->addDSP(dsppitch, 0);
				ERRCHECK(result);
				
				channel[0]->setFrequency(newTempo);
				
				
				result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, pitchf);
				ERRCHECK(result);
				
				channel[0]->getFrequency(&frequency);
				
				lineCount++;
				break;
			}
			
			if (line.compare("dTempo") == 0){
				
				channel[0]->getFrequency(&frequency);
				
				float base = 2.0f;
				float newTempo = frequency * pow(base,(-6.0f/12.0f));
				
				float pitchf = 1.0f;
				
				result = dsppitch->remove();
				ERRCHECK(result);
				
				result = system->addDSP(dsppitch, 0);
				ERRCHECK(result);
				
				channel[0]->setFrequency(newTempo);
				
				
				result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, pitchf);
				ERRCHECK(result);
				
				channel[0]->getFrequency(&frequency);
				
				lineCount++;
				break;
			}
			
			if (line.compare("quit") == 0){				
				key = 27;
				lineCount++;
				//printf("Line Count: %d \n", lineCount);
				break;
			}
			
		}
		myfile.close();
		
		
        if (kbhit())
        {
            key = getch();
			
            switch (key)
            {
				case 's' :
                {
					bool paused;
					
					channel[0]->getPaused(&paused);
					ERRCHECK(result);
					
					paused = !paused;
					
					result = channel[0]->setPaused(paused);
					ERRCHECK(result);
					break;
				}
				case '1' :
                {
					//	Play Sound From Left Speakers
					for (count = 0; count < numSounds; count++)
					{
						channel[count]->getVolume(&volume);
						result = channel[count]->setSpeakerMix(1.0f, 0, 0, 0, 0, 0, 0, 0);
						ERRCHECK(result);
					}
                    break;
                }
                case '2' :
                {
					//	Play Sound From Right Speakers
					for (count = 0; count < numSounds; count++)
					{
					channel[count]->getVolume(&volume);
					printf("Volume: %f\n", volume);
                    result = channel[count]->setSpeakerMix(0, 1.0f, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);
					}
                    break;
                }
				case '3' :
                {
					//	Play Sound From Both Speakers
					for (count = 0; count < numSounds; count++)
					{
					channel[count]->getVolume(&volume);
                    result = channel[count]->setSpeakerMix(1.0f, 1.0f, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);
					}
                    break;
                }	
                case '4' : 
                {
					//	Decrmenent Tempo
					//if(frequencyCount > -12){
					//if (tempoChange + pitchCount > -12 && abs(pitchCount) < 12 && tempoChange > -12) {
					if (pitchf < 1.98f) {
						frequencyCount--;
						tempoChange++;
						printf("Pitch Count: %d\n", pitchCount);
						printf("Tempo Count: %d\n", tempoChange);
						
						channel[0]->getFrequency(&frequency);
						//printf("Z Initial Frequency: %f \n", frequency);
						
						float base = 2.0f;
						
						//printf("inc by: %f \n", pow(base,(-1.0f/12.0f)));
						float newTempo = frequency * pow(base,(-1.0f/12.0f));
						
						//float pitchf = 1.0f;
						
						//if (pitchCount == 0 && tempoChange == 0) {
						//	pitchf = 1.0f;
						//}
						if (pitchf == 1.0f) {
							pitchf = pow(1.059f,abs(tempoChange + pitchCount));
						}
						else if (pitchf > 1.0f) {
							pitchf = pow(1.059f,abs(tempoChange + pitchCount));
						}
						else if (pitchf < 1.0f) {
							pitchf = pow(.9438f,abs(tempoChange + pitchCount));
						}

						printf("pitchf: %f\n", pitchf);
						printf("Frequency: %f \n", newTempo);
						
						result = dsppitch->remove();
						ERRCHECK(result);
						
						result = system->addDSP(dsppitch, 0);
						ERRCHECK(result);
						
						channel[0]->setFrequency(newTempo);

						result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, pitchf);
						ERRCHECK(result);
						
					}
					else {
						printf("Reached Min Tempo\n");
					}
					
                    break;
                }
				case '5' : 
                {
					//	Incrmenent Tempo
					if (pitchf > 0.52f) {
						frequencyCount++;
						tempoChange--;
						printf("Pitch Count: %d\n", pitchCount);
						printf("Tempo Count: %d\n", tempoChange);
						
						channel[0]->getFrequency(&frequency);
						//printf("Z Initial Frequency: %f \n", frequency);
						
						float base = 2.0f;
						float newTempo = frequency * pow(base,(1.0f/12.0f));
						
						if (pitchf == 1.0f) {
							//printf("tempo one\n");
							pitchf = pow(.9438f,abs(tempoChange + pitchCount));
						}
						else if (pitchf > 1.0f) {
							//printf("tempo inc\n");
							pitchf = pow(1.059f,abs(tempoChange + pitchCount));
						}
						else if (pitchf < 1.0f) {
							//printf("tempo dec\n");
							pitchf = pow(.9438f,abs(tempoChange + pitchCount));
						}
						
						printf("pitchf: %f\n", pitchf);
						
						printf("Frequency: %f \n", newTempo);
						
						
						result = dsppitch->remove();
						ERRCHECK(result);
						
						result = system->addDSP(dsppitch, 0);
						ERRCHECK(result);
						
						channel[0]->setFrequency(newTempo);

										
						result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, pitchf);
						ERRCHECK(result);
					}
					else {
						printf("Reached Max Tempo\n");
					}
					break;
                }	
					
				case '6' : 
                {
					//	Pitch Shift Down Octave
                    bool active;
					
                    result = dsppitch->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dsppitch->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dsppitch, 0);
                        ERRCHECK(result);
						
						result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, 0.5f);
                        ERRCHECK(result);
						
                    }
                    break;
                }
					
				case '7' :
                {
					//	Pitch Shift Down One Note
                    bool active;
					
                    result = dsppitch->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dsppitch->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dsppitch, 0);
                        ERRCHECK(result);
						
						result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, .9438f);
                        ERRCHECK(result);
						
                    }
                    break;
                }
					
				case '8' :
                {
					//	Pitch Shift Up One Note
                    bool active;
					
                    result = dsppitch->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dsppitch->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dsppitch, 0);
                        ERRCHECK(result);
						
						result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, 1.059f);
                        ERRCHECK(result);
						
                    }
                    break;
                }
					
				case '9' :
                {
					//	Pitch Shift Up Octave
                    bool active;
					
                    result = dsppitch->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dsppitch->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dsppitch, 0);
                        ERRCHECK(result);
						
						result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, 2.0f);
                        ERRCHECK(result);
						
                    }
                    break;
                }
					
					
				case 'v' : 
                case 'V' : 
                {
					//	Increment Volume
					for (count = 0; count < numSounds; count++)
					{
					channel[count]->getVolume(&volume);
                    volume += 0.1f;
                    if (volume > 1)
                    {
						volume = 1;
                    }
					//printf("Volume: %f \n", volume);
                    channel[count]->setVolume(volume);
					}
                    break;
                }
				case 'd' : 
                case 'D' : 
                {
					//	Decrement Volume
					for (count = 0; count < numSounds; count++)
					{
					channel[count]->getVolume(&volume);
                    volume -= 0.1f;
                    if (volume < 0)
                    {
						volume = 0;
                    }
					//printf("Volume: %f \n", volume);
                    channel[count]->setVolume(volume);
					}
                    break;
                }
                case '[' :
                {
					// Pan Left
					for (count = 0; count < numSounds; count++)
					{
                    channel[count]->getPan(&pan);
                    pan -= 0.1f;
                    if (pan < -1)
                    {
                        pan = -1;
                    }
                    channel[count]->setPan(pan);
					}
                    break;
                }
                case ']' :
                {
					//	Pan Right
					for (count = 0; count < numSounds; count++)
					{
                    channel[count]->getPan(&pan);
                    pan += 0.1f;
                    if (pan > 1)
                    {
                        pan = 1;
                    }
                    channel[count]->setPan(pan);
					}
                    break;
                }
					
				case 'n' :
                {
					//	Decremental Pitch
					if (pitchf > 0.52f) {
						frequencyCount--;
						pitchCount--;
						printf("Pitch Count: %d\n", pitchCount);
						printf("Tempo Count: %d\n", tempoChange);
						
						if (pitchf == 1.0f) {
							pitchf = pow(.9438f,abs(tempoChange + pitchCount));
						}
						else if (pitchf > 1.0f) {
							pitchf = pow(1.059f,tempoChange + pitchCount);
						}
						else if (pitchf < 1.0f) {
							pitchf = pow(.9438f,abs(tempoChange + pitchCount));
						}
						
						 
						printf("pitchf: %f\n", pitchf);
						
						result = dsppitch->remove();
						ERRCHECK(result);
						
						result = system->addDSP(dsppitch, 0);
						ERRCHECK(result);
											
						result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, pitchf);
						ERRCHECK(result);
					}
					else {
						printf("Reached Min Pitch\n");
					}
										
                    break;
                }
					
					
				case 'm' :
                {
					//	Incremental Pitch
					if (pitchf < 1.98f) {
						frequencyCount++;
						pitchCount++;
						printf("Pitch Count: %d\n", pitchCount);
						printf("Tempo Count: %d\n", tempoChange);

						if (pitchf == 1.0f) {
							pitchf = pow(1.059f,abs(tempoChange + pitchCount));
						}
						else if (pitchf > 1.0f) {
							pitchf = pow(1.059f,tempoChange + pitchCount);
						}
						else if (pitchf < 1.0f) {
							pitchf = pow(.9438f,abs(tempoChange + pitchCount));
						}
						
						printf("pitchf: %f\n", pitchf);
						
						result = dsppitch->remove();
						ERRCHECK(result);
						
						result = system->addDSP(dsppitch, 0);
						ERRCHECK(result);

												
						result = dsppitch->setParameter(FMOD_DSP_PITCHSHIFT_PITCH, pitchf);
						ERRCHECK(result);
					}
					else {
						printf("Reached Max Pitch\n");
					}

                    break;
                }
					
				case 'r' :
                {
					//	Lowpass
					bool active;
					
                    result = dsplowpass->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dsplowpass->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dsplowpass, 0);
                        ERRCHECK(result);
                    }
                    break;
					
				}
					
				case 't' :
                {
					// Highpass
					bool active;
					
                    result = dsphighpass->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dsphighpass->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dsphighpass, 0);
                        ERRCHECK(result);
                    }
                    break;
					
				}
					
				case 'y' :
                {
					//	Echo
					bool active;
					
                    result = dspecho->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dspecho->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dspecho, 0);
                        ERRCHECK(result);
						
                        result = dspecho->setParameter(FMOD_DSP_ECHO_DELAY, 50.0f);
                        ERRCHECK(result);
                    }
                    break;
					
				}
					
				case 'u' :
                {
					//	Flange
					bool active;
					
                    result = dspflange->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dspflange->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dspflange, 0);
                        ERRCHECK(result);
                    }
                    break;
					
				}
					
				case 'i' :
                {
					//	Distortion
					bool active;
					
                    result = dspdistortion->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dspdistortion->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dspdistortion, 0);
                        ERRCHECK(result);
						
                        result = dspdistortion->setParameter(FMOD_DSP_DISTORTION_LEVEL, 0.8f);
                        ERRCHECK(result);
                    }
                    break;
					
				}
					
				case 'o' :
                {
					//	Chorus
					bool active;
					
                    result = dspchorus->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dspchorus->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dspchorus, 0);
                        ERRCHECK(result);
                    }
                    break;
					
				}
					
				case 'p' :
                {
					//	Parameq
					bool active;
					
                    result = dspparameq->getActive(&active);
                    ERRCHECK(result);
					
                    if (active)
                    {
                        result = dspparameq->remove();
                        ERRCHECK(result);
                    }
                    else
                    {
                        result = system->addDSP(dspparameq, 0);
                        ERRCHECK(result);
						
                        result = dspparameq->setParameter(FMOD_DSP_PARAMEQ_CENTER, 5000.0f);
                        ERRCHECK(result);
                        result = dspparameq->setParameter(FMOD_DSP_PARAMEQ_GAIN, 0.0f);
                        ERRCHECK(result);
                    }
                    break;
					
				}
            }
        }
		
        system->update();
		
        {
            int  channelsplaying = 0;
			
			bool dsppitch_active;
			dsppitch	 ->getActive(&dsppitch_active);
			
            system->getChannelsPlaying(&channelsplaying);
			
        }
		
        fflush(stdout);
        Sleep(10);
		
    } while (key != 27);
	
	{
		
		for (count = 0; count < numSounds; count++)
		{
		//channel[count]->getFrequency(&frequency);
		channel[count]->getVolume(&volume);
		int count;
		//float initFreq = frequency;
		float initVol = volume;
		
			for (count = 0; count < 200; count++)
			{
			//printf("Volume: %f \n", volume);
				//channel[count]->setFrequency(frequency);
				channel[count]->setVolume(volume);

				volume   -= (initVol / 200.0f);
				//frequency -= (initFreq / 200.0f);
			
            Sleep(2);
			}
		}		
	}
	
    printf("\n");
	
    /*
	 Shut down
	 */
	channel[0]->setFrequency(originalFrequency);
	
	result = dsppitch->remove();
	ERRCHECK(result);
	
	result = dspparameq->remove();
	ERRCHECK(result);
	
	result = dspchorus->remove();
	ERRCHECK(result);
	
	result = dspdistortion->remove();
	ERRCHECK(result);
	
	result = dspflange->remove();
	ERRCHECK(result);
	
	result = dspecho->remove();
	ERRCHECK(result);
	
	result = dsplowpass->remove();
	ERRCHECK(result);
	
	result = dsphighpass->remove();
	ERRCHECK(result);
	
	for (count = 0; count < numSounds; count++)
	{
		result = sound[count]->release();
		ERRCHECK(result);
	}
	
	result = system->createSound("../../Config/Recital Crowd Applause.aif", FMOD_SOFTWARE, 0, &applause);
	ERRCHECK(result);
	
	wait(.5);
	
	result = system->playSound(FMOD_CHANNEL_FREE, applause, false, &applauseChannel);
	ERRCHECK(result);
	
	wait(10);
	
	result = applause->release();
	ERRCHECK(result);
	
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);
	
    return 0;
}
Beispiel #28
0
int main(int argc, char *argv[])
{
    FMOD::System     *system;
    FMOD::Sound      *sound1, *sound2, *sound3;
    FMOD::Channel    *channel = 0;
    FMOD_RESULT       result;
    int               key;
    unsigned int      version;

    /*
        Global Settings
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        getch();
        return 0;
    }

    result = system->init(32, FMOD_INIT_NORMAL, NULL);
    ERRCHECK(result);

    result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound1);
    ERRCHECK(result);

    result = sound1->setMode(FMOD_LOOP_OFF);
    ERRCHECK(result);

    result = system->createSound("../media/jaguar.wav", FMOD_SOFTWARE, 0, &sound2);
    ERRCHECK(result);

    result = system->createSound("../media/swish.wav", FMOD_SOFTWARE, 0, &sound3);
    ERRCHECK(result);

    printf("===================================================================\n");
    printf("PlaySound Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===================================================================\n");
    printf("\n");
    printf("Press '1' to Play a mono sound using software mixing\n");
    printf("Press '2' to Play a mono sound using software mixing\n");
    printf("Press '3' to Play a stereo sound using software mixing\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Main loop.
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case '1' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound1, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
                case '2' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound2, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
                case '3' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound3, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
            }
        }

        system->update();

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            bool         playing = 0;
            bool         paused = 0;
            int          channelsplaying = 0;

            if (channel)
            {
                FMOD::Sound *currentsound = 0;

                result = channel->isPlaying(&playing);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = channel->getPaused(&paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }
               
                channel->getCurrentSound(&currentsound);
                if (currentsound)
                {
                    result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }
            }

            system->getChannelsPlaying(&channelsplaying);

            printf("\rTime %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
            fflush(stdout);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = sound1->release();
    ERRCHECK(result);
    result = sound2->release();
    ERRCHECK(result);
    result = sound3->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}
Beispiel #29
0
int main(int argc, char *argv[])
{
    FMOD::System     *system;
    FMOD::Sound      *sound;
    FMOD::Channel    *channel = 0;
    FMOD_RESULT       result;
    int               key;
    unsigned int      version;
    HANDLE            threadhandle;

    InitializeCriticalSection(&gCrit);
    
	threadhandle = (HANDLE)_beginthreadex(NULL, 0, ProcessQueue, 0, 0, 0);
    if (!threadhandle)
    {
        printf("Failed to create file thread.\n");
        return 0;
    }
    
    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }

    result = system->init(1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->setStreamBufferSize(32768, FMOD_TIMEUNIT_RAWBYTES);
    ERRCHECK(result);
    
    result = system->setFileSystem(myopen, myclose, myread, myseek, myasyncread, myasynccancel, 2048);
    ERRCHECK(result);

    printf("====================================================================\n");
    printf("Stream IO Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("====================================================================\n");
    printf("\n");
    printf("\n");
    printf("====================== CALLING CREATESOUND ON MP3 =======================\n");
    
    result = system->createStream("../media/wave.mp3", FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_2D | FMOD_IGNORETAGS, 0, &sound);
    ERRCHECK(result);

    printf("====================== CALLING PLAYSOUND ON MP3 =======================\n");

    result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        if (sound)
        {
            FMOD_OPENSTATE openstate;
            bool starving;

            sound->getOpenState(&openstate, 0, &starving, 0);
            
            if (starving)
            {
                printf("Starving\n");
                result = channel->setMute(true);
            }
            else
            {
                result = channel->setMute(false);
                ERRCHECK(result);
            }
        }

       
        if (_kbhit())
        {
            key = _getch();

            switch (key)
            {
                case ' ' :
                {
                    result = sound->release();
                    if (result == FMOD_OK)
                    {
                        sound = 0;
                        printf("Released sound.\n");
                    }
                    break;
                }
            }
        }

        system->update();
        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    if (sound)
    {
        result = sound->release();
        ERRCHECK(result);
    }
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    gThreadQuit = true;   

    return 0;
}
Beispiel #30
0
int main(int argc, char *argv[])
{
    FMOD::System     *system;
    FMOD::Sound      *sound;
    FMOD_RESULT       result;
    unsigned int      version;

    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }

    result = system->init(1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->createStream("../media/wave.mp3", FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
    ERRCHECK(result);

    printf("==========================================================================\n");
    printf("Offline Decoding Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("==========================================================================\n");
    printf("\n");
    printf("This program will open wave.mp3 and decode it into wave.raw using the\n");
    printf("Sound::readData function.\n");
    printf("\n");

    /*
        Decode the sound and write it to a .raw file.
    */
    {
        void *data;
        unsigned int length = 0, read;
        unsigned int bytesread;
        FILE *outfp;

        #define CHUNKSIZE 4096

        result = sound->getLength(&length, FMOD_TIMEUNIT_PCMBYTES);
        ERRCHECK(result);

        outfp = fopen("output.raw", "wb");
        if (!outfp)
        {
            printf("Error!  Could not open output.raw output file.\n");
            return 0;
        }

        data = malloc(CHUNKSIZE);
        if (!data)
        {
            printf("Error!  Failed to allocate %d bytes.\n", CHUNKSIZE);
            return 0;
        }

        bytesread = 0;
        do
        {
            result = sound->readData((char *)data, CHUNKSIZE, &read);

            fwrite((char *)data, read, 1, outfp);
                       
            bytesread += read;

            printf("writing %d bytes of %d to output.raw\r", bytesread, length);
        }
        while (result == FMOD_OK && read == CHUNKSIZE);

        /*
            Loop terminates when either 
            1. the read function returns an error.  (ie FMOD_ERR_FILE_EOF etc).
            2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi).

            If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size, 
            but this will not usually happen if FMOD_ACCURATETIME is used.  (this will give the correct length for VBR formats)
        */

        printf("\n");

        if (outfp)
        {
            fclose(outfp);
        }
    }
        

    printf("\n");

    /*
        Shut down
    */
    result = sound->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}