void set_sound_volume(int vol) { if(sound_volume() == vol) { return; } preferences::set("sound_volume", lexical_cast_default<std::string>(vol, "100")); sound::set_sound_volume(sound_volume()); }
void set_sound_volume(int vol) { if(sound_volume() == vol) { return; } prefs["sound_volume"] = vol; sound::set_sound_volume(sound_volume()); }
/** * @brief Callback to set the sound level. * * @param wid Window calling the callback. * @param str Name of the widget calling the callback. */ static void opt_setSFXLevel( unsigned int wid, char *str ) { double vol; vol = window_getFaderValue(wid, str); sound_volume(vol); }
/** * @brief Callback to set the sound level. * * @param wid Window calling the callback. * @param str Name of the widget calling the callback. */ static void opt_setSFXLevel( unsigned int wid, char *str ) { char buf[32]; double vol; /* Set fader. */ vol = window_getFaderValue(wid, str); sound_volume(vol); /* Update message. */ snprintf( buf, sizeof(buf), "Sound Volume: %.2f", sound_getVolume() ); window_modifyText( wid, "txtSound", buf ); }
/** * @brief Callback to set the sound or music level. * * @param wid Window calling the callback. * @param str Name of the widget calling the callback. * @param type 0 for sound, 1 for audio. */ static void opt_setAudioLevel( unsigned int wid, char *str ) { char buf[32], *widget; double vol; vol = window_getFaderValue(wid, str); if (strcmp(str,"fadSound")==0) { sound_volume(vol); widget = "txtSound"; opt_audioLevelStr( buf, sizeof(buf), 0, vol ); } else { music_volume(vol); widget = "txtMusic"; opt_audioLevelStr( buf, sizeof(buf), 1, vol ); } window_modifyText( wid, widget, buf ); }
/** * @brief Sets the audio defaults. */ static void opt_audioDefaults( unsigned int wid, char *str ) { (void) str; /* Ask user. */ if (!dialogue_YesNoRaw( "Restore Defaults", "Are you sure you want to restore default audio settings?" )) return; /* Set defaults. */ conf_setAudioDefaults(); /* Have sound levels affect. */ sound_volume(conf.sound); music_volume(conf.music); /* Update widgets. */ opt_audioUpdate( wid, NULL ); /* Alert user it worked. */ dialogue_msgRaw( "Defaults Restored", "Audio settings restored to defaults."); }
void GW_PlatformSDL::initialize() { if (!initialized_) { GWDBG_OUTPUT("SDL: Initialize"); // initialize SDL video if ( SDL_Init( sdlinit(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) ) < 0 ) throw GW_Exception(string("Unable to init SDL: "+string(SDL_GetError()))); #ifndef GW_NO_SDL_MIXER if ( Mix_OpenAudio(22050, AUDIO_S16SYS, 1, audiobufsize_get()) < 0) throw GW_Exception(string("Unable to init SDL_mixer: "+string(Mix_GetError()))); #endif #ifndef GW_NO_SDL_TTF if ( TTF_Init() < 0 ) throw GW_Exception(string("Unable to init SDL_ttf: "+string(TTF_GetError()))); #endif #ifndef GW_NO_SDL_MIXER Mix_AllocateChannels(6); sound_volume(75); #endif custom_initialize(); // make sure SDL cleans up before exit atexit(SDL_Quit); // set application icon plat_init(); // create a new window window_ = SDL_CreateWindow("Game & Watch simulator - by Hitnrun / ZsoltK & Madrigal", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width_, height_, fullscreen_ ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_SHOWN); if ( !window_ ) throw GW_Exception(string("Unable to allocate game window: " + string(SDL_GetError()))); renderer_ = SDL_CreateRenderer(window_, -1, SDL_RENDERER_ACCELERATED); if ( !renderer_ ) throw GW_Exception(string("Unable to allocate renderer: " + string(SDL_GetError()))); // Let SDL & GPU do the scaling SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); SDL_RenderSetLogicalSize(renderer_, width_, height_); SDL_ShowCursor(SDL_DISABLE); #ifndef GW_NO_SDL_TTF // load font //font_=TTF_OpenFont( bf::path( bf::path(platformdata_get() ) / "andalemo.ttf" ).string().c_str(), fontsize_get() ); string pfont(platformdata_get() + "/" + "andalemo.ttf" ); font_=TTF_OpenFont( pfont.c_str(), fontsize_get() ); if (!font_) throw GW_Exception(string("Unable to load font: "+string(TTF_GetError()))); #endif initialized_=true; } }
int main(int argc, char *argv[]) { int result = ACTION_NONE; int leave = 0; /* i18n */ #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif /* ltris info */ printf( "LTris %s\nCopyright 2002-2005 Michael Speck\nPublished under GNU GPL\n---\n", VERSION ); printf( "Looking up data in: %s\n", SRC_DIR ); #ifndef SOUND printf( "Compiled without sound and music\n" ); #endif set_random_seed(); /* set random seed */ /* game ids - not translated to be fixed independant of language */ strcpy(gametype_ids[0],"demo"); strcpy(gametype_ids[1],"classic"); strcpy(gametype_ids[2],"figures"); strcpy(gametype_ids[3],"vshuman"); strcpy(gametype_ids[4],"vscpu"); strcpy(gametype_ids[5],"vshumanhuman"); strcpy(gametype_ids[6],"vshumancpu"); strcpy(gametype_ids[7],"vscpucpu"); /* game names - translated for display */ strcpy(gametype_names[0],_("Demo")); strcpy(gametype_names[1],_("Classic")); strcpy(gametype_names[2],_("Figures")); strcpy(gametype_names[3],_("Vs Human")); strcpy(gametype_names[4],_("Vs CPU")); strcpy(gametype_names[5],_("Vs Human&Human")); strcpy(gametype_names[6],_("Vs Human&CPU")); strcpy(gametype_names[7],_("Vs CPU&CPU")); config_load(); init_sdl( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER ); set_video_mode( std_video_mode( config.fullscreen ) ); SDL_WM_SetCaption( "LTris", 0 ); sdl.fade = config.fade; SDL_SetEventFilter( event_filter ); #ifdef SOUND audio_open(); sound_enable( config.sound ); sound_volume( config.volume * 16 ); #endif /* create */ hint_load_res(); manager_create(); tetris_create(); chart_load(); /* run game */ manager_fade( FADE_IN ); while( !leave && !term_game ) { result = manager_run(); switch( result ) { case ACTION_QUIT: leave = 1; break; case ACTION_MAKE_STAT: manager_fade( FADE_OUT ); tetris_make_stat(); manager_fade( FADE_IN ); break; case ACTION_PLAY: manager_fade( FADE_OUT ); if ( tetris_init() ) { tetris_run(); tetris_clear(); } manager_fade( FADE_IN ); break; default: break; } } manager_fade( FADE_OUT ); /* delete stuff */ tetris_delete(); manager_delete(); chart_save(); chart_delete(); hint_delete_res(); #ifdef SOUND audio_close(); #endif config_save(); return EXIT_SUCCESS; }
/** * @brief Initializes the sound subsystem. * * @return 0 on success. */ int sound_init (void) { int ret; /* See if sound is disabled. */ if (conf.nosound) { sound_disabled = 1; music_disabled = 1; } /* Parse conf. */ if (sound_disabled && music_disabled) return 0; /* Choose sound system. */ if ((sound_sys_init == NULL) && (conf.sound_backend != NULL) && (strcmp(conf.sound_backend,"openal")==0)) { #if USE_OPENAL /* * OpenAL Sound. */ /* Creation. */ sound_sys_init = sound_al_init; sound_sys_exit = sound_al_exit; /* Sound Creation. */ sound_sys_load = sound_al_load; sound_sys_free = sound_al_free; /* Sound settings. */ sound_sys_volume = sound_al_volume; sound_sys_getVolume = sound_al_getVolume; sound_sys_getVolumeLog = sound_al_getVolumeLog; /* Sound playing. */ sound_sys_play = sound_al_play; sound_sys_playPos = sound_al_playPos; sound_sys_updatePos = sound_al_updatePos; sound_sys_updateVoice = sound_al_updateVoice; /* Sound management. */ sound_sys_update = sound_al_update; sound_sys_stop = sound_al_stop; sound_sys_pause = sound_al_pause; sound_sys_resume = sound_al_resume; sound_sys_setSpeed = sound_al_setSpeed; /* Listener. */ sound_sys_updateListener = sound_al_updateListener; /* Groups. */ sound_sys_createGroup = sound_al_createGroup; sound_sys_playGroup = sound_al_playGroup; sound_sys_stopGroup = sound_al_stopGroup; sound_sys_pauseGroup = sound_al_pauseGroup; sound_sys_resumeGroup = sound_al_resumeGroup; /* Env. */ sound_sys_env = sound_al_env; #else /* USE_OPENAL */ WARN("OpenAL support not compiled in!"); #endif /* USE_OPENAL */ } if ((sound_sys_init == NULL) && (conf.sound_backend != NULL) && (strcmp(conf.sound_backend,"sdlmix")==0)) { #if USE_SDLMIX /* * SDL_mixer Sound. */ /* Creation. */ sound_sys_init = sound_mix_init; sound_sys_exit = sound_mix_exit; /* Sound Creation. */ sound_sys_load = sound_mix_load; sound_sys_free = sound_mix_free; /* Sound settings. */ sound_sys_volume = sound_mix_volume; sound_sys_getVolume = sound_mix_getVolume; sound_sys_getVolumeLog = sound_mix_getVolume; /* Sound playing. */ sound_sys_play = sound_mix_play; sound_sys_playPos = sound_mix_playPos; sound_sys_updatePos = sound_mix_updatePos; sound_sys_updateVoice = sound_mix_updateVoice; /* Sound management. */ sound_sys_update = sound_mix_update; sound_sys_stop = sound_mix_stop; sound_sys_pause = sound_mix_pause; sound_sys_resume = sound_mix_resume; sound_sys_setSpeed = sound_mix_setSpeed; /* Listener. */ sound_sys_updateListener = sound_mix_updateListener; /* Groups. */ sound_sys_createGroup = sound_mix_createGroup; sound_sys_playGroup = sound_mix_playGroup; sound_sys_stopGroup = sound_mix_stopGroup; sound_sys_pauseGroup = sound_mix_pauseGroup; sound_sys_resumeGroup = sound_mix_resumeGroup; /* Env. */ sound_sys_env = sound_mix_env; #else /* USE_SDLMIX */ WARN("SDL_mixer support not compiled in!"); #endif /* USE_SDLMIX */ } if (sound_sys_init == NULL) { WARN("Unknown/Unavailable sound backend '%s'.", conf.sound_backend); sound_disabled = 1; WARN("Sound disabled."); music_disabled = 1; return 0; } /* Initialize sound backend. */ ret = sound_sys_init(); if (ret != 0) { sound_disabled = 1; music_disabled = 1; WARN("Sound disabled."); return ret; } /* Create voice lock. */ voice_mutex = SDL_CreateMutex(); if (voice_mutex == NULL) { WARN("Unable to create voice mutex."); } /* Load available sounds. */ ret = sound_makeList(); if (ret != 0) return ret; /* Initialize music. */ ret = music_init(); if (ret != 0) { music_disabled = 1; WARN("Music disabled."); } /* Set volume. */ if ((conf.sound > 1.) || (conf.sound < 0.)) WARN("Sound has invalid value, clamping to [0:1]."); sound_volume(conf.sound); /* Initialized. */ sound_initialized = 1; return 0; }