Ejemplo n.º 1
0
	Sound::Sound(std::string filename, glm::vec3 position, bool loop)
	{
		FMOD_VECTOR velocity = { 0, 0, 0 };
		FMOD_VECTOR pos = { position.x, position.y, position.z };

		FMOD::System *system = AudioSystem::GetFMODSystem();

		FMOD_RESULT result;

		mFilepath = kSoundDir + filename;
		mPosition = pos;
		mVelocity = velocity;

		result = system->createSound(mFilepath.c_str(), FMOD_3D, 0, &mSound);
		if (result != FMOD_OK) {
			//TODO: Error handling
		}

		result = system->playSound(FMOD_CHANNEL_FREE, mSound, true, &mChannel);
		if (result != FMOD_OK) {
			//TODO: Error handling
		}

		Update();

		SetLooping(loop);
	}
Ejemplo n.º 2
0
void DuckHuntMain::OnMouseDown(WPARAM btnState, int x, int y)
{
	mLastMousePos.x = x;
	mLastMousePos.y = y;

	if ((btnState & MK_RBUTTON) != 0)
	{
		mZoomed = true;
		zoom = 1;
		mCam.Zoom(AspectRatio());
	}
	if ((btnState & MK_LBUTTON) != 0)
	{
		result = mSystem->playSound(mGunFire, 0, false, &channel);

	
		pickedModel = pick(mScreenViewport.Width / 2, mScreenViewport.Height / 2, mModelInstances);

		if (pickedModel != -1)
		{
			score++;
			mModelInstances.erase(mModelInstances.begin() + pickedModel);
		}
		

	}
	SetCapture(mhMainWnd);
}
Ejemplo n.º 3
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;
	}
Ejemplo n.º 4
0
void AudioVisualizerApp::playAudio( const fs::path& file )
{
	FMOD_RESULT err;

	// ignore if this is not a file
	if( file.empty() || !fs::is_regular_file( file ) )
		return;

	// if audio is already playing, stop it first
	stopAudio();

	// stream the audio
	err = mFMODSystem->createStream( file.string().c_str(), FMOD_SOFTWARE, NULL, &mFMODSound );
	err = mFMODSystem->playSound( FMOD_CHANNEL_FREE, mFMODSound, false, &mFMODChannel );

	// we want to be notified of channel events
	err = mFMODChannel->setCallback( channelCallback );

	// keep track of the audio file
	mAudioPath = file;
	mIsAudioPlaying = true;

	// 
	console() << "Now playing:" << mAudioPath.filename() << std::endl;
}
Ejemplo n.º 5
0
void _TBOX_PREFIX_App::setup()
{
    FMOD::System_Create( &mSystem );
    mSystem->init( 32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL );

    mSystem->createSound( getAssetPath( "Blank__Kytt_-_08_-_RSPN.mp3" ).string().c_str(), FMOD_SOFTWARE, NULL, &mSound );
	mSound->setMode( FMOD_LOOP_NORMAL );

	mSystem->playSound( FMOD_CHANNEL_FREE, mSound, false, &mChannel );
}
Ejemplo n.º 6
0
void Game::initSound()
{
	FMOD::System *system = NULL;
	FMOD::Sound *sound = NULL;
	FMOD::Channel *channel;
	
	FMOD::System_Create(&system);
	system->init(32, FMOD_INIT_NORMAL, 0);
	system->createSound("data/drumloop.wav", FMOD_SOFTWARE, 0, &sound);
	system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
}
Ejemplo n.º 7
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 );
			}
		}
	}
Ejemplo n.º 8
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 );
			}
		}
	}
Ejemplo n.º 9
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 );
			}
		}
	}
Ejemplo n.º 10
0
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 );
}
Ejemplo n.º 11
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 );
			});
		}
	}
Ejemplo n.º 12
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();
}
Ejemplo n.º 13
0
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 );
}
Ejemplo n.º 14
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;

	}
Ejemplo n.º 15
0
int FMOD_Main()
{
    FMOD::System       *system;
    FMOD::Sound        *sound;
    FMOD::Channel      *channel;
    FMOD::DSP          *mydsp;
    FMOD::ChannelGroup *mastergroup;
    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);

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

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

    /*
        Create the DSP effect.
    */  
    { 
        FMOD_DSP_DESCRIPTION dspdesc; 
        memset(&dspdesc, 0, sizeof(dspdesc));
        
        strncpy(dspdesc.name, "My first DSP unit", sizeof(dspdesc.name));
        dspdesc.version = 0x00010000;
        dspdesc.numinputbuffers = 1;
        dspdesc.numoutputbuffers = 1;
        dspdesc.read = myDSPCallback; 
        dspdesc.userdata = (void *)0x12345678; 

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

    /*
        Attach the DSP, inactive by default.
    */
    result = mydsp->setBypass(true);
    ERRCHECK(result);

    result = system->getMasterChannelGroup(&mastergroup);
    ERRCHECK(result);

    result = mastergroup->addDSP(0, mydsp, 0);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        bool bypass;

        Common_Update();

        result = mydsp->getBypass(&bypass);
        ERRCHECK(result);

        if (Common_BtnPress(BTN_ACTION1))
        {
            bypass = !bypass;
            
            result = mydsp->setBypass(bypass);
            ERRCHECK(result);
        }

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

        Common_Draw("==================================================");
        Common_Draw("Custom DSP Example.");
        Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
        Common_Draw("==================================================");
        Common_Draw("");
        Common_Draw("Press %s to toggle filter bypass", Common_BtnStr(BTN_ACTION1));
        Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
        Common_Draw("");
        Common_Draw("Filter is %s", bypass ? "inactive" : "active");

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

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

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

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

    Common_Close();

    return 0;
}
Ejemplo n.º 16
0
/*==============================================================================
Record example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2014.

This example shows how to record continuously, and play back the same data as
closely to the record cursor as possible without stuttering.
==============================================================================*/
#include "fmod.hpp"
#include "common.h"

