/** * event_set_volume: * @gain : amount of gain to be applied to current volume level. * * Adjusts the current audio volume level. * **/ static void event_set_volume(float gain) { char msg[PATH_MAX_LENGTH] = {0}; settings_t *settings = config_get_ptr(); settings->audio.volume += gain; settings->audio.volume = max(settings->audio.volume, -80.0f); settings->audio.volume = min(settings->audio.volume, 12.0f); snprintf(msg, sizeof(msg), "Volume: %.1f dB", settings->audio.volume); rarch_main_msg_queue_push(msg, 1, 180, true); RARCH_LOG("%s\n", msg); audio_driver_set_volume_gain(db_to_gain(settings->audio.volume)); }
/** * event_set_volume: * @gain : amount of gain to be applied to current volume level. * * Adjusts the current audio volume level. * **/ static void event_set_volume(float gain) { char msg[128]; settings_t *settings = config_get_ptr(); settings->audio.volume += gain; settings->audio.volume = MAX(settings->audio.volume, -80.0f); settings->audio.volume = MIN(settings->audio.volume, 12.0f); snprintf(msg, sizeof(msg), "Volume: %.1f dB", settings->audio.volume); runloop_msg_queue_push(msg, 1, 180, true); RARCH_LOG("%s\n", msg); audio_driver_set_volume_gain(db_to_gain(settings->audio.volume)); }
static void set_volume(float gain) { char msg[256]; g_settings.audio.volume += gain; g_settings.audio.volume = max(g_settings.audio.volume, -80.0f); g_settings.audio.volume = min(g_settings.audio.volume, 12.0f); snprintf(msg, sizeof(msg), "Volume: %.1f dB", g_settings.audio.volume); msg_queue_clear(g_extern.msg_queue); msg_queue_push(g_extern.msg_queue, msg, 1, 180); RARCH_LOG("%s\n", msg); g_extern.audio_data.volume_gain = db_to_gain(g_settings.audio.volume); }
static void run(LV2_Handle instance, uint32_t n_samples) { uint32_t i,c; BalanceControl* self = (BalanceControl*)instance; const float balance = *self->balance; const float trim = db_to_gain(*self->trim); float gain_left = 1.0; float gain_right = 1.0; const int ascnt = self->samplerate / UPDATE_FREQ; const uint32_t capacity = self->notify->atom.size; lv2_atom_forge_set_buffer(&self->forge, (uint8_t*)self->notify, capacity); lv2_atom_forge_sequence_head(&self->forge, &self->frame, 0); /* reset after state restore */ if (self->queue_stateswitch) { self->queue_stateswitch = 0; self->peak_integrate_pref = self->state[0] * self->samplerate; self->meter_falloff = self->state[1] / UPDATE_FREQ; self->peak_hold = self->state[2] * UPDATE_FREQ; self->peak_integrate_pref = MAX(0, self->peak_integrate_pref); self->peak_integrate_pref = MIN(self->peak_integrate_pref, self->peak_integrate_max); self->meter_falloff = MAX(0, self->meter_falloff); self->meter_falloff = MIN(self->meter_falloff, 1000); self->peak_hold = MAX(0, self->peak_hold); self->peak_hold = MIN(self->peak_hold, 60 * UPDATE_FREQ); reset_uicom(self); send_cfg_to_ui(self); } /* Process incoming events from GUI */ if (self->control) { LV2_Atom_Event* ev = lv2_atom_sequence_begin(&(self->control)->body); while(!lv2_atom_sequence_is_end(&(self->control)->body, (self->control)->atom.size, ev)) { if (ev->body.type == self->uris.atom_Blank || ev->body.type == self->uris.atom_Object) { const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body; if (obj->body.otype == self->uris.blc_meters_on) { if (self->uicom_active == 0) { reset_uicom(self); send_cfg_to_ui(self); self->uicom_active = 1; } } if (obj->body.otype == self->uris.blc_meters_off) { self->uicom_active = 0; } if (obj->body.otype == self->uris.blc_meters_cfg) { const LV2_Atom* key = NULL; const LV2_Atom* value = NULL; lv2_atom_object_get(obj, self->uris.blc_cckey, &key, self->uris.blc_ccval, &value, 0); if (value && key) { update_meter_cfg(self, ((LV2_Atom_Int*)key)->body, ((LV2_Atom_Float*)value)->body); } } } ev = lv2_atom_sequence_next(ev); } } /* pre-calculate parameters */ if (balance < 0) { gain_right = 1.0 + RAIL(balance, -1.0, 0.0); } else if (balance > 0) { gain_left = 1.0 - RAIL(balance, 0.0, 1.0); } switch ((int) *self->unitygain) { case 1: { /* maintain amplitude sum */ const double gaindiff = (gain_left - gain_right); gain_left = 1.0 + gaindiff; gain_right = 1.0 - gaindiff; } break; case 2: { /* equal power*/ if (balance < 0) { gain_right = MAX(.5, gain_right); gain_left = db_to_gain(-gain_to_db(gain_right)); } else { gain_left = MAX(.5, gain_left); gain_right = db_to_gain(-gain_to_db(gain_left)); } } case 0: /* 'tradidional' balance */ break; } if (*(self->phase[C_LEFT])) gain_left *=-1; if (*(self->phase[C_RIGHT])) gain_right *=-1; /* keep track of input levels -- only if GUI is visiable */ if (self->uicom_active) { for (c=0; c < CHANNELS; ++c) { for (i=0; i < n_samples; ++i) { /* input peak meter */ const float ps = fabsf(self->input[c][i]); if (ps > self->p_peak_in[c]) self->p_peak_in[c] = ps; if (self->peak_integrate_pref < 1) { const float psm = ps * ps; if (psm > self->p_peak_inM[c]) self->p_peak_inM[c] = psm; continue; } /* integrated level, peak */ const int pip = (self->peak_integrate_pos + i ) % self->peak_integrate_pref; const double p_sig = SQUARE(self->input[c][i]); self->p_peak_inP[c] += p_sig - self->p_peak_inPi[c][pip]; self->p_peak_inPi[c][pip] = p_sig; /* peak of integrated signal */ const float psm = self->p_peak_inP[c] / (double) self->peak_integrate_pref; if (psm > self->p_peak_inM[c]) self->p_peak_inM[c] = psm; } } } /* process audio -- delayline + balance & gain */ process_channel(self, gain_left * trim, C_LEFT, n_samples); process_channel(self, gain_right * trim, C_RIGHT, n_samples); /* swap/assign channels */ uint32_t pos = 0; if (self->c_monomode != (int) *self->monomode) { /* smooth change */ const uint32_t fade_len = (n_samples >= FADE_LEN) ? FADE_LEN : n_samples; for (; pos < fade_len; pos++) { const float gain = (float)pos / (float)fade_len; float x1[CHANNELS], x2[CHANNELS]; channel_map_change(self, self->c_monomode, pos, x1); channel_map_change(self, (int) *self->monomode, pos, x2); self->output[C_LEFT][pos] = x1[C_LEFT] * (1.0 - gain) + x2[C_LEFT] * gain; self->output[C_RIGHT][pos] = x1[C_RIGHT] * (1.0 - gain) + x2[C_RIGHT] * gain; } } channel_map(self, (int) *self->monomode, pos, n_samples); self->c_monomode = (int) *self->monomode; /* audio processing done */ if (!self->uicom_active) { return; } /* output peak meter */ for (c=0; c < CHANNELS; ++c) { for (i=0; i < n_samples; ++i) { /* peak */ const float ps = fabsf(self->output[c][i]); if (ps > self->p_peak_out[c]) self->p_peak_out[c] = ps; if (self->peak_integrate_pref < 1) { const float psm = ps * ps; if (psm > self->p_peak_outM[c]) self->p_peak_outM[c] = psm; continue; } /* integrated level, peak */ const int pip = (self->peak_integrate_pos + i ) % self->peak_integrate_pref; const double p_sig = SQUARE(self->output[c][i]); self->p_peak_outP[c] += p_sig - self->p_peak_outPi[c][pip]; self->p_peak_outPi[c][pip] = p_sig; /* peak of integrated signal */ const float psm = self->p_peak_outP[c] / (double) self->peak_integrate_pref; if (psm > self->p_peak_outM[c]) self->p_peak_outM[c] = psm; } } if (self->peak_integrate_pref > 0) { self->peak_integrate_pos = (self->peak_integrate_pos + n_samples ) % self->peak_integrate_pref; } /* simple output phase correlation */ for (i=0; i < n_samples; ++i) { const double p_pos = SQUARE(self->output[C_LEFT][i] + self->output[C_RIGHT][i]); const double p_neg = SQUARE(self->output[C_LEFT][i] - self->output[C_RIGHT][i]); /* integrate over 500ms */ self->p_phase_outP += p_pos - self->p_phase_outPi[self->phase_integrate_pos]; self->p_phase_outN += p_neg - self->p_phase_outNi[self->phase_integrate_pos]; self->p_phase_outPi[self->phase_integrate_pos] = p_pos; self->p_phase_outNi[self->phase_integrate_pos] = p_neg; self->phase_integrate_pos = (self->phase_integrate_pos + 1) % self->phase_integrate_max; } /* abs peak hold */ #define PKM(A,CHN,ID) \ { \ const float peak = VALTODB(self->p_peak_##A[CHN]); \ if (peak > self->p_max_##A[CHN]) { \ self->p_max_##A[CHN] = peak; \ self->p_tme_##A[CHN] = 0; \ forge_kvcontrolmessage(&self->forge, &self->uris, ID, self->p_max_##A[CHN]); \ } else if (self->peak_hold <= 0) { \ (self->p_tme_##A[CHN])=0; /* infinite hold */ \ } else if (self->p_tme_##A[CHN] <= self->peak_hold) { \ (self->p_tme_##A[CHN])++; \ } else if (self->meter_falloff == 0) { \ self->p_max_##A[CHN] = peak; \ forge_kvcontrolmessage(&self->forge, &self->uris, ID, self->p_max_##A[CHN]); \ } else { \ self->p_max_##A[CHN] -= self->meter_falloff; \ self->p_max_##A[CHN] = MAX(peak, self->p_max_##A[CHN]); \ forge_kvcontrolmessage(&self->forge, &self->uris, ID, self->p_max_##A[CHN]); \ } \ } /* RMS meter */ #define PKF(A,CHN,ID) \ { \ float dbp = VALTODB(sqrt(2.0 * self->p_peak_##A##M[CHN])); \ if (dbp > self->p_vpeak_##A[CHN]) { \ self->p_vpeak_##A[CHN] = dbp; \ } else if (self->meter_falloff == 0) { \ self->p_vpeak_##A[CHN] = dbp; \ } else { \ self->p_vpeak_##A[CHN] -= self->meter_falloff; \ self->p_vpeak_##A[CHN] = MAX(dbp, self->p_vpeak_##A[CHN]); \ } \ forge_kvcontrolmessage(&self->forge, &self->uris, ID, (self->p_vpeak_##A [CHN])); \ } /* report peaks to UI */ self->p_peakcnt += n_samples; if (self->p_peakcnt > ascnt) { PKF(in, C_LEFT, METER_IN_LEFT) PKF(in, C_RIGHT, METER_IN_RIGHT); PKF(out, C_LEFT, METER_OUT_LEFT); PKF(out, C_RIGHT, METER_OUT_RIGHT); PKM(in, C_LEFT, PEAK_IN_LEFT); PKM(in, C_RIGHT, PEAK_IN_RIGHT); PKM(out, C_LEFT, PEAK_OUT_LEFT); PKM(out, C_RIGHT, PEAK_OUT_RIGHT); #define RMSF(A) sqrt( ( (A) / (double)self->phase_integrate_max ) + 1.0e-12 ) double phase = 0.0; const double phasdiv = self->p_phase_outP + self->p_phase_outN; if (phasdiv >= 1.0e-6) { phase = (RMSF(self->p_phase_outP) - RMSF(self->p_phase_outN)) / RMSF(phasdiv); } else if (self->p_phase_outP > .001 && self->p_phase_outN > .001) { phase = 1.0; } forge_kvcontrolmessage(&self->forge, &self->uris, PHASE_OUT, phase); self->p_peakcnt -= ascnt; for (c=0; c < CHANNELS; ++c) { self->p_peak_in[c] = -INFINITY; self->p_peak_out[c] = -INFINITY; self->p_peak_inM[c] = -INFINITY; self->p_peak_outM[c] = -INFINITY; } } /* report values to UI - if changed*/ float bal = gain_to_db(fabsf(gain_left)); if (bal != self->p_bal[C_LEFT]) { forge_kvcontrolmessage(&self->forge, &self->uris, GAIN_LEFT, bal); } self->p_bal[C_LEFT] = bal; bal = gain_to_db(fabsf(gain_right)); if (bal != self->p_bal[C_RIGHT]) { forge_kvcontrolmessage(&self->forge, &self->uris, GAIN_RIGHT, bal); } self->p_bal[C_RIGHT] = bal; if (self->p_dly[C_LEFT] != self->c_dly[C_LEFT]) { forge_kvcontrolmessage(&self->forge, &self->uris, DELAY_LEFT, (float) self->c_dly[C_LEFT] / self->samplerate); } self->p_dly[C_LEFT] = self->c_dly[C_LEFT]; if (self->p_dly[C_RIGHT] != self->c_dly[C_RIGHT]) { forge_kvcontrolmessage(&self->forge, &self->uris, DELAY_RIGHT, (float) self->c_dly[C_RIGHT] / self->samplerate); } self->p_dly[C_RIGHT] = self->c_dly[C_RIGHT]; }
void config_set_defaults(void) { unsigned i, j; const char *def_video = config_get_default_video(); const char *def_audio = config_get_default_audio(); const char *def_input = config_get_default_input(); #ifdef HAVE_CAMERA const char *def_camera = config_get_default_camera(); if (def_camera) strlcpy(g_settings.camera.driver, def_camera, sizeof(g_settings.camera.driver)); #endif #ifdef HAVE_LOCATION const char *def_location = config_get_default_location(); if (def_location) strlcpy(g_settings.location.driver, def_location, sizeof(g_settings.location.driver)); #endif #ifdef HAVE_OSK const char *def_osk = config_get_default_osk(); if (def_osk) strlcpy(g_settings.osk.driver, def_osk, sizeof(g_settings.osk.driver)); #endif if (def_video) strlcpy(g_settings.video.driver, def_video, sizeof(g_settings.video.driver)); if (def_audio) strlcpy(g_settings.audio.driver, def_audio, sizeof(g_settings.audio.driver)); if (def_input) strlcpy(g_settings.input.driver, def_input, sizeof(g_settings.input.driver)); g_settings.video.xscale = xscale; g_settings.video.yscale = yscale; g_settings.video.fullscreen = g_extern.force_fullscreen ? true : fullscreen; g_settings.video.windowed_fullscreen = windowed_fullscreen; g_settings.video.monitor_index = monitor_index; g_settings.video.fullscreen_x = fullscreen_x; g_settings.video.fullscreen_y = fullscreen_y; g_settings.video.disable_composition = disable_composition; g_settings.video.vsync = vsync; g_settings.video.hard_sync = hard_sync; g_settings.video.hard_sync_frames = hard_sync_frames; g_settings.video.black_frame_insertion = black_frame_insertion; g_settings.video.swap_interval = swap_interval; g_settings.video.threaded = video_threaded; g_settings.video.smooth = video_smooth; g_settings.video.force_aspect = force_aspect; g_settings.video.scale_integer = scale_integer; g_settings.video.crop_overscan = crop_overscan; g_settings.video.aspect_ratio = aspect_ratio; g_settings.video.aspect_ratio_auto = aspect_ratio_auto; // Let implementation decide if automatic, or 1:1 PAR. g_settings.video.aspect_ratio_idx = aspect_ratio_idx; g_settings.video.shader_enable = shader_enable; g_settings.video.allow_rotate = allow_rotate; g_settings.video.font_enable = font_enable; g_settings.video.font_size = font_size; g_settings.video.font_scale = font_scale; g_settings.video.msg_pos_x = message_pos_offset_x; g_settings.video.msg_pos_y = message_pos_offset_y; g_settings.video.msg_color_r = ((message_color >> 16) & 0xff) / 255.0f; g_settings.video.msg_color_g = ((message_color >> 8) & 0xff) / 255.0f; g_settings.video.msg_color_b = ((message_color >> 0) & 0xff) / 255.0f; g_settings.video.refresh_rate = refresh_rate; g_settings.video.post_filter_record = post_filter_record; g_settings.video.gpu_record = gpu_record; g_settings.video.gpu_screenshot = gpu_screenshot; g_settings.video.rotation = ORIENTATION_NORMAL; g_settings.audio.enable = audio_enable; g_settings.audio.out_rate = out_rate; g_settings.audio.block_frames = 0; g_settings.audio.in_rate = out_rate; if (audio_device) strlcpy(g_settings.audio.device, audio_device, sizeof(g_settings.audio.device)); g_settings.audio.latency = out_latency; g_settings.audio.sync = audio_sync; g_settings.audio.rate_control = rate_control; g_settings.audio.rate_control_delta = rate_control_delta; g_settings.audio.volume = audio_volume; g_extern.audio_data.volume_db = g_settings.audio.volume; g_extern.audio_data.volume_gain = db_to_gain(g_settings.audio.volume); g_settings.rewind_enable = rewind_enable; g_settings.rewind_buffer_size = rewind_buffer_size; g_settings.rewind_granularity = rewind_granularity; g_settings.slowmotion_ratio = slowmotion_ratio; g_settings.fastforward_ratio = fastforward_ratio; g_settings.pause_nonactive = pause_nonactive; g_settings.autosave_interval = autosave_interval; g_settings.block_sram_overwrite = block_sram_overwrite; g_settings.savestate_auto_index = savestate_auto_index; g_settings.savestate_auto_save = savestate_auto_save; g_settings.savestate_auto_load = savestate_auto_load; g_settings.network_cmd_enable = network_cmd_enable; g_settings.network_cmd_port = network_cmd_port; g_settings.stdin_cmd_enable = stdin_cmd_enable; g_settings.game_history_size = game_history_size; #ifdef HAVE_MENU g_settings.rgui_show_start_screen = rgui_show_start_screen; #endif rarch_assert(sizeof(g_settings.input.binds[0]) >= sizeof(retro_keybinds_1)); rarch_assert(sizeof(g_settings.input.binds[1]) >= sizeof(retro_keybinds_rest)); memcpy(g_settings.input.binds[0], retro_keybinds_1, sizeof(retro_keybinds_1)); #ifdef RARCH_CONSOLE memcpy(g_settings.input.menu_binds, retro_keybinds_menu, sizeof(retro_keybinds_menu)); #endif for (i = 1; i < MAX_PLAYERS; i++) memcpy(g_settings.input.binds[i], retro_keybinds_rest, sizeof(retro_keybinds_rest)); for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < RARCH_BIND_LIST_END; j++) { g_settings.input.autoconf_binds[i][j].joykey = NO_BTN; g_settings.input.autoconf_binds[i][j].joyaxis = AXIS_NONE; } } memset(g_settings.input.autoconfigured, 0, sizeof(g_settings.input.autoconfigured)); // Verify that binds are in proper order. for (i = 0; i < MAX_PLAYERS; i++) for (j = 0; j < RARCH_BIND_LIST_END; j++) if (g_settings.input.binds[i][j].valid) rarch_assert(j == g_settings.input.binds[i][j].id); g_settings.input.axis_threshold = axis_threshold; g_settings.input.netplay_client_swap_input = netplay_client_swap_input; g_settings.input.turbo_period = turbo_period; g_settings.input.turbo_duty_cycle = turbo_duty_cycle; g_settings.input.overlay_opacity = 0.7f; g_settings.input.overlay_scale = 1.0f; g_settings.input.debug_enable = input_debug_enable; g_settings.input.autodetect_enable = input_autodetect_enable; *g_settings.input.keyboard_layout = '\0'; #ifdef ANDROID g_settings.input.back_behavior = BACK_BUTTON_QUIT; #endif for (i = 0; i < MAX_PLAYERS; i++) { g_settings.input.joypad_map[i] = i; g_settings.input.analog_dpad_mode[i] = ANALOG_DPAD_NONE; if (!g_extern.has_set_libretro_device[i]) g_settings.input.libretro_device[i] = RETRO_DEVICE_JOYPAD; } g_extern.console.screen.viewports.custom_vp.width = 0; g_extern.console.screen.viewports.custom_vp.height = 0; g_extern.console.screen.viewports.custom_vp.x = 0; g_extern.console.screen.viewports.custom_vp.y = 0; // Make sure settings from other configs carry over into defaults for another config. if (!g_extern.has_set_save_path) *g_extern.savefile_dir = '\0'; if (!g_extern.has_set_state_path) *g_extern.savestate_dir = '\0'; *g_settings.libretro_info_path = '\0'; *g_settings.core_options_path = '\0'; *g_settings.game_history_path = '\0'; *g_settings.cheat_database = '\0'; *g_settings.cheat_settings_path = '\0'; *g_settings.screenshot_directory = '\0'; *g_settings.system_directory = '\0'; *g_settings.input.autoconfig_dir = '\0'; *g_settings.input.overlay = '\0'; *g_settings.content_directory = '\0'; *g_settings.video.shader_path = '\0'; *g_settings.video.shader_dir = '\0'; #ifdef HAVE_MENU *g_settings.rgui_content_directory = '\0'; *g_settings.rgui_config_directory = '\0'; #endif #ifdef RARCH_CONSOLE g_extern.lifecycle_state |= (1ULL << MODE_MENU_PREINIT); strlcpy(g_settings.system_directory, default_paths.system_dir, sizeof(g_settings.system_directory)); g_settings.video.msg_pos_x = 0.05f; g_settings.video.msg_pos_y = 0.90f; g_settings.video.aspect_ratio = -1.0f; g_settings.core_specific_config = default_core_specific_config; // g_extern strlcpy(g_extern.savefile_dir, default_paths.sram_dir, sizeof(g_extern.savefile_dir)); g_extern.console.screen.gamma_correction = DEFAULT_GAMMA; g_extern.lifecycle_state |= (1ULL << MODE_AUDIO_CUSTOM_BGM_ENABLE); g_extern.lifecycle_state |= (1ULL << MODE_VIDEO_TRIPLE_BUFFERING_ENABLE); g_extern.lifecycle_state |= (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE); g_extern.lifecycle_state |= (1ULL << MODE_VIDEO_FLICKER_FILTER_ENABLE); g_extern.console.screen.resolutions.current.id = 0; strlcpy(g_extern.savestate_dir, default_paths.savestate_dir, sizeof(g_extern.savestate_dir)); g_extern.state_slot = 0; g_extern.audio_data.mute = 0; g_extern.verbose = true; g_extern.console.sound.mode = SOUND_MODE_NORMAL; #ifdef _XBOX1 g_extern.console.sound.volume_level = 0; #endif #endif #ifdef HAVE_OVERLAY if (default_overlay_dir) { fill_pathname_expand_special(g_extern.overlay_dir, default_overlay_dir, sizeof(g_extern.overlay_dir)); #if defined(__QNX__) || defined(IOS) fill_pathname_join(g_settings.input.overlay, g_extern.overlay_dir, "snes/snes.cfg", sizeof(g_settings.input.overlay)); #endif } #endif if (default_shader_dir) fill_pathname_expand_special(g_settings.video.shader_dir, default_shader_dir, sizeof(g_settings.video.shader_dir)); if (default_libretro_path && !g_extern.has_set_libretro) fill_pathname_expand_special(g_settings.libretro, default_libretro_path, sizeof(g_settings.libretro)); if (default_libretro_info_path) fill_pathname_expand_special(g_settings.libretro_info_path, default_libretro_info_path, sizeof(g_settings.libretro_info_path)); if (default_config_path) fill_pathname_expand_special(g_extern.config_path, default_config_path, sizeof(g_extern.config_path)); g_extern.config_save_on_exit = config_save_on_exit; /* Avoid reloading config on every ROM load */ g_extern.block_config_read = default_block_config_read; rarch_init_msg_queue(); }