Re-do the way the libretro port does audio. Audio is now sent to libretro at 384KHz, which is then resampled to whatever rate the user configured.
This commit is contained in:
parent
5c16d0e656
commit
130c7c28c2
@ -6,7 +6,8 @@
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define AUDIO_FREQUENCY 44100
|
||||
#define AUDIO_FREQUENCY 384000
|
||||
#define FRAME_RATE (0x400000 / 70224.0)
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
@ -18,9 +19,9 @@
|
||||
#include "libretro.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
char slash = '\\';
|
||||
char slash = '\\';
|
||||
#else
|
||||
char slash = '/';
|
||||
char slash = '/';
|
||||
#endif
|
||||
|
||||
#define VIDEO_WIDTH 160
|
||||
@ -39,7 +40,7 @@ static retro_audio_sample_batch_t audio_batch_cb;
|
||||
static retro_input_poll_t input_poll_cb;
|
||||
static retro_input_state_t input_state_cb;
|
||||
|
||||
signed short soundbuf[1024*2];
|
||||
signed short soundbuf[1024 * 2];
|
||||
|
||||
char retro_system_directory[4096];
|
||||
char retro_save_directory[4096];
|
||||
@ -103,15 +104,24 @@ static void GB_update_keys_status(GB_gameboy_t *gb)
|
||||
|
||||
static void audio_callback(void *gb)
|
||||
{
|
||||
GB_apu_copy_buffer(gb, (GB_sample_t *) soundbuf, (float)AUDIO_FREQUENCY / 59.72);
|
||||
audio_batch_cb(soundbuf, (float)AUDIO_FREQUENCY / 59.72);
|
||||
size_t length = GB_apu_get_current_buffer_length(gb);
|
||||
|
||||
while (length > sizeof(soundbuf) / 4)
|
||||
{
|
||||
GB_apu_copy_buffer(gb, (GB_sample_t *) soundbuf, 1024);
|
||||
audio_batch_cb(soundbuf, 1024);
|
||||
length -= 1024;
|
||||
}
|
||||
if (length) {
|
||||
GB_apu_copy_buffer(gb, (GB_sample_t *) soundbuf, length);
|
||||
audio_batch_cb(soundbuf, length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void vblank(GB_gameboy_t *gb)
|
||||
{
|
||||
GB_update_keys_status(gb);
|
||||
GB_set_pixels_output(gb, frame_buf);
|
||||
audio_callback(gb);
|
||||
}
|
||||
|
||||
@ -180,7 +190,7 @@ void retro_get_system_info(struct retro_system_info *info)
|
||||
void retro_get_system_av_info(struct retro_system_av_info *info)
|
||||
{
|
||||
struct retro_game_geometry geom = { VIDEO_WIDTH, VIDEO_HEIGHT,VIDEO_WIDTH, VIDEO_HEIGHT ,160.0 / 144.0 };
|
||||
struct retro_system_timing timing = { 59.72, 44100.0 };
|
||||
struct retro_system_timing timing = { FRAME_RATE, AUDIO_FREQUENCY };
|
||||
|
||||
info->geometry = geom;
|
||||
info->timing = timing;
|
||||
@ -269,20 +279,10 @@ static void check_variables(void)
|
||||
|
||||
void retro_run(void)
|
||||
{
|
||||
static int frames;
|
||||
size_t samples;
|
||||
|
||||
bool updated = false;
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
|
||||
check_variables();
|
||||
samples = GB_apu_get_current_buffer_length(&gb);
|
||||
if (!(frames < (samples / 35112)))
|
||||
{
|
||||
GB_run_frame(&gb);
|
||||
frames ++;
|
||||
}
|
||||
else
|
||||
frames = 0;
|
||||
|
||||
video_cb(frame_buf, VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_WIDTH * sizeof(uint32_t));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user