#define LATENCY_MS      (50) /* Some devices will require higher latency to avoid glitches */
int FMOD_Main()
{
    FMOD::System   *system = 0;
    FMOD::Sound    *sound = 0;
    FMOD::Channel  *channel = 0;
    FMOD_RESULT     result = FMOD_OK;
    unsigned int    version = 0;
    unsigned int    soundlength = 0;
    bool            dspenabled = false;
    void           *extradriverdata = 0;
    unsigned int    recordpos = 0;
    unsigned int    recorddelta = 0;
    unsigned int    minrecorddelta = (unsigned int)-1;
    unsigned int    lastrecordpos = 0;
    unsigned int    samplesrecorded = 0;
    unsigned int    playpos = 0;
    float           smootheddelta = 0;
    FMOD_CREATESOUNDEXINFO exinfo;
    
    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(100, FMOD_INIT_NORMAL, extradriverdata);
    ERRCHECK(result);


    int recordrate;
    int recordchannels;
    result = system->getRecordDriverInfo(0, NULL, NULL, 0, 0, &recordrate, 0, &recordchannels);
    ERRCHECK(result);

    unsigned int adjustedlatency = (recordrate * LATENCY_MS) / 1000;
    unsigned int driftthreshold =  adjustedlatency / 2;


    /*
        Create user sound to record into.
    */
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = recordchannels;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = recordrate;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5; /* 5 second buffer, doesnt really matter how big this is, but not too small of course. */
    
    result = system->createSound(0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    result = system->recordStart(0, sound, true);
    ERRCHECK(result);

    result = sound->getLength(&soundlength, FMOD_TIMEUNIT_PCM);
    ERRCHECK(result);

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

        if (Common_BtnPress(BTN_ACTION1))
        {
            FMOD_REVERB_PROPERTIES propon = FMOD_PRESET_CONCERTHALL;
            FMOD_REVERB_PROPERTIES propoff = FMOD_PRESET_OFF;

            dspenabled = !dspenabled;

            result = system->setReverbProperties(0, dspenabled ? &propon : &propoff);
            ERRCHECK(result);
        }

        result = system->update();
        ERRCHECK(result);
       
        system->getRecordPosition(0, &recordpos);
        ERRCHECK(result);

        recorddelta = (recordpos >= lastrecordpos) ? (recordpos - lastrecordpos) : (recordpos + soundlength - lastrecordpos);
        lastrecordpos = recordpos;
        
        samplesrecorded += recorddelta;
        if (samplesrecorded >= adjustedlatency && !channel)
        {
            result = system->playSound(sound, 0, false, &channel);
            ERRCHECK(result);
        }

        if (channel && recorddelta)
        {
            /*
                If the record driver steps the position of the record cursor in larger increments than the user
                defined latency value, then we should increase our latency value to match.
            */
            if (recorddelta < minrecorddelta)
            {
                minrecorddelta = recorddelta;
                if (adjustedlatency < recorddelta)
                {
                    adjustedlatency = recorddelta;
                }
            }

            result = channel->getPosition(&playpos, FMOD_TIMEUNIT_PCM);
            ERRCHECK(result);
            
	        /*
                Smooth total
            */
            {
                const float dampratio = 0.97f;
                static float total = 0;

                total *= dampratio;
                total += (recordpos >= playpos) ? (recordpos - playpos) : (recordpos + soundlength - playpos);
                smootheddelta = total * (1.0f - dampratio);
            }
           
            if (smootheddelta < (adjustedlatency - driftthreshold) || smootheddelta > soundlength / 2) /* If play cursor is catching up to record (or passed it), slow playback down */
            {
                channel->setFrequency(recordrate - (recordrate / 50)); /* Decrease speed by 2% */
            }
            else if (smootheddelta > (adjustedlatency + driftthreshold)) /* If play cursor is falling too far behind record, speed playback up */
            {
                channel->setFrequency(recordrate + (recordrate / 50)); /* Increase speed by 2% */
            }
            else
            {
                channel->setFrequency(recordrate); /* Otherwise set to normal rate */
            }
        }
       
        Common_Draw("==================================================");
        Common_Draw("Record Example.");
        Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
        Common_Draw("==================================================");
        Common_Draw("");
        Common_Draw("Adjust LATENCY define to compensate for stuttering");
        Common_Draw("");
        Common_Draw("Press %s to %s DSP effect", Common_BtnStr(BTN_ACTION1), dspenabled ? "disable" : "enable");
        Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
        Common_Draw("");
        Common_Draw("Default playback latency: %4d (%dms)", (recordrate * LATENCY_MS) / 1000, LATENCY_MS);
        Common_Draw("Current playback latency: %4d (%dms)", (int)smootheddelta, (int)smootheddelta * 1000 / recordrate);
        Common_Draw("Record position: %6d", recordpos);
        Common_Draw("Play Position:   %6d", playpos);

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

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

    Common_Close();

    return 0;
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
int FMOD_Main()
{
    FMOD::System     *system;
    FMOD::Sound      *sound1, *sound2;
    FMOD::Channel    *channel = 0;
    FMOD_RESULT       result;
    unsigned int      version;
    int               selection = 0;
    void             *extradriverdata = 0;
    FMOD_SPEAKERMODE  speakermode = FMOD_SPEAKERMODE_STEREO;
    
    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);

    result = system->getSoftwareFormat(0, &speakermode, 0);
    ERRCHECK(result);

    result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_2D | FMOD_LOOP_OFF, 0, &sound1);
    ERRCHECK(result);

    result = system->createSound(Common_MediaPath("stereo.ogg"), FMOD_2D | FMOD_LOOP_OFF,  0, &sound2);
    ERRCHECK(result);

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

        if (Common_BtnPress(BTN_UP) && (selection != 0))
        {
            selection--;
        }
        
        if (Common_BtnPress(BTN_DOWN) && (selection != (SELECTION_COUNT - 1)))
        {
            selection++;
        }

        if (Common_BtnPress(BTN_ACTION1) && isSelectionAvailable(speakermode, selection))
        {
            if (selection == 0) /* Mono front left */
            {
                result = system->playSound(sound1, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixLevelsOutput(1.0f, 0, 0, 0, 0, 0, 0, 0);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
            else if (selection == 1) /* Mono front right */
            {
                result = system->playSound(sound1, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixLevelsOutput(0, 1.0f, 0, 0, 0, 0, 0, 0);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
            else if (selection == 2) /* Mono center */
            {
                result = system->playSound(sound1, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixLevelsOutput(0, 0, 1.0f, 0, 0, 0, 0, 0);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
            else if (selection == 3) /* Mono surround left */
            {
                result = system->playSound(sound1, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixLevelsOutput(0, 0, 0, 0, 1.0f, 0, 0, 0);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
            else if (selection == 4) /* Mono surround right */
            {
                result = system->playSound(sound1, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixLevelsOutput(0, 0, 0, 0, 0, 1.0f, 0, 0);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
            else if (selection == 5) /* Mono rear left */
            {
                result = system->playSound(sound1, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixLevelsOutput(0, 0, 0, 0, 0, 0, 1.0f, 0);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
            else if (selection == 6) /* Mono rear right */
            {
                result = system->playSound(sound1, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixLevelsOutput(0, 0, 0, 0, 0, 0, 0, 1.0f);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
            else if (selection == 7) /* Stereo front */
            {
                result = system->playSound(sound2, 0, false, &channel);
                ERRCHECK(result);
            }
            else if (selection == 8) /* Stereo front channel swapped */
            {
                float matrix[] = { 0.0f, 1.0f,
                                   1.0f, 0.0f };

                result = system->playSound(sound2, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixMatrix(matrix, 2, 2);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
            else if (selection == 9) /* Stereo (right only) center */
            {
                float matrix[] = { 0.0f, 0.0f,
                                   0.0f, 0.0f,
                                   0.0f, 1.0f };

                result = system->playSound(sound2, 0, true, &channel);
                ERRCHECK(result);

                result = channel->setMixMatrix(matrix, 3, 2);
                ERRCHECK(result);

                result = channel->setPaused(false);
                ERRCHECK(result);
            }
        }

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

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            bool         playing = false;
            bool         paused = false;
            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);
                    }
                }
            }

            result = system->getChannelsPlaying(&channelsplaying);
            ERRCHECK(result);

            Common_Draw("==================================================");
            Common_Draw("Multiple Speaker Example.");
            Common_Draw("Copyright (c) Firelight Technologies 2004-2015.");
            Common_Draw("==================================================");
            Common_Draw("");
            Common_Draw("Speaker mode is set to %s%s", SPEAKERMODE_STRING[speakermode], speakermode < FMOD_SPEAKERMODE_7POINT1 ? " causing some speaker options to be unavailable" : "");
            Common_Draw("");
            Common_Draw("Press %s or %s to select mode", Common_BtnStr(BTN_UP), Common_BtnStr(BTN_DOWN));
            Common_Draw("Press %s to play the sound", Common_BtnStr(BTN_ACTION1));
            for (int i = 0; i < SELECTION_COUNT; i++)
            {
                bool disabled = !isSelectionAvailable(speakermode, i);
                Common_Draw("[%c] %s%s", (selection == i) ? (disabled ? '-' : 'X') : ' ', disabled ? "[N/A] " : "", SELECTION_STRING[i]);
            }
            Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
            Common_Draw("");
            Common_Draw("Time %02d:%02d:%02d/%02d:%02d:%02d : %s", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
            Common_Draw("Channels playing: %d", channelsplaying);
        }

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

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

    Common_Close();

    return 0;
}
Ejemplo n.º 21
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;
}
Ejemplo n.º 22
0
int main(int argc, char *argv[])
{
    FMOD::System       *system;
    FMOD::Sound        *sound[6];
    FMOD::Channel      *channel[6];
    FMOD::ChannelGroup *groupA, *groupB, *masterGroup;
    FMOD_RESULT         result;
    int                 key, count;
    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);

    result = system->createSound("../media/drumloop.wav", FMOD_LOOP_NORMAL, 0, &sound[0]);
    ERRCHECK(result);
    result = system->createSound("../media/jaguar.wav", FMOD_LOOP_NORMAL, 0, &sound[1]);
    ERRCHECK(result);
    result = system->createSound("../media/swish.wav", FMOD_LOOP_NORMAL, 0, &sound[2]);
    ERRCHECK(result);
    result = system->createSound("../media/c.ogg", FMOD_LOOP_NORMAL, 0, &sound[3]);
    ERRCHECK(result);
    result = system->createSound("../media/d.ogg", FMOD_LOOP_NORMAL, 0, &sound[4]);
    ERRCHECK(result);
    result = system->createSound("../media/e.ogg", FMOD_LOOP_NORMAL, 0, &sound[5]);
    ERRCHECK(result);

    result = system->createChannelGroup("Group A", &groupA);
    ERRCHECK(result);

    result = system->createChannelGroup("Group B", &groupB);
    ERRCHECK(result);

    result = system->getMasterChannelGroup(&masterGroup);
    ERRCHECK(result);

    printf("=======================================================================\n");
    printf("ChannelGroups Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("=======================================================================\n");
    printf("\n");
    printf("Group A : drumloop.wav, jaguar.wav, swish.wav\n");
    printf("Group B : c.ogg, d.ogg, e.ogg\n");
    printf("\n");
    printf("Press 'A' to mute/unmute group A\n");
    printf("Press 'B' to mute/unmute group B\n");
    printf("Press 'C' to mute/unmute group A and B (master group)\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Instead of being independent, set the group A and B to be children of the master group.
    */
    result = masterGroup->addGroup(groupA);
    ERRCHECK(result);

    result = masterGroup->addGroup(groupB);
    ERRCHECK(result);

    /*
        Start all the sounds!
    */
    for (count = 0; count < 6; count++)
    {
        result = system->playSound(FMOD_CHANNEL_FREE, sound[count], true, &channel[count]);
        ERRCHECK(result);
        if (count < 3)
        {
            result = channel[count]->setChannelGroup(groupA);
        }
        else
        {
            result = channel[count]->setChannelGroup(groupB);
        }
        ERRCHECK(result);
        result = channel[count]->setPaused(false);
        ERRCHECK(result);
    }   

    /*
        Change the volume of each group, just because we can!  (And makes it less noise).
    */
    result = groupA->setVolume(0.5f);
    ERRCHECK(result);
    result = groupB->setVolume(0.5f);
    ERRCHECK(result);

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

            switch (key)
            {
                case 'a' : 
                case 'A' : 
                {
                    static bool mute = true;

                    groupA->setMute(mute);

                    mute = !mute;
                    break;
                }
                case 'b' : 
                case 'B' : 
                {
                    static bool mute = true;

                    groupB->setMute(mute);

                    mute = !mute;
                    break;
                }
                case 'c' : 
                case 'C' : 
                {
                    static bool mute = true;

                    masterGroup->setMute(mute);

                    mute = !mute;
                    break;
                }
            }
        }

        system->update();

        {
            int  channelsplaying = 0;

            system->getChannelsPlaying(&channelsplaying);

            printf("Channels Playing %2d\r", channelsplaying);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        A little fade out. (over 2 seconds)
    */
    printf("Goodbye!\n");
    {
        float pitch = 1.0f;
        float vol = 1.0f;

        for (count = 0; count < 200; count++)
        {
            masterGroup->setPitch(pitch);
            masterGroup->setVolume(vol);

            vol   -= (1.0f / 200.0f);
            pitch -= (0.5f / 200.0f);

            Sleep(10);
        }
    }

    /*
        Shut down
    */
    for (count = 0; count < 6; count++)
    {
        result = sound[count]->release();
        ERRCHECK(result);
    }

    result = groupA->release();
    ERRCHECK(result);
    result = groupB->release();
    ERRCHECK(result);

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

    return 0;
}
Ejemplo n.º 23
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;

    /*
        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->setFileSystem(myopen, myclose, myread, myseek, 0, 0, 2048);
    ERRCHECK(result);

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

    printf("========================================================================\n");
    printf("File Callbacks Example.  Copyright (c) Firelight Technologies 2004-2015.\n");
    printf("========================================================================\n");
    printf("\n");
    printf("Press space to pause, Esc to quit\n");
    printf("\n");

    /*
        Play the sound.
    */

    result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &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))
            {
                ERRCHECK(result);
            }

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

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

            result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
            {
                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");
            fflush(stdout);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    return 0;
}
Ejemplo n.º 24
0
int main(int argc, char *argv[])
{
    FMOD::System          *system  = 0;
    FMOD::Sound           *sound   = 0;
    FMOD::Channel         *channel = 0;
    FMOD_RESULT            result;
    FMOD_CREATESOUNDEXINFO exinfo;
    int                    key, driver, recorddriver, numdrivers, count;
    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;
    }

    /* 
        System initialization
    */
    printf("---------------------------------------------------------\n");    
    printf("Select OUTPUT type\n");    
    printf("---------------------------------------------------------\n");    
    printf("1 :  OSS        - Open Sound System\n");
    printf("2 :  ALSA       - Advanced Linux Sound Architecture\n");
    printf("3 :  ESD        - Enlightenment Sound Daemon\n");
    printf("4 :  PULSEAUDIO - Pulse Audio Sound Server\n");
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = getch();
    } while (key != 27 && key < '1' && key > '5');
    
    switch (key)
    {
        case '1' :  result = system->setOutput(FMOD_OUTPUTTYPE_OSS);
                    break;
        case '2' :  result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
                    break;
        case '3' :  result = system->setOutput(FMOD_OUTPUTTYPE_ESD);
                    break;
        case '4' :  result = system->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
                    break;
        default  :  return 1; 
    }  
    ERRCHECK(result);
    
    /*
        Enumerate playback devices
    */

    result = system->getNumDrivers(&numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a PLAYBACK driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = system->getDriverInfo(count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = getch();
        if (key == 27)
        {
            return 0;
        }
        driver = key - '1';
    } while (driver < 0 || driver >= numdrivers);

    result = system->setDriver(driver);
    ERRCHECK(result);

    /*
        Enumerate record devices
    */

    result = system->getRecordNumDrivers(&numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a RECORD driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = system->getRecordDriverInfo(count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    recorddriver = 0;
    do
    {
        key = getch();
        if (key == 27)
        {
            return 0;
        }
        recorddriver = key - '1';
    } while (recorddriver < 0 || recorddriver >= numdrivers);

    printf("\n");
  
    result = system->init(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 2;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = 44100;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
    
    result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    printf("===================================================================\n");
    printf("Recording example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===================================================================\n");
    printf("\n");
    printf("Press 'r' to record a 5 second segment of audio and write it to a wav file.\n");
    printf("Press 'p' to play the 5 second segment of audio.\n");
    printf("Press 'l' to turn looping on/off.\n");
    printf("Press 's' to stop recording and playback.\n");
    printf("Press 'w' to save the 5 second segment to a wav file.\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Main loop.
    */
    do
    {
        static FMOD::Channel *channel = 0;
        static bool  looping    = false;
        bool         recording  = false;
        bool         playing    = false;
        unsigned int recordpos = 0;
        unsigned int playpos = 0;
        unsigned int length;

        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case 'r' :
                case 'R' :
                {
                    result = system->recordStart(recorddriver, sound, looping);
                    ERRCHECK(result);
                    break;
                }
                case 'p' :
                case 'P' :
                {
                    if (looping)
                    {
                        sound->setMode(FMOD_LOOP_NORMAL);
                    }
                    else
                    {
                        sound->setMode(FMOD_LOOP_OFF);
                    }
                    ERRCHECK(result);

                    result = system->playSound(FMOD_CHANNEL_REUSE, sound, false, &channel);
                    ERRCHECK(result);
                    break;
                }
                case 'l' :
                case 'L' :
                {
                    looping = !looping;
                    break;
                }
                case 's' :
                case 'S' :
                {
                    result = system->recordStop(recorddriver);
                    if (channel)
                    {
                        channel->stop();
                        channel = 0;
                    }
                    break;
                }
                case 'w' :
                case 'W' :
                {
                    printf("Writing to record.wav ...                                                     \r");

                    SaveToWav(sound);
                    Sleep(500);
                    break;
                }
            }
        }

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

        system->isRecording(recorddriver, &recording);
        ERRCHECK(result);

        system->getRecordPosition(recorddriver, &recordpos);
        ERRCHECK(result);

        if (channel)
        {
            channel->isPlaying(&playing);
            ERRCHECK(result);

            channel->getPosition(&playpos, FMOD_TIMEUNIT_PCM);
            ERRCHECK(result);
        }

        printf("State: %-19s. Record pos = %6d : Play pos = %6d : Loop %-3s\r", recording ? playing ? "Recording / playing" : "Recording" : playing ? "Playing" : "Idle", recordpos, playpos, looping ? "On" : "Off");
        fflush(stdout);

        system->update();

        fflush(stdout);
        Sleep(10);

    } while (key != 27);

    printf("\n");

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

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

    return 0;
}
Ejemplo n.º 25
0
int main(int argc, char *argv[])
{
    FMOD::System          *system  = 0;
    FMOD::Sound           *sound   = 0;
    FMOD::Channel         *channel = 0;
    FMOD_RESULT            result;
    FMOD_CREATESOUNDEXINFO exinfo;
    int                    key, driver, recorddriver, numdrivers, count, outputfreq, bin;
    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;
    }

    /* 
        System initialization
    */
    printf("---------------------------------------------------------\n");    
    printf("Select OUTPUT type\n");    
    printf("---------------------------------------------------------\n");    
    printf("1 :  OSS        - Open Sound System\n");
    printf("2 :  ALSA       - Advanced Linux Sound Architecture\n");
    printf("3 :  ESD        - Enlightenment Sound Daemon\n");
    printf("4 :  PULSEAUDIO - Pulse Audio Sound Server\n");
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = getch();
    } while (key != 27 && key < '1' && key > '5');
    
    switch (key)
    {
        case '1' :  result = system->setOutput(FMOD_OUTPUTTYPE_OSS);
                    break;
        case '2' :  result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
                    break;
        case '3' :  result = system->setOutput(FMOD_OUTPUTTYPE_ESD);
                    break;
        case '4' :  result = system->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
                    break;                   
        default  :  return 1; 
    }  
    ERRCHECK(result);
    
    /*
        Enumerate playback devices
    */

    result = system->getNumDrivers(&numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a PLAYBACK driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = system->getDriverInfo(count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = getch();
        if (key == 27)
        {
            return 0;
        }
        driver = key - '1';
    } while (driver < 0 || driver >= numdrivers);

    result = system->setDriver(driver);
    ERRCHECK(result);

    /*
        Enumerate record devices
    */

    result = system->getRecordNumDrivers(&numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a RECORD driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = system->getRecordDriverInfo(count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    recorddriver = 0;
    do
    {
        key = getch();
        if (key == 27)
        {
            return 0;
        }
        recorddriver = key - '1';
    } while (recorddriver < 0 || recorddriver >= numdrivers);

    printf("\n");
 
    result = system->setSoftwareFormat(OUTPUTRATE, FMOD_SOUND_FORMAT_PCM16, 1, 0, FMOD_DSP_RESAMPLER_LINEAR);
    ERRCHECK(result);

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

    system->getSoftwareFormat(&outputfreq, 0, 0, 0, 0, 0);
    ERRCHECK(result);

    /*
        Create a sound to record to.
    */
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 1;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = OUTPUTRATE;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
    
    result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    /*
        Start the interface
    */
    printf("=========================================================================\n");
    printf("Pitch detection example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("=========================================================================\n");
    printf("\n");
    printf("Record something through the selected recording device and FMOD will\n");
    printf("Determine the pitch.  Sustain the tone for at least a second to get an\n");
    printf("accurate reading.\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    result = system->recordStart(recorddriver, sound, true);
    ERRCHECK(result);
    
    Sleep(200);      /* Give it some time to record something */
    
    result = system->playSound(FMOD_CHANNEL_REUSE, sound, false, &channel);
    ERRCHECK(result);

    /* Dont hear what is being recorded otherwise it will feedback.  Spectrum analysis is done before volume scaling in the DSP chain */
    result = channel->setVolume(0);
    ERRCHECK(result);

    bin = 0;

    /*
        Main loop.
    */
    do
    {
        static float spectrum[SPECTRUMSIZE];
        float        dominanthz = 0;
        float        max;
        int          dominantnote = 0;
        float        binsize = BINSIZE;

        if (kbhit())
        {
            key = getch();
        }

        result = channel->getSpectrum(spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE);
        ERRCHECK(result);

        max = 0;

        for (count = 0; count < SPECTRUMSIZE; count++)
        {
            if (spectrum[count] > 0.01f && spectrum[count] > max)
            {
                max = spectrum[count];
                bin = count;
            }
        }        

        dominanthz  = (float)bin * BINSIZE;       /* dominant frequency min */

        dominantnote = 0;
        for (count = 0; count < 120; count++)
        {
             if (dominanthz >= notefreq[count] && dominanthz < notefreq[count + 1])
             {
                /* which is it closer to.  This note or the next note */
                if (fabs(dominanthz - notefreq[count]) < fabs(dominanthz - notefreq[count+1]))
                {
                    dominantnote = count;
                }
                else
                {
                    dominantnote = count + 1;
                }
                break;
             }
        }

        printf("Detected rate : %7.1f -> %7.1f hz.  Detected musical note. %-3s (%7.1f hz)\r", dominanthz, ((float)bin + 0.99f) * BINSIZE, note[dominantnote], notefreq[dominantnote]);
        fflush(stdout);

        system->update();

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

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

    return 0;
}
Ejemplo n.º 26
0
int FMOD_Main()
{
    FMOD::System           *system;
    FMOD::Sound            *sound[3];
    FMOD::Channel          *channel = 0;
    FMOD::ChannelGroup     *channelgroup = 0;
    FMOD_RESULT             result;
    unsigned int            version, dsp_block_len, count;
    int                     outputrate = 0;
    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(100, FMOD_INIT_NORMAL, extradriverdata);
    ERRCHECK(result);

    /*
        Get information needed later for scheduling.  The mixer block size, and the output rate of the mixer.
    */
    result = system->getDSPBufferSize(&dsp_block_len, 0);
    ERRCHECK(result);

    result = system->getSoftwareFormat(&outputrate, 0, 0);
    ERRCHECK(result);

    /*
        Load 3 sounds - these are just sine wave tones at different frequencies.  C, D and E on the musical scale.
    */
    result = system->createSound(Common_MediaPath("c.ogg"), FMOD_DEFAULT, 0, &sound[NOTE_C]);
    ERRCHECK(result);
    result = system->createSound(Common_MediaPath("d.ogg"), FMOD_DEFAULT, 0, &sound[NOTE_D]);
    ERRCHECK(result);
    result = system->createSound(Common_MediaPath("e.ogg"), FMOD_DEFAULT, 0, &sound[NOTE_E]);
    ERRCHECK(result);

    /* 
        Create a channelgroup that the channels will play on.  We can use this channelgroup as our clock reference. 
        It also means we can pause and pitch bend the channelgroup, without affecting the offsets of the delays, because the channelgroup clock
        which the channels feed off, will be pausing and speeding up/slowing down and still keeping the children in sync.
    */
    result = system->createChannelGroup("Parent", &channelgroup);
    ERRCHECK(result);

    unsigned int numsounds = sizeof(note) / sizeof(note[0]);

    /*
        Play all the sounds at once! Space them apart with set delay though so that they sound like they play in order.
    */
    for (count = 0; count < numsounds; count++)
    {
        static unsigned long long clock_start = 0;
        unsigned int slen;
        FMOD::Sound *s = sound[note[count]];                            /* Pick a note from our tune. */

        result = system->playSound(s, channelgroup, true, &channel);    /* Play the sound on the channelgroup we want to use as the parent clock reference (for setDelay further down) */
        ERRCHECK(result);

        if (!clock_start)
        {
            result = channel->getDSPClock(0, &clock_start);
            ERRCHECK(result);

            clock_start += (dsp_block_len * 2);                         /* Start the sound into the future, by 2 mixer blocks worth. */
                                                                        /* Should be enough to avoid the mixer catching up and hitting the clock value before we've finished setting up everything. */
                                                                        /* Alternatively the channelgroup we're basing the clock on could be paused to stop it ticking. */
        }
        else
        {
            float freq;

            result = s->getLength(&slen, FMOD_TIMEUNIT_PCM);            /* Get the length of the sound in samples. */
            ERRCHECK(result);

            result = s->getDefaults(&freq, 0);                          /* Get the default frequency that the sound was recorded at. */
            ERRCHECK(result);

            slen = (unsigned int)((float)slen / freq * outputrate);     /* Convert the length of the sound to 'output samples' for the output timeline. */
            
            clock_start += slen;                                        /* Place the sound clock start time to this value after the last one. */
        }

        result = channel->setDelay(clock_start, 0, false);              /* Schedule the channel to start in the future at the newly calculated channelgroup clock value. */
        ERRCHECK(result);

        result = channel->setPaused(false);                             /* Unpause the sound.  Note that you won't hear the sounds, they are scheduled into the future. */
        ERRCHECK(result);
    }

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

        if (Common_BtnPress(BTN_ACTION1))                               /* Pausing the channelgroup as the clock parent, will pause any scheduled sounds from continuing */
        {                                                               /* If you paused the channel, this would not stop the clock it is delayed against from ticking,  */
            bool paused;                                                /* and you'd have to recalculate the delay for the channel into the future again before it was unpaused. */
            result = channelgroup->getPaused(&paused);
            ERRCHECK(result);
            result = channelgroup->setPaused(!paused);
            ERRCHECK(result);
        }
        if (Common_BtnPress(BTN_ACTION2)) 
        {                                 
            for (count = 0; count < 50; count++)
            {
                float pitch;
                result = channelgroup->getPitch(&pitch);
                ERRCHECK(result);
                pitch += 0.01f;
                result = channelgroup->setPitch(pitch);
                ERRCHECK(result);

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

                Common_Sleep(10);
            }
        }
        if (Common_BtnPress(BTN_ACTION3)) 
        {                                 
            for (count = 0; count < 50; count++)
            {
                float pitch;
                result = channelgroup->getPitch(&pitch);
                ERRCHECK(result);

                if (pitch > 0.1f)
                {
                    pitch -= 0.01f;
                }
                result = channelgroup->setPitch(pitch);
                ERRCHECK(result);
                
                result = system->update();
                ERRCHECK(result);

                Common_Sleep(10);
            }
        }

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

        /*
            Print some information
        */
        {
            bool    playing = false;
            bool    paused = false;
            int     chansplaying;

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

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

            result = system->getChannelsPlaying(&chansplaying);
            ERRCHECK(result);

            Common_Draw("==================================================");
            Common_Draw("Gapless Playback example.");
            Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
            Common_Draw("==================================================");
            Common_Draw("");
            Common_Draw("Press %s to toggle pause", Common_BtnStr(BTN_ACTION1));
            Common_Draw("Press %s to increase pitch", Common_BtnStr(BTN_ACTION2));
            Common_Draw("Press %s to decrease pitch", Common_BtnStr(BTN_ACTION3));
            Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
            Common_Draw("");
            Common_Draw("Channels Playing %d : %s", chansplaying, paused ? "Paused " : playing ? "Playing" : "Stopped");
        }

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

    /*
        Shut down
    */
    result = sound[NOTE_C]->release();
    ERRCHECK(result);
    result = sound[NOTE_D]->release();
    ERRCHECK(result);
    result = sound[NOTE_E]->release();
    ERRCHECK(result);

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

    Common_Close();

    return 0;
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;

    memset(gCurrentTrackArtist, 0, 256);
    memset(gCurrentTrackTitle, 0, 256);
    strcpy(gOutputFileName, "output.mp3");   /* Start off like this then rename if a title tag comes along */

    printf("======================================================================\n");
    printf("RipNetStream Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("======================================================================\n\n");

    if (argc < 2)
    {
        printf("Usage:   ripnetstream <url>\n");
        return -1;
    }

    /*
        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(100, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->setStreamBufferSize(gFileBufferSize, FMOD_TIMEUNIT_RAWBYTES);
    ERRCHECK(result);

    result = system->attachFileSystem(myopen, myclose, myread, 0);
    ERRCHECK(result);

    printf("Buffering...\n\n");

    result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
    ERRCHECK(result);

    /*
        Main loop
    */
    do
    {
        static bool mute = false;

        if (sound && !channel)
        {
            result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
        }

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

            switch (key)
            {
                case ' ' :
                {
                    if (channel)
                    {
                        bool paused;
                        channel->getPaused(&paused);
                        channel->setPaused(!paused);
                    }
                    break;
                }
                case 'm' :
                case 'M' :
                {
                    if (channel)
                    {
                        channel->getMute(&mute);
                        channel->setMute(!mute);
                    }
                    break;
                }
            }
        }

        system->update();

        if (channel)
        {
            bool         playing = false;
            int          tagsupdated = 0;

            sound->getNumTags(0, &tagsupdated);

            if (tagsupdated)
            {
                printf("\n");
                printf("\n");
                for (;;)
                {
                    FMOD_TAG tag;

                    if (sound->getTag(0, -1, &tag) != FMOD_OK)
                    {
                        break;
                    }

                    if (tag.datatype == FMOD_TAGDATATYPE_STRING)
                    {
                        printf("[%-11s] %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
                        
                        sound->getFormat(&gSoundType, 0, 0, 0);
                    
                        if (!strcmp(tag.name, "ARTIST"))
                        {
                            if (strncmp(gCurrentTrackArtist, (const char *)tag.data, 256))
                            {
                                strncpy(gCurrentTrackArtist, (const char *)tag.data, 256);
                                gUpdateFileName = true;
                            }
                        }
                        if (!strcmp(tag.name, "TITLE"))
                        {
                            if (strncmp(gCurrentTrackTitle, (const char *)tag.data, 256))
                            {
                                strncpy(gCurrentTrackTitle, (const char *)tag.data, 256);
                                gUpdateFileName = true;
                            }
                        }
                    }
                }
                printf("\n");
            }

            result = channel->isPlaying(&playing);
            if (result != FMOD_OK || !playing)
            {
                sound->release();
                sound = 0;               
                channel = 0;
            }
            else
            {
                unsigned int    ms = 0, percent = 0;
                bool            paused = false;
                bool            starving = false;
                FMOD_OPENSTATE  openstate;

                result = sound->getOpenState(&openstate, &percent, &starving, 0);
                ERRCHECK(result);
        
                channel->setVolume(starving ? 0.0f : 1.0f);     /* Don't use mute because the user is setting that. */
                ERRCHECK(result);

                result = channel->getPaused(&paused);
                result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
                printf("Time %02d:%02d:%02d : (%3d%%%) %s SPACE = pause. 'm' = mute. ESC = quit.\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, percent, (openstate == FMOD_OPENSTATE_BUFFERING || starving) ? "Buffering..." : openstate == FMOD_OPENSTATE_CONNECTING ? "Connecting..." : paused ? "Paused       " : playing ? "Playing      " : "Stopped      ", percent, starving ? "STARVING" : "        ");

            }
        }

       
        if (sound)
        {
            FMOD_OPENSTATE openstate = FMOD_OPENSTATE_READY;

            sound->getOpenState(&openstate, 0, 0, 0);

            if (openstate == FMOD_OPENSTATE_ERROR)
            {
                sound->release();
                sound = 0;               
                channel = 0;
            }
        }

        if (!sound)
        {
            printf("\n");
            printf("Error occurred or stream ended.  Restarting stream..\n");
            result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
            ERRCHECK(result);
            Sleep(1000);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    return 0;
}
Ejemplo n.º 30
0
int FMOD_Main()
{
    FMOD::System       *system        = 0;
    FMOD::Sound        *sound         = 0;
    FMOD::Channel      *channel       = 0;
    FMOD::ChannelGroup *mastergroup   = 0; 
    FMOD::DSP          *dsplowpass    = 0;
    FMOD::DSP          *dsphighpass   = 0;
    FMOD::DSP          *dspecho       = 0;
    FMOD::DSP          *dspflange     = 0;
    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);

    result = system->getMasterChannelGroup(&mastergroup);
    ERRCHECK(result);

    result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_DEFAULT, 0, &sound);
    ERRCHECK(result);

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

    /*
        Create some effects to play with
    */
    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);

    /*
        Add them to the master channel group.  Each time an effect is added (to position 0) it pushes the others down the list.
    */
    result = mastergroup->addDSP(0, dsplowpass);
    ERRCHECK(result);
    result = mastergroup->addDSP(0, dsphighpass);
    ERRCHECK(result);
    result = mastergroup->addDSP(0, dspecho);
    ERRCHECK(result);
    result = mastergroup->addDSP(0, dspflange);
    ERRCHECK(result);

    /*
        By default, bypass all effects.  This means let the original signal go through without processing.
        It will sound 'dry' until effects are enabled by the user.
    */
    result = dsplowpass->setBypass(true);
    ERRCHECK(result);
    result = dsphighpass->setBypass(true);
    ERRCHECK(result);
    result = dspecho->setBypass(true);
    ERRCHECK(result);
    result = dspflange->setBypass(true);
    ERRCHECK(result);

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

        if (Common_BtnPress(BTN_MORE))
        {
            bool paused;

            result = channel->getPaused(&paused);
            ERRCHECK(result);

            paused = !paused;

            result = channel->setPaused(paused);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION1))
        {
            bool bypass;

            result = dsplowpass->getBypass(&bypass);
            ERRCHECK(result);

            bypass = !bypass;

            result = dsplowpass->setBypass(bypass);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION2))
        {
            bool bypass;

            result = dsphighpass->getBypass(&bypass);
            ERRCHECK(result);

            bypass = !bypass;

            result = dsphighpass->setBypass(bypass);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION3))
        {
            bool bypass;

            result = dspecho->getBypass(&bypass);
            ERRCHECK(result);

            bypass = !bypass;

            result = dspecho->setBypass(bypass);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION4))
        {
            bool bypass;

            result = dspflange->getBypass(&bypass);
            ERRCHECK(result);

            bypass = !bypass;

            result = dspflange->setBypass(bypass);
            ERRCHECK(result);
        }

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

        {
            bool paused = 0;
            bool dsplowpass_bypass;
            bool dsphighpass_bypass;
            bool dspecho_bypass;
            bool dspflange_bypass;

            dsplowpass   ->getBypass(&dsplowpass_bypass);
            dsphighpass  ->getBypass(&dsphighpass_bypass);
            dspecho      ->getBypass(&dspecho_bypass);
            dspflange    ->getBypass(&dspflange_bypass);

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

            Common_Draw("==================================================");
            Common_Draw("Effects Example.");
            Common_Draw("Copyright (c) Firelight Technologies 2004-2015.");
            Common_Draw("==================================================");
            Common_Draw("");
            Common_Draw("Press %s to pause/unpause sound", Common_BtnStr(BTN_MORE));
            Common_Draw("Press %s to toggle dsplowpass effect", Common_BtnStr(BTN_ACTION1));
            Common_Draw("Press %s to toggle dsphighpass effect", Common_BtnStr(BTN_ACTION2));
            Common_Draw("Press %s to toggle dspecho effect", Common_BtnStr(BTN_ACTION3));
            Common_Draw("Press %s to toggle dspflange effect", Common_BtnStr(BTN_ACTION4));
            Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
            Common_Draw("");
            Common_Draw("%s : lowpass[%c] highpass[%c] echo[%c] flange[%c]", 
                    paused              ? "Paused " : "Playing",
                    dsplowpass_bypass   ? ' ' : 'x',
                    dsphighpass_bypass  ? ' ' : 'x',
                    dspecho_bypass      ? ' ' : 'x',
                    dspflange_bypass    ? ' ' : 'x');
        }

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

    /*
        Shut down
    */
    result = mastergroup->removeDSP(dsplowpass);
    ERRCHECK(result);
    result = mastergroup->removeDSP(dsphighpass);
    ERRCHECK(result);
    result = mastergroup->removeDSP(dspecho);
    ERRCHECK(result);
    result = mastergroup->removeDSP(dspflange);
    ERRCHECK(result);
    
    result = dsplowpass->release();
    ERRCHECK(result);
    result = dsphighpass->release();
    ERRCHECK(result);
    result = dspecho->release();
    ERRCHECK(result);
    result = dspflange->release();
    ERRCHECK(result);

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

    Common_Close();

    return 0;
}