Sound improvements, especially CD Audio and the Sound Blasters.

This commit is contained in:
OBattler
2020-10-21 02:46:50 +02:00
parent baee7c1530
commit 6e013acf95
9 changed files with 1457 additions and 1471 deletions

View File

@@ -221,14 +221,14 @@ static void ad1848_poll(void *p)
}
}
static void ad1848_filter_cd_audio(int channel, float *buffer, void *p)
static void ad1848_filter_cd_audio(int channel, double *buffer, void *p)
{
ad1848_t *ad1848 = (ad1848_t *)p;
int32_t c;
uint32_t volume = channel ? ad1848->cd_vol_r : ad1848->cd_vol_l;
c = (((int32_t) *buffer) * volume) >> 16;
*buffer = (float) c;
*buffer = (double) c;
}
void ad1848_init(ad1848_t *ad1848, int type)

View File

@@ -1274,7 +1274,7 @@ static void es1371_get_buffer(int32_t *buffer, int len, void *p)
es1371->pos = 0;
}
static void es1371_filter_cd_audio(int channel, float *buffer, void *p)
static void es1371_filter_cd_audio(int channel, double *buffer, void *p)
{
es1371_t *es1371 = (es1371_t *)p;
int32_t c;
@@ -1284,7 +1284,7 @@ static void es1371_filter_cd_audio(int channel, float *buffer, void *p)
c = (((int32_t) *buffer) * cd) >> 15;
c = (c * master) >> 15;
*buffer = (float) c;
*buffer = (double) c;
}
static inline double sinc(double x)

View File

@@ -1172,6 +1172,7 @@ azt_init(const device_t *info)
azt2316a_create_config_word(azt2316a);
sound_add_handler(azt2316a_get_buffer, azt2316a);
sound_set_cd_audio_filter(sbpro_filter_cd_audio, azt2316a->sb);
if (azt2316a->cur_mpu401_enabled) {
azt2316a->mpu = (mpu_t *) malloc(sizeof(mpu_t));

File diff suppressed because it is too large Load Diff

View File

@@ -117,7 +117,7 @@ uint8_t adjustMap2[24] = {
252, 0, 252, 0
};
float low_fir_sb16_coef[SB16_NCoef];
double low_fir_sb16_coef[2][SB16_NCoef];
#ifdef ENABLE_SB_DSP_LOG
@@ -147,13 +147,15 @@ sinc(double x)
}
static void
recalc_sb16_filter(int playback_freq)
recalc_sb16_filter(int c, int playback_freq)
{
/* Cutoff frequency = playback / 2 */
float fC = ((float)playback_freq / 2.0) / 48000.0;
float gain;
int n;
double w, h;
double fC = ((double) playback_freq) / 96000.0;
double gain;
pclog("recalc_sb16_filter(%i, %i)\n", c, playback_freq);
for (n = 0; n < SB16_NCoef; n++) {
/* Blackman window */
@@ -162,18 +164,18 @@ recalc_sb16_filter(int playback_freq)
h = sinc(2.0 * fC * ((double)n - ((double)(SB16_NCoef-1) / 2.0)));
/* Create windowed-sinc filter */
low_fir_sb16_coef[n] = w * h;
low_fir_sb16_coef[c][n] = w * h;
}
low_fir_sb16_coef[(SB16_NCoef - 1) / 2] = 1.0;
low_fir_sb16_coef[c][(SB16_NCoef - 1) / 2] = 1.0;
gain = 0.0;
for (n = 0; n < SB16_NCoef; n++)
gain += low_fir_sb16_coef[n];
gain += low_fir_sb16_coef[c][n];
/* Normalise filter, to produce unity gain */
for (n = 0; n < SB16_NCoef; n++)
low_fir_sb16_coef[n] /= gain;
low_fir_sb16_coef[c][n] /= gain;
}
@@ -555,7 +557,7 @@ sb_exec_command(sb_dsp_t *dsp)
temp = 1000000 / temp;
sb_dsp_log("Sample rate - %ihz (%i)\n",temp, dsp->sblatcho);
if ((dsp->sb_freq != temp) && (dsp->sb_type >= SB16))
recalc_sb16_filter(temp);
recalc_sb16_filter(0, temp);
dsp->sb_freq = temp;
break;
case 0x41: /* Set output sampling rate */
@@ -569,7 +571,7 @@ sb_exec_command(sb_dsp_t *dsp)
dsp->sblatchi = dsp->sblatcho;
dsp->sb_timei = dsp->sb_timeo;
if (dsp->sb_freq != temp && dsp->sb_type >= SB16)
recalc_sb16_filter(dsp->sb_freq);
recalc_sb16_filter(0, dsp->sb_freq);
}
break;
case 0x48: /* Set DSP block transfer size */
@@ -1046,7 +1048,8 @@ sb_dsp_init(sb_dsp_t *dsp, int type, int subtype, void *parent)
/* Initialise SB16 filter to same cutoff as 8-bit SBs (3.2 kHz). This will be recalculated when
a set frequency command is sent. */
recalc_sb16_filter(3200*2);
recalc_sb16_filter(0, 3200*2);
recalc_sb16_filter(1, 44100);
}

