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

@@ -1,186 +1,5 @@
#define NCoef 2
/* fc=350Hz */
static inline float low_iir(int i, float NewSample) {
float ACoef[NCoef+1] = {
0.00049713569693400649,
0.00099427139386801299,
0.00049713569693400649
};
float BCoef[NCoef+1] = {
1.00000000000000000000,
-1.93522955470669530000,
0.93726236021404663000
};
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=350Hz */
static inline float low_cut_iir(int i, float NewSample) {
float ACoef[NCoef+1] = {
0.96839970114733542000,
-1.93679940229467080000,
0.96839970114733542000
};
float BCoef[NCoef+1] = {
1.00000000000000000000,
-1.93522955471202770000,
0.93726236021916731000
};
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=3.5kHz */
static inline float high_iir(int i, float NewSample) {
float ACoef[NCoef+1] = {
0.72248704753064896000,
-1.44497409506129790000,
0.72248704753064896000
};
float BCoef[NCoef+1] = {
1.00000000000000000000,
-1.36640781670578510000,
0.52352474706139873000
};
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=3.5kHz */
static inline float high_cut_iir(int i, float NewSample) {
float ACoef[NCoef+1] = {
0.03927726802250377400,
0.07855453604500754700,
0.03927726802250377400
};
float BCoef[NCoef+1] = {
1.00000000000000000000,
-1.36640781666419950000,
0.52352474703279628000
};
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];
}
#undef NCoef
#define NCoef 2
/* fc=3.2kHz */
static inline float sb_iir(int i, float NewSample) {
float ACoef[NCoef+1] = {
0.03356837051492005100,
0.06713674102984010200,
0.03356837051492005100
};
float BCoef[NCoef+1] = {
1.00000000000000000000,
-1.41898265221812010000,
0.55326988968868285000
};
/* float ACoef[NCoef+1] = {
0.17529642630084405000,
0.17529642630084405000
};
float BCoef[NCoef+1] = {
1.00000000000000000000,
-0.64940759319751051000
};*/
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];
}
#undef NCoef
#define NCoef 2
/* fc=150Hz */
static inline float adgold_highpass_iir(int i, float NewSample) {
float ACoef[NCoef+1] = {
@@ -347,30 +166,204 @@ static inline float dac_iir(int i, float NewSample) {
}
#undef NCoef
#define NCoef 2
/* fc=350Hz */
static inline double low_iir(int c, int i, double NewSample) {
double ACoef[NCoef+1] = {
0.00049713569693400649,
0.00099427139386801299,
0.00049713569693400649
};
double BCoef[NCoef+1] = {
1.00000000000000000000,
-1.93522955470669530000,
0.93726236021404663000
};
static double y[2][2][NCoef+1]; /* output samples */
static double 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=350Hz */
static inline double low_cut_iir(int c, int i, double NewSample) {
double ACoef[NCoef+1] = {
0.96839970114733542000,
-1.93679940229467080000,
0.96839970114733542000
};
double BCoef[NCoef+1] = {
1.00000000000000000000,
-1.93522955471202770000,
0.93726236021916731000
};
static double y[2][2][NCoef+1]; /* output samples */
static double 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=3.5kHz */
static inline double high_iir(int c, int i, double NewSample) {
double ACoef[NCoef+1] = {
0.72248704753064896000,
-1.44497409506129790000,
0.72248704753064896000
};
double BCoef[NCoef+1] = {
1.00000000000000000000,
-1.36640781670578510000,
0.52352474706139873000
};
static double y[2][2][NCoef+1]; /* output samples */
static double 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=3.5kHz */
static inline double high_cut_iir(int c, int i, double NewSample) {
double ACoef[NCoef+1] = {
0.03927726802250377400,
0.07855453604500754700,
0.03927726802250377400
};
double BCoef[NCoef+1] = {
1.00000000000000000000,
-1.36640781666419950000,
0.52352474703279628000
};
static double y[2][2][NCoef+1]; /* output samples */
static double 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];
}
#undef NCoef
#define NCoef 2
/* fc=3.2kHz */
static inline double sb_iir(int c, int i, double NewSample) {
double ACoef[NCoef+1] = {
0.03356837051492005100,
0.06713674102984010200,
0.03356837051492005100
};
double BCoef[NCoef+1] = {
1.00000000000000000000,
-1.41898265221812010000,
0.55326988968868285000
};
static double y[2][2][NCoef+1]; /* output samples */
static double 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];
}
#undef NCoef
#define NCoef 1
#define SB16_NCoef 51
extern float low_fir_sb16_coef[SB16_NCoef];
extern double low_fir_sb16_coef[2][SB16_NCoef];
static inline float low_fir_sb16(int i, float NewSample)
static inline double low_fir_sb16(int c, int i, double NewSample)
{
static float x[2][SB16_NCoef+1]; //input samples
static int pos = 0;
float out = 0.0;
static double x[2][2][SB16_NCoef+1]; //input samples
static int pos[2] = { 0, 0 };
double out = 0.0;
int n;
/* Calculate the new output */
x[i][pos] = NewSample;
x[c][i][pos[c]] = NewSample;
for (n = 0; n < ((SB16_NCoef+1)-pos) && n < SB16_NCoef; n++)
out += low_fir_sb16_coef[n] * x[i][n+pos];
for (n = 0; n < ((SB16_NCoef+1)-pos[c]) && n < SB16_NCoef; n++)
out += low_fir_sb16_coef[c][n] * x[c][i][n+pos[c]];
for (; n < SB16_NCoef; n++)
out += low_fir_sb16_coef[n] * x[i][(n+pos) - (SB16_NCoef+1)];
out += low_fir_sb16_coef[c][n] * x[c][i][(n+pos[c]) - (SB16_NCoef+1)];
if (i == 1)
{
pos++;
if (pos > SB16_NCoef)
pos = 0;
pos[c]++;
if (pos[c] > SB16_NCoef)
pos[c] = 0;
}
return out;

View File

@@ -37,10 +37,10 @@
/* SB 2.0 CD version */
typedef struct sb_ct1335_mixer_t
{
int32_t master;
int32_t voice;
int32_t fm;
int32_t cd;
double master;
double voice;
double fm;
double cd;
uint8_t index;
uint8_t regs[256];
@@ -48,12 +48,12 @@ typedef struct sb_ct1335_mixer_t
/* SB PRO */
typedef struct sb_ct1345_mixer_t
{
int32_t master_l, master_r;
int32_t voice_l, voice_r;
int32_t fm_l, fm_r;
int32_t cd_l, cd_r;
int32_t line_l, line_r;
int32_t mic;
double master_l, master_r;
double voice_l, voice_r;
double fm_l, fm_r;
double cd_l, cd_r;
double line_l, line_r;
double mic;
/*see sb_ct1745_mixer for values for input selector*/
int32_t input_selector;
@@ -71,13 +71,13 @@ typedef struct sb_ct1345_mixer_t
/* SB16 and AWE32 */
typedef struct sb_ct1745_mixer_t
{
int32_t master_l, master_r;
int32_t voice_l, voice_r;
int32_t fm_l, fm_r;
int32_t cd_l, cd_r;
int32_t line_l, line_r;
int32_t mic;
int32_t speaker;
double master_l, master_r;
double voice_l, voice_r;
double fm_l, fm_r;
double cd_l, cd_r;
double line_l, line_r;
double mic;
double speaker;
int bass_l, bass_r;
int treble_l, treble_r;
@@ -103,8 +103,8 @@ typedef struct sb_ct1745_mixer_t
int32_t input_gain_L;
int32_t input_gain_R;
int32_t output_gain_L;
int32_t output_gain_R;
double output_gain_L;
double output_gain_R;
uint8_t index;
uint8_t regs[256];
@@ -112,7 +112,7 @@ typedef struct sb_ct1745_mixer_t
typedef struct sb_t
{
uint8_t opl_enabled;
uint8_t opl_enabled, mixer_enabled;
opl_t opl, opl2;
sb_dsp_t dsp;
union {
@@ -133,6 +133,7 @@ extern uint8_t sb_ct1345_mixer_read(uint16_t addr, void *p);
extern void sb_ct1345_mixer_reset(sb_t* sb);
extern void sb_get_buffer_sbpro(int32_t *buffer, int len, void *p);
extern void sbpro_filter_cd_audio(int channel, double *buffer, void *p);
extern void sb_close(void *p);
extern void sb_speed_changed(void *p);

View File

@@ -46,7 +46,7 @@ extern int sound_card_current;
extern void sound_add_handler(void (*get_buffer)(int32_t *buffer, \
int len, void *p), void *p);
extern void sound_set_cd_audio_filter(void (*filter)(int channel, \
float *buffer, void *p), void *p);
double *buffer, void *p), void *p);
extern int sound_card_available(int card);
extern char *sound_card_getname(int card);