AdLib Gold: Everything now outputs to the same 48k source in order to avoid noise caused by the YM7128's resampling which is currently tailored to that frequency.

This commit is contained in:
OBattler
2025-09-28 00:44:01 +02:00
parent bc41f8bbb6
commit 6ca6afedd5
9 changed files with 291 additions and 321 deletions

View File

@@ -5,7 +5,7 @@
/* fc=150Hz */
static inline float
adgold_highpass_iir(int c, int i, float NewSample)
adgold_highpass_iir(int i, float NewSample)
{
float ACoef[NCoef + 1] = {
0.98657437157334349000,
@@ -19,76 +19,6 @@ adgold_highpass_iir(int c, int i, float NewSample)
0.97261396931534050000
};
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[c][i][n] = x[c][i][n - 1];
y[c][i][n] = y[c][i][n - 1];
}
/* Calculate the new output */
x[c][i][0] = NewSample;
y[c][i][0] = ACoef[0] * x[c][i][0];
for (n = 1; n <= NCoef; n++)
y[c][i][0] += ACoef[n] * x[c][i][n] - BCoef[n] * y[c][i][n];
return y[c][i][0];
}
/* fc=150Hz */
static inline float
adgold_lowpass_iir(int c, int i, float NewSample)
{
float ACoef[NCoef + 1] = {
0.00009159473951071446,
0.00018318947902142891,
0.00009159473951071446
};
float BCoef[NCoef + 1] = {
1.00000000000000000000,
-1.97223372919526560000,
0.97261396931306277000
};
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[c][i][n] = x[c][i][n - 1];
y[c][i][n] = y[c][i][n - 1];
}
/* Calculate the new output */
x[c][i][0] = NewSample;
y[c][i][0] = ACoef[0] * x[c][i][0];
for (n = 1; n <= NCoef; n++)
y[c][i][0] += ACoef[n] * x[c][i][n] - BCoef[n] * y[c][i][n];
return y[c][i][0];
}
/* fc=56Hz */
static inline float
adgold_pseudo_stereo_iir(int i, float NewSample)
{
float ACoef[NCoef + 1] = {
0.00001409030866231767,
0.00002818061732463533,
0.00001409030866231767
};
float BCoef[NCoef + 1] = {
1.00000000000000000000,
-1.98733021473466760000,
0.98738361004063568000
};
static float y[2][NCoef + 1]; /* output samples */
static float x[2][NCoef + 1]; /* input samples */
int n;
@@ -108,6 +38,76 @@ adgold_pseudo_stereo_iir(int i, float NewSample)
return y[i][0];
}
/* fc=150Hz */
static inline float
adgold_lowpass_iir(int i, float NewSample)
{
float ACoef[NCoef + 1] = {
0.00009159473951071446,
0.00018318947902142891,
0.00009159473951071446
};
float BCoef[NCoef + 1] = {
1.00000000000000000000,
-1.97223372919526560000,
0.97261396931306277000
};
static float y[2][NCoef + 1]; /* output samples */
static float x[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];
}
/* Calculate the new output */
x[i][0] = NewSample;
y[i][0] = ACoef[0] * x[i][0];
for (n = 1; n <= NCoef; n++)
y[i][0] += ACoef[n] * x[i][n] - BCoef[n] * y[i][n];
return y[i][0];
}
/* fc=56Hz */
static inline float
adgold_pseudo_stereo_iir(float NewSample)
{
float ACoef[NCoef + 1] = {
0.00001409030866231767,
0.00002818061732463533,
0.00001409030866231767
};
float BCoef[NCoef + 1] = {
1.00000000000000000000,
-1.98733021473466760000,
0.98738361004063568000
};
static float y[NCoef + 1]; /* output samples */
static float x[NCoef + 1]; /* input samples */
int n;
/* shift the old samples */
for (n = NCoef; n > 0; n--) {
x[n] = x[n - 1];
y[n] = y[n - 1];
}
/* Calculate the new output */
x[0] = NewSample;
y[0] = ACoef[0] * x[0];
for (n = 1; n <= NCoef; n++)
y[0] += ACoef[n] * x[n] - BCoef[n] * y[n];
return y[0];
}
/* fc=3.2kHz - probably incorrect */
static inline float
dss_iir(float NewSample)

View File

@@ -49,6 +49,9 @@ enum fm_type {
FM_MAX = 26
};
#define FM_TYPE_MASK 255
#define FM_FORCE_48K 256
enum fm_driver {
FM_DRV_NUKED = 0,
FM_DRV_YMFM = 1,
@@ -65,9 +68,11 @@ typedef struct fm_drv_t {
void (*generate)(void *priv, int32_t *data, uint32_t num_samples); /* daughterboard only. */
} fm_drv_t;
extern uint8_t fm_driver_get_ex(int chip_id, fm_drv_t *drv, int is_48k);
extern uint8_t fm_driver_get(int chip_id, fm_drv_t *drv);
extern const fm_drv_t nuked_opl_drv;
extern const fm_drv_t nuked_opl_drv_48k;
extern const fm_drv_t ymfm_drv;
extern const fm_drv_t esfmu_opl_drv;
extern const fm_drv_t ymfm_opl2board_drv;

View File

@@ -147,7 +147,7 @@ struct _opl3_chip {
typedef struct {
opl3_chip opl;
int8_t flags;
int8_t pad;
int8_t is_48k;
uint16_t port;
uint8_t status;
@@ -159,6 +159,8 @@ typedef struct {
int pos;
int32_t buffer[MUSICBUFLEN * 2];
int32_t *(*update)(void *priv);
} nuked_drv_t;
enum {

View File

@@ -19,18 +19,18 @@ typedef struct ym7128_t {
int c1;
int t[9];
int16_t filter_dat[2];
int16_t prev_l[2];
int16_t prev_r[2];
int16_t filter_dat;
int16_t prev_l;
int16_t prev_r;
int16_t delay_buffer[2][2400];
int delay_pos[2];
int16_t delay_buffer[2400];
int delay_pos;
int16_t last_samp;
} ym7128_t;
void ym7128_init(ym7128_t *ym7128);
void ym7128_write(ym7128_t *ym7128, uint8_t val);
void ym7128_apply(ym7128_t *ym7128, int16_t *buffer, int i, int len);
void ym7128_apply(ym7128_t *ym7128, int16_t *buffer, int len);
#endif /*SOUND_YM7128_H*/