View File

@@ -77,7 +77,7 @@ static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN;
static volatile int cdaudioon = 0;
static int cd_thread_enable = 0;
static void (*filter_cd_audio)(int channel, float *buffer, void *p) = NULL;
static void (*filter_cd_audio)(int channel, double *buffer, void *p) = NULL;
static void *filter_cd_audio_p = NULL;
@@ -215,8 +215,8 @@ static void
sound_cd_thread(void *param)
{
int c, r, i, channel_select[2];
float audio_vol_l, audio_vol_r;
float cd_buffer_temp[2] = {0.0, 0.0};
double audio_vol_l, audio_vol_r;
double cd_buffer_temp[2] = {0.0, 0.0};
thread_set_event(sound_cd_start_event);
@@ -274,18 +274,18 @@ sound_cd_thread(void *param)
if ((audio_vol_l != 0.0) && (channel_select[0] != 0)) {
if (channel_select[0] & 1)
cd_buffer_temp[0] += ((float) cd_buffer[i][c]); /* Channel 0 => Port 0 */
cd_buffer_temp[0] += ((double) cd_buffer[i][c]); /* Channel 0 => Port 0 */
if (channel_select[0] & 2)
cd_buffer_temp[0] += ((float) cd_buffer[i][c + 1]); /* Channel 1 => Port 0 */
cd_buffer_temp[0] += ((double) cd_buffer[i][c + 1]); /* Channel 1 => Port 0 */
cd_buffer_temp[0] *= audio_vol_l; /* Multiply Port 0 by Port 0 volume */
}
if ((audio_vol_r != 0.0) && (channel_select[1] != 0)) {
if (channel_select[1] & 1)
cd_buffer_temp[1] += ((float) cd_buffer[i][c]); /* Channel 0 => Port 1 */
cd_buffer_temp[1] += ((double) cd_buffer[i][c]); /* Channel 0 => Port 1 */
if (channel_select[1] & 2)
cd_buffer_temp[1] += ((float) cd_buffer[i][c + 1]); /* Channel 1 => Port 1 */
cd_buffer_temp[1] += ((double) cd_buffer[i][c + 1]); /* Channel 1 => Port 1 */
cd_buffer_temp[1] *= audio_vol_r; /* Multiply Port 1 by Port 1 volume */
}
@@ -297,8 +297,8 @@ sound_cd_thread(void *param)
}
if (sound_is_float) {
cd_out_buffer[c] += (cd_buffer_temp[0] / 32768.0);
cd_out_buffer[c+1] += (cd_buffer_temp[1] / 32768.0);
cd_out_buffer[c] += (float) (cd_buffer_temp[0] / 32768.0);
cd_out_buffer[c+1] += (float) (cd_buffer_temp[1] / 32768.0);
} else {
if (cd_buffer_temp[0] > 32767)
cd_buffer_temp[0] = 32767;
@@ -309,8 +309,8 @@ sound_cd_thread(void *param)
if (cd_buffer_temp[1] < -32768)
cd_buffer_temp[1] = -32768;
cd_out_buffer_int16[c] += cd_buffer_temp[0];
cd_out_buffer_int16[c+1] += cd_buffer_temp[1];
cd_out_buffer_int16[c] += (int16_t) cd_buffer_temp[0];
cd_out_buffer_int16[c+1] += (int16_t) cd_buffer_temp[1];
}
}
}
@@ -384,7 +384,7 @@ sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p
void
sound_set_cd_audio_filter(void (*filter)(int channel, float *buffer, void *p), void *p)
sound_set_cd_audio_filter(void (*filter)(int channel, double *buffer, void *p), void *p)
{
if ((filter_cd_audio == NULL) || (filter == NULL)) {
filter_cd_audio = filter;