void uninit_audio(void) { if (driver.audio_data && driver.audio) driver.audio->free(driver.audio_data); free(g_extern.audio_data.conv_outsamples); g_extern.audio_data.conv_outsamples = NULL; g_extern.audio_data.data_ptr = 0; free(g_extern.audio_data.rewind_buf); g_extern.audio_data.rewind_buf = NULL; if (!g_settings.audio.enable) { g_extern.audio_active = false; return; } rarch_resampler_freep(&g_extern.audio_data.resampler, &g_extern.audio_data.resampler_data); free(g_extern.audio_data.data); g_extern.audio_data.data = NULL; free(g_extern.audio_data.outsamples); g_extern.audio_data.outsamples = NULL; rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); compute_audio_buffer_statistics(); }
void uninit_audio(void) { if (driver.audio_data && driver.audio) driver.audio->free(driver.audio_data); free(g_extern.audio_data.conv_outsamples); g_extern.audio_data.conv_outsamples = NULL; g_extern.audio_data.data_ptr = 0; free(g_extern.audio_data.rewind_buf); g_extern.audio_data.rewind_buf = NULL; if (!g_settings.audio.enable) { g_extern.audio_active = false; return; } rarch_resampler_freep(&g_extern.audio_data.resampler, &g_extern.audio_data.resampler_data); free(g_extern.audio_data.data); g_extern.audio_data.data = NULL; free(g_extern.audio_data.outsamples); g_extern.audio_data.outsamples = NULL; rarch_deinit_dsp_filter(); compute_audio_buffer_statistics(); }
int main(int argc, char *argv[]) { int16_t input_i[1024]; int16_t output_i[1024 * 8]; float input_f[1024]; float output_f[1024 * 8]; if (argc != 3) { fprintf(stderr, "Usage: %s <in-rate> <out-rate> (max ratio: 8.0)\n", argv[0]); return 1; } double in_rate = strtod(argv[1], NULL); double out_rate = strtod(argv[2], NULL); double ratio = out_rate / in_rate; if (ratio >= 7.99) { fprintf(stderr, "Ratio is too high.\n"); return 1; } const rarch_resampler_t *resampler = NULL; void *re = NULL; if (!rarch_resampler_realloc(&re, &resampler, NULL)) { fprintf(stderr, "Failed to allocate resampler ...\n"); return 1; } for (;;) { if (fread(input_i, sizeof(int16_t), 1024, stdin) != 1024) break; audio_convert_s16_to_float(input_f, input_i, 1024, 1.0f); struct resampler_data data = { .data_in = input_f, .data_out = output_f, .input_frames = sizeof(input_f) / (2 * sizeof(float)), .ratio = ratio, }; rarch_resampler_process(resampler, re, &data); size_t output_samples = data.output_frames * 2; audio_convert_float_to_s16(output_i, output_f, output_samples); if (fwrite(output_i, sizeof(int16_t), output_samples, stdout) != output_samples) break; } rarch_resampler_freep(&resampler, &re); }
static void ffmpeg_free(void *data) { ffmpeg_t *handle = (ffmpeg_t*)data; if (!handle) return; deinit_thread(handle); deinit_thread_buf(handle); if (handle->audio.codec) { avcodec_close(handle->audio.codec); av_free(handle->audio.codec); } av_free(handle->audio.buffer); if (handle->video.codec) { avcodec_close(handle->video.codec); av_free(handle->video.codec); } av_frame_free(&handle->video.conv_frame); av_free(handle->video.conv_frame_buf); scaler_ctx_gen_reset(&handle->video.scaler); if (handle->video.sws) sws_freeContext(handle->video.sws); if (handle->config.conf) config_file_free(handle->config.conf); if (handle->config.video_opts) av_dict_free(&handle->config.video_opts); if (handle->config.audio_opts) av_dict_free(&handle->config.audio_opts); rarch_resampler_freep(&handle->audio.resampler, &handle->audio.resampler_data); av_free(handle->audio.float_conv); av_free(handle->audio.resample_out); av_free(handle->audio.fixed_conv); av_free(handle->audio.planar_buf); free(handle); }
int main(int argc, char *argv[]) { srand(time(NULL)); int16_t input_i[1024]; int16_t output_i[1024 * 8]; float input_f[1024]; float output_f[1024 * 8]; double ratio_max_deviation = 0.0; if (argc < 3 || argc > 4) { fprintf(stderr, "Usage: %s <in-rate> <out-rate> [ratio deviation] (max ratio: 8.0)\n", argv[0]); return 1; } else if (argc == 4) { ratio_max_deviation = fabs(strtod(argv[3], NULL)); fprintf(stderr, "Ratio deviation: %.4f.\n", ratio_max_deviation); } double in_rate = strtod(argv[1], NULL); double out_rate = strtod(argv[2], NULL); double ratio = out_rate / in_rate; if (ratio >= 7.99) { fprintf(stderr, "Ratio is too high.\n"); return 1; } const rarch_resampler_t *resampler = NULL; void *re = NULL; if (!rarch_resampler_realloc(&re, &resampler, RESAMPLER_IDENT, out_rate / in_rate)) { fprintf(stderr, "Failed to allocate resampler ...\n"); return 1; } for (;;) { if (fread(input_i, sizeof(int16_t), 1024, stdin) != 1024) break; double uniform = (2.0 * rand()) / RAND_MAX - 1.0; double rate_mod = 1.0 + ratio_max_deviation * uniform; audio_convert_s16_to_float(input_f, input_i, 1024, 1.0f); struct resampler_data data = { .data_in = input_f, .data_out = output_f, .input_frames = sizeof(input_f) / (2 * sizeof(float)), .ratio = ratio * rate_mod, }; rarch_resampler_process(resampler, re, &data); size_t output_samples = data.output_frames * 2; audio_convert_float_to_s16(output_i, output_f, output_samples); if (fwrite(output_i, sizeof(int16_t), output_samples, stdout) != output_samples) break; } rarch_resampler_freep(&resampler, &re); }