virtual const float GetVolume(){ float b; if(mpChannel == 0)return 0.0f; else { FMOD_Channel_GetVolume(mpChannel, &b); return b; } }
float sound_volume() { float v = 0; if (loaded) { FMOD_Channel_GetVolume(_channel, &v); } return v; }
void Ultra::play() { float volume = 0.0; FMOD_Channel_SetVolume(musicChannel, 1.0); FMOD_Channel_GetVolume(musicChannel, &volume); fout << volume << std::endl; playMusic(ultraMusic); setCurrentGamePiece(createNewPiece()); setNextPiece(createNewPiece()); enableCurrentPiece(); setLinesCompleted(0); setLevel(1); setFallIterationDelay(computeFallIterationDelay()); setScore(0); setState(RUNNING); sf::Clock fallingClock; fallingClock.Reset(); float currentTime = 0, precTime = 0; while(renderArea->IsOpened()) { if(getState() == PAUSED) { setBackground(PAUSE_IMG); timer.pause(); if(handlePauseInput() == RETURN_MAIN) return; } else { timer.start(); currentTime = fallingClock.GetElapsedTime(); handleTimerInput(currentTime, precTime); handleUserInput(); if(Game::gameOver() || timeElapsed()) { if(handleGameOverInput() == RETURN_MAIN) return; } else render(); } renderArea->Display(); } }
//! Get Volume f32 teSound::GetVolume() { f32 volume = 0.0f; if(channel) teSoundManager::CheckResult(FMOD_Channel_GetVolume(channel, &volume)); return volume; }
void ModuleIrisAudio::FadeBgmThreadProc(int duration){ bgmIsFading = true; int time = duration; while (time >= 0){ float v; FMOD_Channel_SetPaused(bgmChannel, true); FMOD_Channel_GetVolume(bgmChannel, &v); FMOD_Channel_SetVolume(bgmChannel, v - v / (duration / 1000)); time -= 1000; FMOD_Channel_SetPaused(bgmChannel, false); Sleep(1000); } FMOD_Channel_Stop(bgmChannel); bgmIsFading = false; }
/* --------------------------------------- 获取音量 --------------------------------------- */ static bool_t iXMM_FMOD_get_volume ( __CR_IO__ iXMMEDIA* that, __CR_OT__ sint_t* percent ) { float vols; iXMM_FMOD* real; FMOD_RESULT result; real = (iXMM_FMOD*)that; result = FMOD_Channel_GetVolume(real->m_chn, &vols); if (result != FMOD_OK) return (FALSE); that->__volume__ = (sint_t)(vols * 100.0f); if (percent != NULL) *percent = that->__volume__; return (TRUE); }
float Sound::getVolume() { float v; FMOD_Channel_GetVolume(this->ch,&v); return v; }
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; }
float sound::volume() const { float current = 1; FMOD_Channel_GetVolume(_chan, ¤t); return current; }
FMOD_CHANNEL *queue_next_sound(int outputrate, FMOD_CHANNEL *playingchannel, int newindex, int slot) { FMOD_RESULT result; FMOD_CHANNEL *newchannel; FMOD_SOUND *newsound; #ifdef USE_STREAMS /* Create a new stream */ FMOD_CREATESOUNDEXINFO info; memset(&info, 0, sizeof(FMOD_CREATESOUNDEXINFO)); info.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); info.suggestedsoundtype = FMOD_SOUND_TYPE_OGGVORBIS; result = FMOD_System_CreateStream(gSystem, soundname[newindex], FMOD_IGNORETAGS | FMOD_LOWMEM, &info, &sound[slot]); ERRCHECK(result); newsound = sound[slot]; #else /* Use an existing sound that was passed into us */ newsound = sound[newindex]; #endif result = FMOD_System_PlaySound(gSystem, FMOD_CHANNEL_FREE, newsound, 1, &newchannel); ERRCHECK(result); result = FMOD_Channel_SetSpeakerMix(newchannel, 1,1,1,1,1,1,1,1); ERRCHECK(result); if (playingchannel) { unsigned int hi = 0, lo = 0, sound_length; float sound_frequency; FMOD_SOUND *playingsound; /* Get the start time of the playing channel. */ result = FMOD_Channel_GetDelay(playingchannel, FMOD_DELAYTYPE_DSPCLOCK_START, &hi, &lo); ERRCHECK(result); printf("playing sound started at %d\n", lo); /* Grab the length of the playing sound, and its frequency, so we can caluate where to place the new sound on the time line. */ result = FMOD_Channel_GetCurrentSound(playingchannel, &playingsound); ERRCHECK(result); result = FMOD_Sound_GetLength(playingsound, &sound_length, FMOD_TIMEUNIT_PCM); ERRCHECK(result); result = FMOD_Channel_GetFrequency(playingchannel, &sound_frequency); ERRCHECK(result); /* Now calculate the length of the sound in 'output samples'. Ie if a 44khz sound is 22050 samples long, and the output rate is 48khz, then we want to delay by 24000 output samples. */ sound_length *= outputrate; sound_length /= (int)sound_frequency; FMOD_64BIT_ADD(hi, lo, 0, sound_length); /* Add output rate adjusted sound length, to the clock value of the sound that is currently playing */ result = FMOD_Channel_SetDelay(newchannel, FMOD_DELAYTYPE_DSPCLOCK_START, hi, lo); /* Set the delay of the new sound to the end of the old sound */ ERRCHECK(result); } { unsigned int hi = 0, lo = 0; float val, variation; /* Randomize pitch/volume to make it sound more realistic / random. */ FMOD_Channel_GetFrequency(newchannel, &val); variation = (((float)(rand()%10000) / 5000.0f) - 1.0f); /* -1.0 to +1.0 */ val *= (1.0f + (variation * 0.02f)); /* @22khz, range fluctuates from 21509 to 22491 */ FMOD_Channel_SetFrequency(newchannel, val); FMOD_Channel_GetVolume(newchannel, &val); variation = ((float)(rand()%10000) / 10000.0f); /* 0.0 to 1.0 */ val *= (1.0f - (variation * 0.2f)); /* 0.8 to 1.0 */ FMOD_Channel_SetVolume(newchannel, val); FMOD_Channel_GetDelay(newchannel, FMOD_DELAYTYPE_DSPCLOCK_START, &hi, &lo); printf("new sound to start at %d (slot %d)\n", lo, slot); } result = FMOD_Channel_SetPaused(newchannel, FALSE); ERRCHECK(result); return newchannel; }
int main(int argc, char *argv[]) { int att = 1, motion_state = 0, status = STOP; float volume; SDL_Event event; SDL_Surface *ecran = NULL, *fond = NULL, *play = NULL, *stop = NULL, *pause = NULL, *volumeup = NULL, *volumedown = NULL, *spectrum = NULL; SDL_Surface *iplay = NULL, *ipause = NULL, *istop = NULL, *ivolup = NULL, *ivoldo = NULL; SDL_Rect pos_fond, pos_spect, pos_play, pos_pause, pos_stop, pos_volumeup, pos_volumedown; printf("Démarrage de Freqalyzer\n"); FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_CHANNEL *channel=0; FMOD_RESULT result; FMOD_BOOL state; void *extradriverdata = 0; pos_fond.x = 0; pos_fond.y = 0; pos_spect.x = 100; pos_spect.y = 150; pos_play.x = 100; pos_play.y = 520; pos_pause.x = 100 + CONTROLLER_SIZE; pos_pause.y = 520; pos_stop.x = 100 + (CONTROLLER_SIZE * 2); pos_stop.y = 520; pos_volumeup.x = 100 + (CONTROLLER_SIZE * 3); pos_volumeup.y = 520; pos_volumedown.x = 100 + (CONTROLLER_SIZE * 4); pos_volumedown.y = 520; //Chargement en mémoire du système d'affichage SDL - Vidéo SDL_Init(SDL_INIT_VIDEO); if(SDL_Init(SDL_INIT_VIDEO) == -1) { fprintf(stderr, "Erreur d'initialisation de la SDL"); exit(EXIT_FAILURE); } //Paramétrage et ouverture de la fenêtre ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); spectrum = SDL_CreateRGBSurface(SDL_HWSURFACE, 600, 350, 32, 0, 0, 0, 0); SDL_FillRect(spectrum, NULL, SDL_MapRGB(ecran->format, 0, 0, 0)); //Titrage de la fenêtre SDL_WM_SetCaption("Freqalyzer", NULL); //Chargement des images fond = IMG_Load("../pictures/fond.jpg"); W_GestionErreur(P_IMAGE, 0, fond, "fond.jpg"); play = IMG_Load("../pictures/play.jpg"); W_GestionErreur(P_IMAGE, 0, play, "play.jpg"); pause = IMG_Load("../pictures/pause.jpg"); W_GestionErreur(P_IMAGE, 0, pause, "pause.jpg"); stop = IMG_Load("../pictures/stop.jpg"); W_GestionErreur(P_IMAGE, 0, stop, "stop.jpg"); volumeup = IMG_Load("../pictures/volume_up.jpg"); W_GestionErreur(P_IMAGE, 0, volumeup, "volume_up.jpg"); volumedown = IMG_Load("../pictures/volume_down.jpg"); W_GestionErreur(P_IMAGE, 0, volumedown, "volume_down.jpg"); iplay = IMG_Load("../pictures/iplay.jpg"); W_GestionErreur(P_IMAGE, 0, iplay, "iplay.jpg"); ipause = IMG_Load("../pictures/ipause.jpg"); W_GestionErreur(P_IMAGE, 0, ipause, "ipause.jpg"); istop = IMG_Load("../pictures/istop.jpg"); W_GestionErreur(P_IMAGE, 0, istop, "istop.jpg"); ivolup = IMG_Load("../pictures/ivolume_up.jpg"); W_GestionErreur(P_IMAGE, 0, ivolup, "ivolume_up.jpg"); ivoldo = IMG_Load("../pictures/ivolume_down.jpg"); W_GestionErreur(P_IMAGE, 0, ivoldo, "ivolume_down.jpg"); //Allocation de mémoire à system result = FMOD_System_Create(&system); W_GestionErreur(P_CREASON, result, NULL, ""); //Initialisation result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, extradriverdata); W_GestionErreur(P_CHARGSON, result, NULL, ""); result = FMOD_System_CreateSound(system, "../sounds/radio_sig.mp3", FMOD_2D | FMOD_CREATESTREAM, 0, &sound); /* //Chargement du son result = FMOD_System_CreateSound(system, argv[1], FMOD_2D | FMOD_CREATESTREAM, 0, &sound); if (result != 0) { printf("\nErreur de saisie, veuillez taper un chemin correct \n(ex : ./Freqalyser ../sounds/gameofthrones.mp3)\n"); exit(EXIT_FAILURE); }*/ while(att) { SDL_WaitEvent(&event); if (event.motion.x > 100 && event.motion.x < (100 + CONTROLLER_SIZE * 5) && event.motion.y > 520 && event.motion.y < (520 + CONTROLLER_SIZE)) { motion_state = 1; W_event(ecran, iplay, ipause, istop, ivolup, ivoldo); }else motion_state = 0; switch(event.type) { case SDL_QUIT: att = 0; break; case SDL_MOUSEBUTTONUP: if (event.button.x > 100 && event.button.x < (100 + CONTROLLER_SIZE) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE)) { //jouer le son et mettre en pause le programme le temps de sa lecture result=FMOD_System_PlaySound(system, sound, 0, 0, &channel); W_GestionErreur(P_LECTURE, result, NULL, ""); unsigned int length; FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_MS); FMOD_Channel_GetVolume(channel, &volume); FMOD_Channel_GetVolume(channel, &volume); status = PLAY; } if (event.button.x > (100 + CONTROLLER_SIZE) && event.button.x < (100 + (CONTROLLER_SIZE * 2)) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE)) { FMOD_System_GetChannel(system, 512, &channel); FMOD_Channel_GetPaused(channel, &state); if(state) { FMOD_Channel_SetPaused(channel, 0); status = PLAY; } else { FMOD_Channel_SetPaused(channel, 1); status = PAUSE; } } if (event.button.x > (100 + CONTROLLER_SIZE * 2) && event.button.x < (100 + CONTROLLER_SIZE * 3) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE)) { FMOD_Channel_Stop(channel); status = STOP; } if (event.button.x > (100 + CONTROLLER_SIZE * 3) && event.button.x < (100 + CONTROLLER_SIZE * 4) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE)) result = W_GestionVolume(&volume, channel, UP); if (event.button.x > (100 + CONTROLLER_SIZE * 4) && event.button.x < (100 + CONTROLLER_SIZE * 5) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE)) result = W_GestionVolume(&volume, channel, DOWN); break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: att = 0; break; case SDLK_SPACE: //jouer le son et mettre en pause le programme le temps de sa lecture result=FMOD_System_PlaySound(system, sound, 0, 0, &channel); unsigned int length; FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_MS); FMOD_Channel_GetVolume(channel, &volume); FMOD_Channel_GetVolume(channel, &volume); status = PLAY; break; case SDLK_UP: result = W_GestionVolume(&volume, channel, UP); break; case SDLK_DOWN: result = W_GestionVolume(&volume, channel, DOWN); break; case SDLK_p: FMOD_System_GetChannel(system, 512, &channel); FMOD_Channel_GetPaused(channel, &state); if(state) { FMOD_Channel_SetPaused(channel, 0); status = PLAY; } else { FMOD_Channel_SetPaused(channel, 1); status = PAUSE; } break; case SDLK_s: FMOD_Channel_Stop(channel); status = STOP; break; default: break; } default: break; } //Affichage des surfaces SDL_BlitSurface(fond, NULL, ecran, &pos_fond); SDL_BlitSurface(spectrum, NULL, ecran, &pos_spect); switch (status) { case PLAY: SDL_BlitSurface(iplay, NULL, ecran, &pos_play); SDL_BlitSurface(pause, NULL, ecran, &pos_pause); SDL_BlitSurface(stop, NULL, ecran, &pos_stop); break; case PAUSE: SDL_BlitSurface(play, NULL, ecran, &pos_play); SDL_BlitSurface(ipause, NULL, ecran, &pos_pause); SDL_BlitSurface(stop, NULL, ecran, &pos_stop); break; case STOP: SDL_BlitSurface(play, NULL, ecran, &pos_play); SDL_BlitSurface(pause, NULL, ecran, &pos_pause); SDL_BlitSurface(istop, NULL, ecran, &pos_stop); break; default: break; } SDL_BlitSurface(volumeup, NULL, ecran, &pos_volumeup); SDL_BlitSurface(volumedown, NULL, ecran, &pos_volumedown); //Rafraîchissement de la fenêtre SDL_Flip(ecran); FMOD_System_Update(system); } //Fermeture et libération de l'objet system en mémoire FMOD_Sound_Release(sound); FMOD_System_Close(system); FMOD_System_Release(system); SDL_FreeSurface(spectrum); SDL_FreeSurface(fond); SDL_FreeSurface(play); SDL_FreeSurface(pause); SDL_FreeSurface(stop); SDL_FreeSurface(volumeup); SDL_FreeSurface(volumedown); SDL_FreeSurface(iplay); SDL_FreeSurface(ipause); SDL_FreeSurface(istop); SDL_FreeSurface(ivolup); SDL_FreeSurface(ivoldo); SDL_Quit(); return EXIT_SUCCESS; }
FMOD_RESULT bmx_FMOD_Channel_GetVolume(MAX_FMOD_CHANNEL *channel, float * volume) { return FMOD_Channel_GetVolume(channel->channel, volume); }