// ---------------------------------------------------------------------------- void ofxSoundPlayerFMOD::play() { // if it's a looping sound, we should try to kill it, no? // or else people will have orphan channels that are looping if (bLoop == true){ FMOD_Channel_Stop(channel); } // if the sound is not set to multiplay, then stop the current, // before we start another if (!bMultiPlay){ FMOD_Channel_Stop(channel); } FMOD_System_PlaySound(sys, FMOD_CHANNEL_FREE, sound, bPaused, &channel); FMOD_Channel_GetFrequency(channel, &internalFreq); FMOD_Channel_SetVolume(channel,volume); FMOD_Channel_SetPan(channel,pan); FMOD_Channel_SetFrequency(channel, internalFreq * speed); FMOD_Channel_SetMode(channel, (bLoop == true) ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF); //fmod update() should be called every frame - according to the docs. //we have been using fmod without calling it at all which resulted in channels not being able //to be reused. we should have some sort of global update function but putting it here //solves the channel bug FMOD_System_Update(sys); }
//------------------------------------------------------------ void ofFmodSoundPlayer::setPan(float p){ pan = p; p = ofClamp(p, -1, 1); if (isPlaying()){ FMOD_Channel_SetPan(channel,p); } }
// ---------------------------------------------------------------------------- void ofxSoundPlayerFMOD::setPan(float p) { if (getIsPlaying() == true){ FMOD_Channel_SetPan(channel,p); } pan = p; }
INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority) { FMOD_SOUND *sound; FMOD_CHANNEL *chan; INT32 i; float frequency; sound = (FMOD_SOUND *)S_sfx[id].data; I_Assert(sound != NULL); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, sound, true, &chan)); if (sep == 0) sep = 1; FMR(FMOD_Channel_SetVolume(chan, (vol / 255.0) * (sfx_volume / 31.0))); FMR(FMOD_Channel_SetPan(chan, (sep - 128) / 127.0)); FMR(FMOD_Sound_GetDefaults(sound, &frequency, NULL, NULL, NULL)); FMR(FMOD_Channel_SetFrequency(chan, (pitch / 128.0) * frequency)); FMR(FMOD_Channel_SetPriority(chan, priority)); //UNREFERENCED_PARAMETER(priority); //FMR(FMOD_Channel_SetPriority(chan, 1 + ((0xff-vol)>>1))); // automatic priority 1 - 128 based on volume (priority 0 is music) FMR(FMOD_Channel_GetIndex(chan, &i)); FMR(FMOD_Channel_SetPaused(chan, false)); return i; }
void AudioManager::Play( const AudioManager::AudioType Type, const string& ID, const float Volume, const float Pitch, const float Pan, const int32_t LoopCount, const int32_t Priority, const FMOD_CHANNELINDEX ChannelIndex ) { // Create local variables. float Frequency = Null; FMOD_CHANNEL* Channel = nullptr; unordered_map< string, SoundData >::iterator AudioMapIterator; // Check arguments. if( Type == MaxAudioTypes ) throw exception(); // Playback specified audio sample or stream. if( Initialized ) { AudioMapIterator = AudioMaps[ Type ].Instance.find( ID ); if( AudioMapIterator == AudioMaps[ Type ].Instance.end() ) throw exception(); if( FMOD_System_PlaySound( SystemInstance, ChannelIndex, AudioMapIterator->second.Instance, true, &Channel ) != FMOD_OK ) throw exception(); if( FMOD_Channel_SetChannelGroup( Channel, AudioMapIterator->second.Group ) != FMOD_OK ) throw exception(); if( FMOD_Channel_SetLoopCount( Channel, LoopCount ) != FMOD_OK ) throw exception(); if( FMOD_Channel_SetPriority( Channel, Priority ) != FMOD_OK ) throw exception(); if( FMOD_Channel_SetPan( Channel, Pan ) != FMOD_OK ) throw exception(); if( FMOD_Channel_GetFrequency( Channel, &Frequency ) != FMOD_OK ) throw exception(); if( FMOD_Channel_SetFrequency( Channel, ( Frequency * Pitch ) ) != FMOD_OK ) throw exception(); if( FMOD_Channel_SetVolume( Channel, Volume ) != FMOD_OK ) throw exception(); if( FMOD_Channel_SetPaused( Channel, false ) != FMOD_OK ) throw exception(); } }
void PlayStereoFrequency( short player, short which, short freq ) { if( soundOn ) { float oldFreq; FMOD_System_PlaySound( fmodSystem, FMOD_CHANNEL_FREE, sound[which], true, &soundChannel[player] ); // SetPan pans the sound from -1 (full left) to 1 (full right). // which means player 0 should be -1 and player 1 should be 1. // Except hard panning sounds kind of bad so player 0 should be // -0.75 and player 1 should be 0.75. if( playerWindowVisible[1] ) { FMOD_Channel_SetPan( soundChannel[player], -0.75f + 1.5f * player ); } else { FMOD_Channel_SetPan( soundChannel[player], 0.0f ); } FMOD_Channel_GetFrequency( soundChannel[player], &oldFreq ); FMOD_Channel_SetFrequency( soundChannel[player], oldFreq * (16 + freq)/ 16 ); FMOD_Channel_SetPaused( soundChannel[player], false ); } }
void sound_play(eSound snd, float vol, float pan, float freq) { static Sound* s; if (!s) s = &((Data*)SDLazy_GetData())->sound; FMOD_System_PlaySound(s->system, FMOD_CHANNEL_FREE, s->mp3[snd], 0, &s->chan); FMOD_Channel_SetVolume(s->chan, vol); FMOD_Channel_SetPan(s->chan, pan); FMOD_Channel_SetFrequency(s->chan, freq); FMOD_System_Update(s->system); }
// seems to never be called on an invalid channel (calls I_SoundIsPlaying first?) // so I'm not gonna worry about it. void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch) { FMOD_CHANNEL *chan; FMOD_SOUND *sound; float frequency; FMR(FMOD_System_GetChannel(fsys, handle, &chan)); FMR(FMOD_Channel_SetVolume(chan, (vol / 255.0) * (sfx_volume / 31.0))); FMR(FMOD_Channel_SetPan(chan, (sep - 128) / 127.0)); FMR(FMOD_Channel_GetCurrentSound(chan, &sound)); FMR(FMOD_Sound_GetDefaults(sound, &frequency, NULL, NULL, NULL)); FMR(FMOD_Channel_SetFrequency(chan, (pitch / 128.0) * frequency)); //FMR(FMOD_Channel_SetPriority(chan, 1 + ((0xff-vol)>>1))); // automatic priority 1 - 128 based on volume (priority 0 is music) }
// ---------------------------------------------------------------------------- void ofSoundPlayer::play(){ // if it's a looping sound, we should try to kill it, no? // or else people will have orphan channels that are looping if (bLoop == true){ FMOD_Channel_Stop(channel); } // if the sound is not set to multiplay, then stop the current, // before we start another if (!bMultiPlay){ FMOD_Channel_Stop(channel); } FMOD_System_PlaySound(sys, FMOD_CHANNEL_FREE, sound, bPaused, &channel); FMOD_Channel_GetFrequency(channel, &internalFreq); FMOD_Channel_SetVolume(channel,volume); FMOD_Channel_SetPan(channel,pan); FMOD_Channel_SetFrequency(channel, internalFreq * speed); FMOD_Channel_SetMode(channel, (bLoop == true) ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF); }
void update_sound(void) { int i; int vol, pan; if(!sound_is_on)return; for(i=0;i<MAX_SOUNDS_PLAYING;i++) { if(sound_data[i].used) { FMOD_BOOL is_playing; FMOD_Channel_IsPlaying(sound_data[i].voice_num, &is_playing); if(is_playing==FALSE) { FMOD_Channel_Stop(sound_data[i].voice_num); sound_data[i].used=0; } else { if(!sound_data[i].lower_at_dist) { vol = sound_data[i].vol; pan = 128; } else calc_sound_prop(sound_data[i].x,sound_data[i].y,&vol, &pan, sound_info[sound_data[i].sound_num].volume); FMOD_Channel_SetVolume(sound_data[i].voice_num, ((float)vol)/256); FMOD_Channel_SetPan(sound_data[i].voice_num, pan); } } } }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_CHANNEL *channel; FMOD_DSP *dspreverb, *dspchorus, *dsphead, *dspchannelmixer; 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 = FMOD_System_GetVersion(system, &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 = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = FMOD_System_CreateSound(system, "../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-2005.\n"); printf("===============================================================================\n"); printf("Press 'L' to toggle reverb 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 = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel); ERRCHECK(result); /* Create the DSP effects. */ result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_REVERB, &dspreverb); ERRCHECK(result); result = FMOD_System_CreateDSPByType(system, 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 = FMOD_System_GetDSPHead(system, &dsphead); ERRCHECK(result); result = FMOD_DSP_GetInput(dsphead, 0, &dspchannelmixer); ERRCHECK(result); /* Now disconnect channeldsp head from wavetable to look like this. [DSPHEAD] [DSPCHANNELMIXER] */ result = FMOD_DSP_DisconnectFrom(dsphead, dspchannelmixer); ERRCHECK(result); /* Now connect the 2 effects to channeldsp head. [DSPREVERB] / [DSPHEAD] [DSPCHANNELMIXER] \ [DSPCHORUS] */ result = FMOD_DSP_AddInput(dsphead, dspreverb); ERRCHECK(result); result = FMOD_DSP_AddInput(dsphead, dspchorus); ERRCHECK(result); /* Now connect the wavetable to the 2 effects [DSPREVERB] / \ [DSPHEAD] [DSPCHANNELMIXER] \ / [DSPCHORUS] */ result = FMOD_DSP_AddInput(dspreverb, dspchannelmixer); ERRCHECK(result); result = FMOD_DSP_AddInput(dspchorus, dspchannelmixer); 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->dspreverb 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. [DSPREVERB] /1,0 \ [DSPHEAD] [DSPCHANNELMIXER] \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 = FMOD_DSP_SetInputLevels(dsphead, 0, FMOD_SPEAKER_FRONT_LEFT, leftinputon, 2); ERRCHECK(result); result = FMOD_DSP_SetInputLevels(dsphead, 0, FMOD_SPEAKER_FRONT_RIGHT, inputsoff, 2); ERRCHECK(result); result = FMOD_DSP_SetInputLevels(dsphead, 1, FMOD_SPEAKER_FRONT_LEFT, inputsoff, 2); ERRCHECK(result); result = FMOD_DSP_SetInputLevels(dsphead, 1, FMOD_SPEAKER_FRONT_RIGHT, rightinputon, 2); ERRCHECK(result); } result = FMOD_DSP_SetBypass(dspreverb, TRUE); result = FMOD_DSP_SetBypass(dspchorus, TRUE); result = FMOD_DSP_SetActive(dspreverb, TRUE); result = FMOD_DSP_SetActive(dspchorus, TRUE); /* Main loop. */ do { if (kbhit()) { key = getch(); switch (key) { case 'l' : case 'L' : { static int reverb = FALSE; FMOD_DSP_SetBypass(dspreverb, reverb); reverb = !reverb; break; } case 'r' : case 'R' : { static int chorus = FALSE; FMOD_DSP_SetBypass(dspchorus, chorus); chorus = !chorus; break; } case '[' : { FMOD_Channel_GetPan(channel, &pan); pan -= 0.1f; if (pan < -1) { pan = -1; } FMOD_Channel_SetPan(channel, pan); break; } case ']' : { FMOD_Channel_GetPan(channel, &pan); pan += 0.1f; if (pan > 1) { pan = 1; } FMOD_Channel_SetPan(channel, pan); break; } } } FMOD_System_Update(system); { int channelsplaying = 0; FMOD_System_GetChannelsPlaying(system, &channelsplaying); printf("Channels Playing %2d : Pan = %.02f\r", channelsplaying, pan); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_DSP_Release(dspreverb); ERRCHECK(result); result = FMOD_DSP_Release(dspchorus); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_CHANNEL *channel = 0; FMOD_DSP *dsp = 0; FMOD_RESULT result; int key; unsigned int version; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &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 = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); /* Create DSP units for each type of noise we want. */ result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_OSCILLATOR, &dsp); ERRCHECK(result); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_RATE, 440.0f); ERRCHECK(result); printf("======================================================================\n"); printf("GenerateTone Example. Copyright (c) Firelight Technologies 2004-2011.\n"); printf("======================================================================\n\n"); printf("\n"); printf("Press '1' to play a sine wave\n"); printf("Press '2' to play a square wave\n"); printf("Press '3' to play a triangle wave\n"); printf("Press '4' to play a saw wave\n"); printf("Press '5' to play a white noise\n"); printf("Press 's' to stop channel\n"); printf("\n"); printf("Press 'v'/'V' to change channel volume\n"); printf("Press 'f'/'F' to change channel frequency\n"); printf("Press '['/']' to change channel pan\n"); printf("Press 'Esc' to quit\n"); printf("\n"); /* Main loop */ do { if (kbhit()) { key = getch(); switch (key) { case '1' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.5f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 0); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case '2' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.125f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 1); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case '3' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.5f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 2); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case '4' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.125f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 4); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case '5' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.25f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 5); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case 's' : { FMOD_Channel_Stop(channel); break; } case 'v' : { float volume; FMOD_Channel_GetVolume(channel, &volume); volume -= 0.1f; FMOD_Channel_SetVolume(channel, volume); break; } case 'V' : { float volume; FMOD_Channel_GetVolume(channel, &volume); volume += 0.1f; FMOD_Channel_SetVolume(channel, volume); break; } case 'f' : { float frequency; FMOD_Channel_GetFrequency(channel, &frequency); frequency -= 500.0f; FMOD_Channel_SetFrequency(channel, frequency); break; } case 'F' : { float frequency; FMOD_Channel_GetFrequency(channel, &frequency); frequency += 500.0f; FMOD_Channel_SetFrequency(channel, frequency); break; } case '[' : { float pan; FMOD_Channel_GetPan(channel, &pan); pan -= 0.1f; FMOD_Channel_SetPan(channel, pan); break; } case ']' : { float pan; FMOD_Channel_GetPan(channel, &pan); pan += 0.1f; FMOD_Channel_SetPan(channel, pan); break; } } } FMOD_System_Update(system); { float frequency = 0, volume = 0, pan = 0; int playing = FALSE; if (channel) { FMOD_Channel_GetFrequency(channel, &frequency); FMOD_Channel_GetVolume(channel, &volume); FMOD_Channel_GetPan(channel, &pan); FMOD_Channel_IsPlaying(channel, &playing); } printf("Channel %s : Frequency %.1f Volume %.1f Pan %.1f \r", playing ? "playing" : "stopped", frequency, volume, pan); fflush(stdout); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_DSP_Release(dsp); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
//! Set Pan void teSound::SetPan(f32 pan) { if(channel) teSoundManager::CheckResult(FMOD_Channel_SetPan(channel, pan)); }
//------------------------------------------------------------ void ofMultiDeviceSoundPlayer::setPan(float p){ if (getIsPlaying() == true){ FMOD_Channel_SetPan(channel,p); } pan = p; }
FMOD_RESULT bmx_FMOD_Channel_SetPan(MAX_FMOD_CHANNEL *channel, float pan) { return FMOD_Channel_SetPan(channel->channel, pan); }