Moved OPL2 and OPL3 to a new 49716 Hz source so resampling is no longer needed, also fixed SB OPL and PC Speaker filtering (OPL was being downsampled to the selected DSP sample rate, which is incorrect, and the PC Speaker filter was using the wrong filter index in some liens).

This commit is contained in:
OBattler
2024-03-01 06:52:48 +01:00
parent 71ecdc1b55
commit e0d80aefb4
18 changed files with 683 additions and 193 deletions

View File

@@ -53,9 +53,11 @@ typedef struct {
int sound_card_current[SOUND_CARD_MAX] = { 0, 0, 0, 0 };
int sound_pos_global = 0;
int music_pos_global = 0;
int sound_gain = 0;
static sound_handler_t sound_handlers[8];
static sound_handler_t music_handlers[8];
static thread_t *sound_cd_thread_h;
static event_t *sound_cd_event;
@@ -63,9 +65,15 @@ static event_t *sound_cd_start_event;
static int32_t *outbuffer;
static float *outbuffer_ex;
static int16_t *outbuffer_ex_int16;
static int32_t *outbuffer_m;
static float *outbuffer_m_ex;
static int16_t *outbuffer_m_ex_int16;
static int sound_handlers_num;
static int music_handlers_num;
static pc_timer_t sound_poll_timer;
static uint64_t sound_poll_latch;
static pc_timer_t music_poll_timer;
static uint64_t music_poll_latch;
static int16_t cd_buffer[CDROM_NUM][CD_BUFLEN * 2];
static float cd_out_buffer[CD_BUFLEN * 2];
@@ -395,6 +403,28 @@ sound_realloc_buffers(void)
}
}
static void
music_realloc_buffers(void)
{
if (outbuffer_m_ex != NULL) {
free(outbuffer_m_ex);
outbuffer_m_ex = NULL;
}
if (outbuffer_m_ex_int16 != NULL) {
free(outbuffer_m_ex_int16);
outbuffer_m_ex_int16 = NULL;
}
if (sound_is_float) {
outbuffer_m_ex = calloc(MUSICBUFLEN * 2, sizeof(float));
memset(outbuffer_m_ex, 0x00, MUSICBUFLEN * 2 * sizeof(float));
} else {
outbuffer_m_ex_int16 = calloc(MUSICBUFLEN * 2, sizeof(int16_t));
memset(outbuffer_m_ex_int16, 0x00, MUSICBUFLEN * 2 * sizeof(int16_t));
}
}
void
sound_init(void)
{
@@ -403,10 +433,18 @@ sound_init(void)
outbuffer_ex = NULL;
outbuffer_ex_int16 = NULL;
outbuffer_m_ex = NULL;
outbuffer_m_ex_int16 = NULL;
outbuffer = NULL;
outbuffer = calloc(SOUNDBUFLEN * 2, sizeof(int32_t));
memset(outbuffer, 0x00, SOUNDBUFLEN * 2 * sizeof(int32_t));
outbuffer_m = NULL;
outbuffer_m = calloc(MUSICBUFLEN * 2, sizeof(int32_t));
memset(outbuffer_m, 0x00, MUSICBUFLEN * 2 * sizeof(int32_t));
for (uint8_t i = 0; i < CDROM_NUM; i++) {
if (cdrom[i].bus_type != CDROM_BUS_DISABLED)
available_cdrom_drives++;
@@ -438,6 +476,14 @@ sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *priv), void
sound_handlers_num++;
}
void
music_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *priv), void *priv)
{
music_handlers[music_handlers_num].get_buffer = get_buffer;
music_handlers[music_handlers_num].priv = priv;
music_handlers_num++;
}
void
sound_set_cd_audio_filter(void (*filter)(int channel, double *buffer, void *priv), void *priv)
{
@@ -502,10 +548,48 @@ sound_poll(UNUSED(void *priv))
}
}
void
music_poll(UNUSED(void *priv))
{
timer_advance_u64(&music_poll_timer, music_poll_latch);
music_pos_global++;
if (music_pos_global == MUSICBUFLEN) {
int c;
memset(outbuffer_m, 0x00, MUSICBUFLEN * 2 * sizeof(int32_t));
for (c = 0; c < music_handlers_num; c++)
music_handlers[c].get_buffer(outbuffer_m, MUSICBUFLEN, music_handlers[c].priv);
for (c = 0; c < MUSICBUFLEN * 2; c++) {
if (sound_is_float)
outbuffer_m_ex[c] = ((float) outbuffer_m[c]) / (float) 32768.0;
else {
if (outbuffer_m[c] > 32767)
outbuffer_m[c] = 32767;
if (outbuffer_m[c] < -32768)
outbuffer_m[c] = -32768;
outbuffer_m_ex_int16[c] = outbuffer_m[c];
}
}
if (sound_is_float)
givealbuffer_music(outbuffer_m_ex);
else
givealbuffer_music(outbuffer_m_ex_int16);
music_pos_global = 0;
}
}
void
sound_speed_changed(void)
{
sound_poll_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / (double) SOUND_FREQ));
music_poll_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / (double) MUSIC_FREQ));
}
void
@@ -513,6 +597,8 @@ sound_reset(void)
{
sound_realloc_buffers();
music_realloc_buffers();
midi_out_device_init();
midi_in_device_init();
@@ -523,6 +609,11 @@ sound_reset(void)
sound_handlers_num = 0;
memset(sound_handlers, 0x00, 8 * sizeof(sound_handler_t));
timer_add(&music_poll_timer, music_poll, NULL, 1);
music_handlers_num = 0;
memset(music_handlers, 0x00, 8 * sizeof(sound_handler_t));
filter_cd_audio = NULL;
filter_cd_audio_p = NULL;