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 );
}
Example #2
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;
}
Example #3
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;
}
Example #4
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;
}
Example #5
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;
}
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;
}
Example #7
0
int main(int argc, char *argv[])
{
    FMOD::System     *system;
    FMOD::Sound      *sound1, *sound2;
    FMOD::Channel    *channel = 0;
    FMOD_RESULT       result;
    FMOD_SPEAKERMODE  speakermode;
    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;
    }

    /* 
       Choose the speaker mode selected by the Windows control panel.
    */
    result = system->getDriverCaps(0, 0, 0, &speakermode);
    ERRCHECK(result);

    result = system->setSpeakerMode(speakermode);
    ERRCHECK(result);

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

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

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

    printf("==============================================================================\n");
    printf("Multi Speaker Output Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("==============================================================================\n");
    printf("\n");
    switch (speakermode)
    {
        case FMOD_SPEAKERMODE_MONO    :
        {
            printf("Using control panel speaker mode : MONO.\n");
            printf("\n");
            printf("Note! This output mode is very limited in its capability.\n");
            printf("Most functionality of this demo is only realized with at least FMOD_SPEAKERMODE_QUAD\n");
            printf("and above.\n");
            break;
        }
        case FMOD_SPEAKERMODE_STEREO  :
        {
            printf("Using control panel speaker mode : STEREO.\n");
            printf("\n");
            printf("Note! This output mode is very limited in its capability.\n");
            printf("Most functionality of this demo is only realized with FMOD_SPEAKERMODE_QUAD\n");
            printf("and above.\n");
            break;
        }
        case FMOD_SPEAKERMODE_QUAD :
        {
            printf("Using control panel speaker mode : QUAD.\n");
            printf("Side left, side right, center and subwoofer mix will be disabled.\n");
            break;
        }
        case FMOD_SPEAKERMODE_SURROUND :
        {
            printf("Using control panel speaker mode : SURROUND.\n");
            printf("Side left, side right and subwoofer mix will be disabled.\n");
            break;
        }
        case FMOD_SPEAKERMODE_5POINT1 :
        {
            printf("Using control panel speaker mode : 5.1 surround.\n");
            printf("Side left and right mix will be disabled..\n");
            break;
        }
        case FMOD_SPEAKERMODE_7POINT1 :
        {
            printf("Using control panel speaker mode : 7.1 surround.\n");
            printf("Full capability.\n");
            break;
        }
    };
    printf("\n");

    printf("Press '1' to play a mono sound on the FRONT LEFT speaker.\n");
    printf("Press '2' to play a mono sound on the FRONT RIGHT speaker.\n");

    if (speakermode >= FMOD_SPEAKERMODE_SURROUND)
    {
        printf("Press '3' to play a mono sound on the CENTER speaker.\n");
    }
    else
    {
        printf("- CENTER Disabled\n");
    }

    if (speakermode >= FMOD_SPEAKERMODE_QUAD)
    {
        printf("Press '4' to play a mono sound on the REAR LEFT speaker.\n");
        printf("Press '5' to play a mono sound on the REAR RIGHT speaker.\n");
    }
    else
    {
        printf("- REAR LEFT Disabled\n");
        printf("- REAR RIGHT Disabled\n");
    }
    if (speakermode >= FMOD_SPEAKERMODE_7POINT1)
    {
        printf("Press '6' to play a mono sound on the SIDE LEFT speaker.\n");
        printf("Press '7' to play a mono sound on the SIDE RIGHT speaker.\n");
    }
    else
    {
        printf("- SIDE LEFT Disabled\n");
        printf("- SIDE RIGHT Disabled\n");
    }

    printf("\n");
    printf("Press '8' to play a stereo sound on the front speakers.\n");
    printf("Press '9' to play a stereo sound on the front speakers but channel swapped.\n");

    if (speakermode >= FMOD_SPEAKERMODE_SURROUND)
    {
        printf("Press '0' to play the right part of a stereo sound on the CENTER speaker.\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, true, &channel);
                    ERRCHECK(result);

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

                    result = channel->setPaused(false);
                    ERRCHECK(result);
                    break;
                }
                case '2' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                    ERRCHECK(result);

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

                    result = channel->setPaused(false);
                    ERRCHECK(result);
                    break;
                }
                case '3' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_SURROUND)   /* All formats that have a center speaker. */
                    {
                        result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                        ERRCHECK(result);

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

                        result = channel->setPaused(false);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '4' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_QUAD)
                    {
                        result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                        ERRCHECK(result);

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

                        result = channel->setPaused(false);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '5' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_QUAD)
                    {
                        result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                        ERRCHECK(result);

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

                        result = channel->setPaused(false);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '6' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_7POINT1)
                    {
                        result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                        ERRCHECK(result);

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

                        result = channel->setPaused(false);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '7' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_7POINT1)
                    {
                        result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                        ERRCHECK(result);

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

                        result = channel->setPaused(false);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '8' :
                {
                    float levels[2] = { 0, 1.0f };

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

                    /*
                        By default a stereo sound would play in all right and all left speakers, so this forces it to just the front.
                    */
                    result = channel->setSpeakerMix(1.0f, 1.0f, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

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

                    break;
                }
                case '9' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel);
                    ERRCHECK(result);

                    /*
                        Clear out all speakers first.
                    */
                    result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

                    /*
                        Put the left channel of the sound in the right speaker.
                    */
                    {
                        float levels[2] = { 0, 1.0f };    /* This array represents the source stereo sound.  l/r */

                        result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_LEFT, levels, 2);
                        ERRCHECK(result);
                    }
                    /*
                        Put the right channel of the sound in the left speaker.
                    */
                    {
                        float levels[2] = { 1.0f, 0 };    /* This array represents the source stereo sound.  l/r */

                        result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_RIGHT, levels, 2);
                        ERRCHECK(result);
                    }

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

                    break;
                }
                case '0' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_SURROUND)   /* All formats that have a center speaker. */
                    {
                        result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel);
                        ERRCHECK(result);

                        /*
                            Clear out all speakers first.
                        */
                        result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 0);
                        ERRCHECK(result);

                        /*
                            Put the left channel of the sound in the right speaker.
                        */
                        {
                            float levels[2] = { 0, 1.0f };    /* This array represents the source stereo sound.  l/r */

                            result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_CENTER, levels, 2);
                            ERRCHECK(result);
                        }

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

        system->update();

        {
            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);
                    }
                }
            }

            system->getChannelsPlaying(&channelsplaying);

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

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    return 0;
}
int FMOD_Main()
{
    FMOD::System     *system;
    FMOD::Sound      *sound1, *sound2, *sound3;
    FMOD::Channel    *channel = 0;
    FMOD_RESULT       result;
    unsigned int      version;
    void             *extradriverdata = 0;
    void             *buff = 0;
    int               length = 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(32, FMOD_INIT_NORMAL, extradriverdata);
    ERRCHECK(result);
    
    Common_LoadFileMemory(Common_MediaPath("drumloop.wav"), &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;

    result = system->createSound((const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY | FMOD_LOOP_OFF, &exinfo, &sound1);
    ERRCHECK(result);
    Common_UnloadFileMemory(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!

    Common_LoadFileMemory(Common_MediaPath("jaguar.wav"), &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;    
   
    result = system->createSound((const char *)buff, FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &sound2);
    ERRCHECK(result);
    Common_UnloadFileMemory(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!
    
    Common_LoadFileMemory(Common_MediaPath("swish.wav"), &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;    

    result = system->createSound((const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound3);
    ERRCHECK(result);
    Common_UnloadFileMemory(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!

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

        if (Common_BtnPress(BTN_ACTION1))
        {
            result = system->playSound(sound1, 0, false, &channel);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION2))
        {
            result = system->playSound(sound2, 0, false, &channel);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION3))
        {
            result = system->playSound(sound3, 0, false, &channel);
            ERRCHECK(result);
        }

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

        {
            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);

            Common_Draw("==================================================");
            Common_Draw("Load From Memory Example.");
            Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
            Common_Draw("==================================================");
            Common_Draw("");
            Common_Draw("Press %s to play a mono sound (drumloop)", Common_BtnStr(BTN_ACTION1));
            Common_Draw("Press %s to play a mono sound (jaguar)", Common_BtnStr(BTN_ACTION2));
            Common_Draw("Press %s to play a stereo sound (swish)", Common_BtnStr(BTN_ACTION3));
            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 %2d", channelsplaying);
        }

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

    /*
        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);

    Common_Close();

    return 0;
}
Example #9
0
int main(int argc, char *argv[])
{
    FMOD::System        *system;
    FMOD::Sound         *sound;
    FMOD::Channel       *channel;
    FMOD::DSP           *dsplowpass, *dspchorus, *dsphead, *dspchannelmixer;
	FMOD::DSPConnection *dsplowpassconnection, *dspchorusconnection;
    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("DSP effect per speaker example. Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===============================================================================\n");
    printf("Press 'L' to toggle lowpass on/off on left speaker only\n");
    printf("Press 'R' to toggle chorus on/off on right speaker only\n");
    printf("Press '[' to pan sound left\n");
    printf("Press ']' to pan sound right\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

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

    /*
        Create the DSP effects.
    */  
    result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
    ERRCHECK(result);

    result = system->createDSPByType(FMOD_DSP_TYPE_CHORUS, &dspchorus);
    ERRCHECK(result);

    /*
        Connect up the DSP network
    */

    /*
        When a sound is played, a subnetwork is set up in the DSP network which looks like this.
        Wavetable is the drumloop sound, and it feeds its data from right to left.

        [DSPHEAD]<------------[DSPCHANNELMIXER]
    */  
    result = system->getDSPHead(&dsphead);
    ERRCHECK(result);

    result = dsphead->getInput(0, &dspchannelmixer, 0);
    ERRCHECK(result);

    /*
        Now disconnect channeldsp head from wavetable to look like this.

        [DSPHEAD]             [DSPCHANNELMIXER]
    */
    result = dsphead->disconnectFrom(dspchannelmixer);
    ERRCHECK(result);

    /*
        Now connect the 2 effects to channeldsp head.  
		Store the 2 connections this makes so we can set their speakerlevels later.

                  [DSPLOWPASS]
                 /x           
        [DSPHEAD]             [DSPCHANNELMIXER]
                 \y           
                  [DSPCHORUS]
    */
    result = dsphead->addInput(dsplowpass, &dsplowpassconnection);  /* x = dsplowpassconnection */
    ERRCHECK(result);
    result = dsphead->addInput(dspchorus, &dspchorusconnection);    /* y = dspchorusconnection */
    ERRCHECK(result);
    
    /*
        Now connect the wavetable to the 2 effects

                  [DSPLOWPASS]
                 /x          \
        [DSPHEAD]             [DSPCHANNELMIXER]
                 \y          /
                  [DSPCHORUS]
    */
    result = dsplowpass->addInput(dspchannelmixer, 0);  /* Null for connection - we dont care about it. */
    ERRCHECK(result);
    result = dspchorus->addInput(dspchannelmixer, 0);   /* Null for connection - we dont care about it. */
    ERRCHECK(result);

    /*
        Now the drumloop will be twice as loud, because it is being split into 2, then recombined at the end.
        What we really want is to only feed the dspchannelmixer->dsplowpass through the left speaker, and 
        dspchannelmixer->dspchorus to the right speaker.
        We can do that simply by setting the pan, or speaker levels of the connections.

                  [DSPLOWPASS]
                 /x=1,0      \
        [DSPHEAD]             [DSPCHANNELMIXER]
                 \y=0,1      /
                  [DSPCHORUS]
    */
    {
        float leftinputon[2]  = { 1.0f, 0.0f };
        float rightinputon[2] = { 0.0f, 1.0f };
        float inputsoff[2]    = { 0.0f, 0.0f };

        result = dsplowpassconnection->setLevels(FMOD_SPEAKER_FRONT_LEFT, leftinputon, 2);
        ERRCHECK(result);
        result = dsplowpassconnection->setLevels(FMOD_SPEAKER_FRONT_RIGHT, inputsoff, 2);
        ERRCHECK(result);

        result = dspchorusconnection->setLevels(FMOD_SPEAKER_FRONT_LEFT, inputsoff, 2);
        ERRCHECK(result);
        result = dspchorusconnection->setLevels(FMOD_SPEAKER_FRONT_RIGHT, rightinputon, 2);
        ERRCHECK(result);
    }

    result = dsplowpass->setBypass(true);
    result = dspchorus->setBypass(true);

    result = dsplowpass->setActive(true);
    result = dspchorus->setActive(true);

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

            switch (key)
            {
                case 'l' : 
                case 'L' : 
                {
                    static bool lowpass = false;

                    dsplowpass->setBypass(lowpass);

                    lowpass = !lowpass;
                    break;
                }
                case 'r' : 
                case 'R' : 
                {
                    static bool chorus = false;

                    dspchorus->setBypass(chorus);

                    chorus = !chorus;
                    break;
                }
                case '[' :
                {
                    channel->getPan(&pan);
                    pan -= 0.1f;
                    if (pan < -1)
                    {
                        pan = -1;
                    }
                    channel->setPan(pan);
                    break;
                }
                case ']' :
                {
                    channel->getPan(&pan);
                    pan += 0.1f;
                    if (pan > 1)
                    {
                        pan = 1;
                    }
                    channel->setPan(pan);
                    break;
                }
            }
        }

        system->update();

        {
            int  channelsplaying = 0;

            system->getChannelsPlaying(&channelsplaying);

            printf("Channels Playing %2d : Pan = %.02f\r", channelsplaying, pan);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    result = dsplowpass->release();
    ERRCHECK(result);
    result = dspchorus->release();
    ERRCHECK(result);

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

    return 0;
}
Example #10
0
int main(int argc, char *argv[])
{
    FMOD::System     *system;
    FMOD::Sound      *fsb;
    FMOD::Channel    *channel = 0;
    FMOD_RESULT       result;
    int               key, count, numsubsounds;
    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/example.fsb", FMOD_DEFAULT, 0, &fsb);
    ERRCHECK(result);

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

    result = fsb->getNumSubSounds(&numsubsounds);
    ERRCHECK(result);

    for (count = 0; count < numsubsounds; count++)
    {
        FMOD::Sound *subsound;
        char name[256];

        result = fsb->getSubSound(count, &subsound);
        ERRCHECK(result);

        result = subsound->getName(name, 256);
        ERRCHECK(result);

        printf("Press '%c' to play \"%s\"\n", '1' + count, name);
    }
    printf("Press 'Esc' to quit\n");
    printf("\n");

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

            if (key >= '1' && key < '1' + numsubsounds)
            {
                FMOD::Sound *subsound;
                int index = key - '1';

                fsb->getSubSound(index, &subsound);
               
                result = system->playSound(FMOD_CHANNEL_FREE, subsound, false, &channel);
                ERRCHECK(result);
            }
        }

        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("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    return 0;
}
Example #11
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;
    void             *buff = 0;
    int               length = 0;
    FMOD_CREATESOUNDEXINFO exinfo;

    /*
        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);

    LoadFileIntoMemory("../media/drumloop.wav", &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;

    result = system->createSound((const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound1);
    ERRCHECK(result);
    
    result = sound1->setMode(FMOD_LOOP_OFF);
    ERRCHECK(result);   

    free(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!
     
    LoadFileIntoMemory("../media/jaguar.wav", &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;    
   
    result = system->createSound((const char *)buff, FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &sound2);
    ERRCHECK(result);

    free(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!
    
    LoadFileIntoMemory("../media/swish.wav", &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;    

    result = system->createSound((const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound3);
    ERRCHECK(result);

    free(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!

    printf("==========================================================================\n");
    printf("Load from memory example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("==========================================================================\n");
    printf("\n");
    printf("Press '1' to play a mono sound using hardware mixing\n");
    printf("Press '2' to play a mono sound using software mixing\n");
    printf("Press '3' to play a stereo sound using hardware 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, false, &channel);
                    ERRCHECK(result);
                    break;
                }
                case '2' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound2, false, &channel);
                    ERRCHECK(result);
                    break;
                }
                case '3' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &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("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
        }

        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;
}
Example #12
0
int main(int argc, char *argv[])
{
    FMOD::System     *system  = 0;
    FMOD::Sound      *sound   = 0;
    FMOD::Channel    *channel = 0;
    FMOD_RESULT       result;
    int               count;
    bool              playing = false;
    int               key, numoutputplugins;
    unsigned int      version;
    unsigned int      handle;

    /*
        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;
    }

    /*
        Set the source directory for all of the FMOD plugins.
    */
#ifdef _WIN64
    result = system->setPluginPath("../../api/plugins/64bit");
#else    
    result = system->setPluginPath("../../api/plugins");
#endif    
    ERRCHECK(result);

    /*
        Load up an extra plugin that is not normally used by FMOD.
    */
#ifdef _WIN64
    result = system->loadPlugin("output_mp364.dll", 0, 0);
#else
    result = system->loadPlugin("output_mp3.dll", 0, 0);
#endif    
    if (result == FMOD_ERR_FILE_NOTFOUND)
    {
        /*
            If it isn't in the same directory, try for the plugin directory.
        */
#ifdef _WIN64
        result = system->loadPlugin("../plugin_dev/output_mp3/output_mp364.dll", 0, 0);
#else
        result = system->loadPlugin("../plugin_dev/output_mp3/output_mp3.dll", 0, 0);
#endif        
        ERRCHECK(result);
    }


    /*
        Display plugins
    */
    {
        int num;
        char name[256];

        printf("Codec plugins\n");
        printf("--------------\n");
        result = system->getNumPlugins(FMOD_PLUGINTYPE_CODEC, &num);
        ERRCHECK(result);
        for (count = 0; count < num; count++)
        {
            result = system->getPluginHandle(FMOD_PLUGINTYPE_CODEC, count, &handle);
            ERRCHECK(result);

            result = system->getPluginInfo(handle, 0, name, 256, 0);
            ERRCHECK(result);

            printf("%2d - %-30s", count + 1, name);

            if (count % 2)
            {
                printf("\n");
            }
        }
        printf("\n");
        if (count % 2)
        {
            printf("\n");
        }

        printf("DSP plugins\n");
        printf("--------------\n");
        result = system->getNumPlugins(FMOD_PLUGINTYPE_DSP, &num);
        ERRCHECK(result);
        for (count = 0; count < num; count++)
        {
            result = system->getPluginHandle(FMOD_PLUGINTYPE_DSP, count, &handle);
            ERRCHECK(result);

            result = system->getPluginInfo(handle, 0, name, 256, 0);
            ERRCHECK(result);

            printf("%2d - %-30s", count + 1, name);

            if (count % 2)
            {
                printf("\n");
            }
        }
        printf("\n");
        if (count % 2)
        {
            printf("\n");
        }

        printf("Output plugins\n");
        printf("--------------\n");
        result = system->getNumPlugins(FMOD_PLUGINTYPE_OUTPUT, &numoutputplugins);
        ERRCHECK(result);
        for (count = 0; count < numoutputplugins; count++)
        {
            result = system->getPluginHandle(FMOD_PLUGINTYPE_OUTPUT, count, &handle);
            ERRCHECK(result);

            result = system->getPluginInfo(handle, 0, name, 256, 0);
            ERRCHECK(result);

            printf("%2d - %-30s", count + 1, name);

            if (count % 2)
            {
                printf("\n");
            }
        }
        if (count % 2)
        {
            printf("\n");
        }
    }

    /*
        System initialization
    */
    printf("-----------------------------------------------------------------------\n");    // print driver names
    printf("Press a corresponding number for an OUTPUT PLUGIN to use or ESC to quit\n");

    do
    {
        key = _getch();
    } while (key != 27 && key < '1' && key > '0' + numoutputplugins);
    if (key == 27)
    {
        return 0;
    }
    
    result = system->getPluginHandle(FMOD_PLUGINTYPE_OUTPUT, key - '1', &handle);
    ERRCHECK(result);

    result = system->setOutputByPlugin(handle);
    ERRCHECK(result);

    int drivers;
    result = system->getNumDrivers(&drivers);
    ERRCHECK(result);

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

    result = system->createSound("../media/wave.mp3", FMOD_SOFTWARE | FMOD_CREATESTREAM, 0, &sound);
    ERRCHECK(result);

    printf("Press a key to play sound to output device.\n");

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

    /*
        Main loop.
    */
    do
    {
        unsigned int ms = 0;
        unsigned int lenms = 0;
        bool         paused = false;
        int          channelsplaying = 0;
        FMOD::Sound *currentsound = 0;

        system->update();

        playing = false;

        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("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);

        Sleep(5);

        if (_kbhit())
        {
            key = _getch();
            if (key == 27)
            {
                break;
            }
        }

    } while (playing);

    printf("\n");

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

    return 0;
}
int FMOD_Main()
{
    FMOD::System       *system;
    FMOD::Sound        *sound[6];
    FMOD::Channel      *channel[6];
    FMOD::ChannelGroup *groupA, *groupB, *masterGroup;
    FMOD_RESULT         result;
    int                 count;
    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_LOOP_NORMAL, 0, &sound[0]);
    ERRCHECK(result);
    result = system->createSound(Common_MediaPath("jaguar.wav"), FMOD_LOOP_NORMAL, 0, &sound[1]);
    ERRCHECK(result);
    result = system->createSound(Common_MediaPath("swish.wav"), FMOD_LOOP_NORMAL, 0, &sound[2]);
    ERRCHECK(result);
    result = system->createSound(Common_MediaPath("c.ogg"), FMOD_LOOP_NORMAL, 0, &sound[3]);
    ERRCHECK(result);
    result = system->createSound(Common_MediaPath("d.ogg"), FMOD_LOOP_NORMAL, 0, &sound[4]);
    ERRCHECK(result);
    result = system->createSound(Common_MediaPath("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);

    /*
        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(sound[count], 0, true, &channel[count]);
        ERRCHECK(result);
        
        result = channel[count]->setChannelGroup((count < 3) ? groupA : groupB);
        ERRCHECK(result);
        
        result = channel[count]->setPaused(false);
        ERRCHECK(result);
    }   

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

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

        if (Common_BtnPress(BTN_ACTION1))
        {
            bool mute = true;
            groupA->getMute(&mute);
            groupA->setMute(!mute);
        }

        if (Common_BtnPress(BTN_ACTION2))
        {
            bool mute = true;
            groupB->getMute(&mute);
            groupB->setMute(!mute);
        }

        if (Common_BtnPress(BTN_ACTION3))
        {
            bool mute = true;
            masterGroup->getMute(&mute);
            masterGroup->setMute(!mute);
        }

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

        {
            int channelsplaying = 0;

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

            Common_Draw("==================================================");
            Common_Draw("Channel Groups Example.");
            Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
            Common_Draw("==================================================");
            Common_Draw("");
            Common_Draw("Group A : drumloop.wav, jaguar.wav, swish.wav");
            Common_Draw("Group B : c.ogg, d.ogg, e.ogg");
            Common_Draw("");
            Common_Draw("Press %s to mute/unmute group A", Common_BtnStr(BTN_ACTION1));
            Common_Draw("Press %s to mute/unmute group B", Common_BtnStr(BTN_ACTION2));
            Common_Draw("Press %s to mute/unmute master group", Common_BtnStr(BTN_ACTION3));
            Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
            Common_Draw("");
            Common_Draw("Channels playing %d", channelsplaying);
        }

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


    /*
        A little fade out over 2 seconds.
    */
    {
        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);

            Common_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);

    Common_Close();

    return 0;
}
Example #14
0
int main(int argc, char *argv[])
{
    FMOD::System       *system;
    FMOD::Sound        *sound[5];
    FMOD::Channel      *channel[5];
    FMOD::ChannelGroup *groupA, *groupB, *masterGroup;
    FMOD::DSP          *dspreverb, *dspflange, *dsplowpass;
    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_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[0]);
    ERRCHECK(result);
    result = system->createSound("../media/jaguar.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[1]);
    ERRCHECK(result);
    result = system->createSound("../media/c.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[2]);
    ERRCHECK(result);
    result = system->createSound("../media/d.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[3]);
    ERRCHECK(result);
    result = system->createSound("../media/e.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[4]);
    ERRCHECK(result);

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

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

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

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

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

    printf("======================================================================\n");
    printf("Sub-mixing example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("======================================================================\n");
    printf("                                                       (drumloop.wav) \n");
    printf("                                                      /               \n");
    printf("                                              (groupA)                \n");
    printf("                                     (reverb)/        \\               \n");
    printf("                                    /                  (jaguar.wav)   \n");
    printf("(soundcard)--(lowpass)--(mastergroup)                                  \n");
    printf("                                    \\                  (c.ogg)        \n");
    printf("                                     (flange)         /                \n");
    printf("                                             \\(groupB)--(d.ogg)       \n");
    printf("                                                      \\               \n");
    printf("                                                       (e.ogg)        \n");
    printf("Press 'A' to mute/unmute group A\n");
    printf("Press 'B' to mute/unmute group B\n");
    printf("\n");
    printf("Press 'R' to place reverb on group A\n");
    printf("Press 'F' to place flange on group B\n");
    printf("Press 'L' to place lowpass on master group (everything)\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

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

    /*
        Create the DSP effects we want to apply to our submixes.
    */
    result = system->createDSPByType(FMOD_DSP_TYPE_SFXREVERB, &dspreverb);
    ERRCHECK(result);

    result = system->createDSPByType(FMOD_DSP_TYPE_FLANGE, &dspflange);
    ERRCHECK(result);
    result = dspflange->setParameter(FMOD_DSP_FLANGE_RATE, 1.0f);
    ERRCHECK(result);

    result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
    ERRCHECK(result);
    result = dsplowpass->setParameter(FMOD_DSP_LOWPASS_CUTOFF, 500.0f);
    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 'r' :
            case 'R' :
            {
                static bool reverb = true;

                if (reverb)
                {
                    groupA->addDSP(dspreverb, 0);
                }
                else
                {
                    dspreverb->remove();
                }

                reverb = !reverb;
                break;
            }
            case 'f' :
            case 'F' :
            {
                static bool flange = true;

                if (flange)
                {
                    groupB->addDSP(dspflange, 0);
                }
                else
                {
                    dspflange->remove();
                }

                flange = !flange;
                break;
            }
            case 'l' :
            case 'L' :
            {
                static bool lowpass = true;

                if (lowpass)
                {
                    masterGroup->addDSP(dsplowpass, 0);
                }
                else
                {
                    dsplowpass->remove();
                }

                lowpass = !lowpass;
                break;
            }
            }
        }

        system->update();

        {
            int  channelsplaying = 0;

            system->getChannelsPlaying(&channelsplaying);

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

        fflush(stdout);
        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    result = dspreverb->release();
    ERRCHECK(result);
    result = dspflange->release();
    ERRCHECK(result);
    result = dsplowpass->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;
}
Example #15
0
int main(int argc, char *argv[])
{
    FMOD::System     *system;
    FMOD::Sound      *sound1, *sound2;
    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);
        getch();
        return 0;
    }

    /*
        Multichannel only supported in ALSA mode in 5.1 and 7.1.
        If the user doesn't have 5.1 speakers then only the speakers
        they have will be audible.
    */

    result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
    ERRCHECK(result);

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

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


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

    printf("==============================================================================\n");
    printf("Multi Speaker Output Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("==============================================================================\n");
    printf("\n");
    printf("Note!  You must have your speaker configuration set up correctly\n");
    printf("       in the windows control panel for this to work properly.\n");
    printf("\n");
    printf("Press '1' to play a mono sound on the FRONT LEFT speaker.\n");
    printf("Press '2' to play a mono sound on the FRONT RIGHT speaker.\n");
    printf("Press '3' to play a mono sound on the CENTER speaker.\n");
    printf("Press '4' to play a mono sound on the REAR LEFT speaker.\n");
    printf("Press '5' to play a mono sound on the REAR RIGHT speaker.\n");
    printf("Press '6' to play a mono sound on the SIDE LEFT speaker.\n");
    printf("Press '7' to play a mono sound on the SIDE RIGHT speaker.\n");
    printf("Press '8' to play a stereo sound on the front speakers.\n");
    printf("Press '9' to play a stereo sound on the front speakers but channel swapped.\n");
    printf("Press '0' to play the right part of a stereo sound on the CENTER speaker.\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, true, &channel);
                    ERRCHECK(result);

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

                    result = channel->setPaused(false);
                    ERRCHECK(result);
                    break;
                }
                case '2' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                    ERRCHECK(result);

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

                    result = channel->setPaused(false);
                    ERRCHECK(result);
                    break;
                }
                case '3' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                    ERRCHECK(result);

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

                    result = channel->setPaused(false);
                    ERRCHECK(result);
                    break;
                }
                case '4' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                    ERRCHECK(result);

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

                    result = channel->setPaused(false);
                    ERRCHECK(result);
                    break;
                }
                case '5' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                    ERRCHECK(result);

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

                    result = channel->setPaused(false);
                    ERRCHECK(result);
                    break;
                }
                case '6' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                    ERRCHECK(result);

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

                    result = channel->setPaused(false);
                    ERRCHECK(result);
                    break;
                }
                case '7' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
                    ERRCHECK(result);

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

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

                    break;
                }
                case '8' :
                {
                    float levels[2] = { 0, 1.0f };

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

                    /*
                        By default a stereo sound would play in all right and all left speakers, so this forces it to just the front.
                    */
                    result = channel->setSpeakerMix(1.0f, 1.0f, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

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

                    break;
                }
                case '9' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel);
                    ERRCHECK(result);

                    /*
                        Clear out all speakers first.
                    */
                    result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

                    /*
                        Put the left channel of the sound in the right speaker.
                    */
                    {
                        float levels[2] = { 0, 1.0f };    /* This array represents the source stereo sound.  l/r */

                        result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_LEFT, levels, 2);
                        ERRCHECK(result);
                    }
                    /*
                        Put the right channel of the sound in the left speaker.
                    */
                    {
                        float levels[2] = { 1.0f, 0 };    /* This array represents the source stereo sound.  l/r */

                        result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_RIGHT, levels, 2);
                        ERRCHECK(result);
                    }

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

                    break;
                }
                case '0' :
                {
                    result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel);
                    ERRCHECK(result);

                    /*
                        Clear out all speakers first.
                    */
                    result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

                    /*
                        Put the left channel of the sound in the right speaker.
                    */
                    {
                        float levels[2] = { 0, 1.0f };    /* This array represents the source stereo sound.  l/r */

                        result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_CENTER, levels, 2);
                        ERRCHECK(result);
                    }

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

                    break;
                }
            }
        }

        system->update();

        {
            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);
                    }
                }
            }

            system->getChannelsPlaying(&channelsplaying);

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

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    return 0;
}