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

@@ -5,7 +5,7 @@
/* fc=150Hz */
static inline float
adgold_highpass_iir(int i, float NewSample)
adgold_highpass_iir(int c, int i, float NewSample)
{
float ACoef[NCoef + 1] = {
0.98657437157334349000,
@@ -19,28 +19,28 @@ adgold_highpass_iir(int i, float NewSample)
0.97261396931534050000
};
static float y[2][NCoef + 1]; /* output samples */
static float x[2][NCoef + 1]; /* input samples */
static float y[2][2][NCoef + 1]; /* output samples */
static float x[2][2][NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
for (n = NCoef; n > 0; n--) {
x[i][n] = x[i][n - 1];
y[i][n] = y[i][n - 1];
x[c][i][n] = x[c][i][n - 1];
y[c][i][n] = y[c][i][n - 1];
}
/* Calculate the new output */
x[i][0] = NewSample;
y[i][0] = ACoef[0] * x[i][0];
x[c][i][0] = NewSample;
y[c][i][0] = ACoef[0] * x[c][i][0];
for (n = 1; n <= NCoef; n++)
y[i][0] += ACoef[n] * x[i][n] - BCoef[n] * y[i][n];
y[c][i][0] += ACoef[n] * x[c][i][n] - BCoef[n] * y[c][i][n];
return y[i][0];
return y[c][i][0];
}
/* fc=150Hz */
static inline float
adgold_lowpass_iir(int i, float NewSample)
adgold_lowpass_iir(int c, int i, float NewSample)
{
float ACoef[NCoef + 1] = {
0.00009159473951071446,
@@ -54,23 +54,23 @@ adgold_lowpass_iir(int i, float NewSample)
0.97261396931306277000
};
static float y[2][NCoef + 1]; /* output samples */
static float x[2][NCoef + 1]; /* input samples */
static float y[2][2][NCoef + 1]; /* output samples */
static float x[2][2][NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
for (n = NCoef; n > 0; n--) {
x[i][n] = x[i][n - 1];
y[i][n] = y[i][n - 1];
x[c][i][n] = x[c][i][n - 1];
y[c][i][n] = y[c][i][n - 1];
}
/* Calculate the new output */
x[i][0] = NewSample;
y[i][0] = ACoef[0] * x[i][0];
x[c][i][0] = NewSample;
y[c][i][0] = ACoef[0] * x[c][i][0];
for (n = 1; n <= NCoef; n++)
y[i][0] += ACoef[n] * x[i][n] - BCoef[n] * y[i][n];
y[c][i][0] += ACoef[n] * x[c][i][n] - BCoef[n] * y[c][i][n];
return y[i][0];
return y[c][i][0];
}
/* fc=56Hz */
@@ -197,8 +197,8 @@ low_iir(int c, int i, double NewSample)
0.93726236021404663000
};
static double y[3][2][NCoef + 1]; /* output samples */
static double x[3][2][NCoef + 1]; /* input samples */
static double y[4][2][NCoef + 1]; /* output samples */
static double x[4][2][NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
@@ -232,8 +232,8 @@ low_cut_iir(int c, int i, double NewSample)
0.93726236021916731000
};
static double y[3][2][NCoef + 1]; /* output samples */
static double x[3][2][NCoef + 1]; /* input samples */
static double y[4][2][NCoef + 1]; /* output samples */
static double x[4][2][NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
@@ -266,8 +266,8 @@ high_iir(int c, int i, double NewSample)
-1.36640781670578510000,
0.52352474706139873000
};
static double y[3][2][NCoef + 1]; /* output samples */
static double x[3][2][NCoef + 1]; /* input samples */
static double y[4][2][NCoef + 1]; /* output samples */
static double x[4][2][NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
@@ -300,8 +300,8 @@ high_cut_iir(int c, int i, double NewSample)
-1.36640781666419950000,
0.52352474703279628000
};
static double y[3][2][NCoef + 1]; /* output samples */
static double x[3][2][NCoef + 1]; /* input samples */
static double y[4][2][NCoef + 1]; /* output samples */
static double x[4][2][NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
@@ -334,8 +334,8 @@ deemph_iir(int i, double NewSample)
-1.05429146278569141337,
0.26412280202756849290
};
static double y[3][NCoef + 1]; /* output samples */
static double x[3][NCoef + 1]; /* input samples */
static double y[4][NCoef + 1]; /* output samples */
static double x[4][NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
@@ -372,8 +372,8 @@ sb_iir(int c, int i, double NewSample)
0.55326988968868285000
};
static double y[3][2][NCoef + 1]; /* output samples */
static double x[3][2][NCoef + 1]; /* input samples */
static double y[4][2][NCoef + 1]; /* output samples */
static double x[4][2][NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
@@ -395,13 +395,13 @@ sb_iir(int c, int i, double NewSample)
#define NCoef 1
#define SB16_NCoef 51
extern double low_fir_sb16_coef[3][SB16_NCoef];
extern double low_fir_sb16_coef[4][SB16_NCoef];
static inline double
low_fir_sb16(int c, int i, double NewSample)
{
static double x[3][2][SB16_NCoef + 1]; // input samples
static int pos[3] = { 0, 0 };
static double x[4][2][SB16_NCoef + 1]; // input samples
static int pos[4] = { 0, 0, 0, 0 };
double out = 0.0;
int n;

View File

@@ -143,7 +143,6 @@ typedef struct sb_t {
emu8k_t emu8k;
void *gameport;
int pos;
int pnp;
uint8_t pos_regs[8];
@@ -165,6 +164,7 @@ extern uint8_t sb_ct1745_mixer_read(uint16_t addr, void *priv);
extern void sb_ct1745_mixer_reset(sb_t *sb);
extern void sb_get_buffer_sbpro(int32_t *buffer, int len, void *priv);
extern void sb_get_music_buffer_sbpro(int32_t *buffer, int len, void *priv);
extern void sbpro_filter_cd_audio(int channel, double *buffer, void *priv);
extern void sb16_awe32_filter_cd_audio(int channel, double *buffer, void *priv);
extern void sb_close(void *priv);

View File

@@ -97,6 +97,8 @@ typedef struct sb_dsp_t {
int sb_irqm16;
int sb_irqm401;
uint8_t sb_has_real_opl;
uint8_t sb_asp_regs[256];
uint8_t sb_asp_mode;
@@ -158,6 +160,8 @@ extern void sb_dsp_speed_changed(sb_dsp_t *dsp);
extern void sb_dsp_poll(sb_dsp_t *dsp, int16_t *l, int16_t *r);
extern void sb_dsp_set_real_opl(sb_dsp_t *dsp, uint8_t has_real_opl);
extern void sb_dsp_set_stereo(sb_dsp_t *dsp, int stereo);
extern void sb_dsp_update(sb_dsp_t *dsp);

View File

@@ -33,6 +33,9 @@ extern int sound_gain;
#define SOUND_FREQ FREQ_48000
#define SOUNDBUFLEN (SOUND_FREQ / 50)
#define MUSIC_FREQ FREQ_49716
#define MUSICBUFLEN (MUSIC_FREQ / 36)
#define CD_FREQ FREQ_44100
#define CD_BUFLEN (CD_FREQ / 10)
@@ -47,12 +50,18 @@ extern int speakval;
extern int speakon;
extern int sound_pos_global;
extern int music_pos_global;
extern int sound_card_current[SOUND_CARD_MAX];
extern void sound_add_handler(void (*get_buffer)(int32_t *buffer,
int len, void *priv),
void *priv);
extern void music_add_handler(void (*get_buffer)(int32_t *buffer,
int len, void *priv),
void *priv);
extern void sound_set_cd_audio_filter(void (*filter)(int channel,
double *buffer, void *priv),
void *priv);
@@ -86,6 +95,7 @@ extern void sound_cd_thread_reset(void);
extern void closeal(void);
extern void inital(void);
extern void givealbuffer(void *buf);
extern void givealbuffer_music(void *buf);
extern void givealbuffer_cd(void *buf);
#define sb_vibra16c_onboard_relocate_base sb_vibra16s_onboard_relocate_base