mirror of
https://github.com/Pecusx/libretro-atari800.git
synced 2026-05-20 22:33:22 +02:00
fix buzzing sound in audio
This commit is contained in:
+25
-16
@@ -264,6 +264,11 @@ typedef struct stPokeyState
|
|||||||
|
|
||||||
} PokeyState;
|
} PokeyState;
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
double s16;
|
||||||
|
double s8;
|
||||||
|
} volume;
|
||||||
|
|
||||||
PokeyState pokey_states[NPOKEYS];
|
PokeyState pokey_states[NPOKEYS];
|
||||||
|
|
||||||
/* Forward declarations for ResetPokeyState */
|
/* Forward declarations for ResetPokeyState */
|
||||||
@@ -1421,6 +1426,10 @@ int MZPOKEYSND_Init(ULONG freq17, int playback_freq, UBYTE num_pokeys,
|
|||||||
#ifdef SYNCHRONIZED_SOUND
|
#ifdef SYNCHRONIZED_SOUND
|
||||||
init_syncsound();
|
init_syncsound();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
volume.s8 = POKEYSND_volume * 0xff / 256.0;
|
||||||
|
volume.s16 = POKEYSND_volume * 0xffff / 256.0;
|
||||||
|
|
||||||
return 0; /* OK */
|
return 0; /* OK */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2341,16 +2350,16 @@ static void mzpokeysnd_process_8(void* sndbuffer, int sndn)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VOL_ONLY_SOUND
|
#ifdef VOL_ONLY_SOUND
|
||||||
buffer[0] = (UBYTE)floor((generate_sample(pokey_states) + POKEYSND_sampout - MAX_SAMPLE / 2.0)
|
buffer[0] = (UBYTE)floor((generate_sample(pokey_states) + POKEYSND_sampout)
|
||||||
* (255.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
* (255.0 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
||||||
#else
|
#else
|
||||||
buffer[0] = (UBYTE)floor((generate_sample(pokey_states) - MAX_SAMPLE / 2.0)
|
buffer[0] = (UBYTE)floor(generate_sample(pokey_states)
|
||||||
* (255.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
* (255.0 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
||||||
#endif
|
#endif
|
||||||
for(i=1; i<num_cur_pokeys; i++)
|
for(i=1; i<num_cur_pokeys; i++)
|
||||||
{
|
{
|
||||||
buffer[i] = (UBYTE)floor((generate_sample(pokey_states + i) - MAX_SAMPLE / 2.0)
|
buffer[i] = (UBYTE)floor(generate_sample(pokey_states + i)
|
||||||
* (255.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
* (255.0 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
||||||
}
|
}
|
||||||
buffer += num_cur_pokeys;
|
buffer += num_cur_pokeys;
|
||||||
nsam -= num_cur_pokeys;
|
nsam -= num_cur_pokeys;
|
||||||
@@ -2389,16 +2398,16 @@ static void mzpokeysnd_process_16(void* sndbuffer, int sndn)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef VOL_ONLY_SOUND
|
#ifdef VOL_ONLY_SOUND
|
||||||
buffer[0] = (SWORD)floor((generate_sample(pokey_states) + POKEYSND_sampout - MAX_SAMPLE / 2.0)
|
buffer[0] = (SWORD)floor((generate_sample(pokey_states) + POKEYSND_sampout)
|
||||||
* (65535.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
* (65535.0 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95) + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
||||||
#else
|
#else
|
||||||
buffer[0] = (SWORD)floor((generate_sample(pokey_states) - MAX_SAMPLE / 2.0)
|
buffer[0] = (SWORD)floor(generate_sample(pokey_states)
|
||||||
* (65535.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
* (65535.0 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95) + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
||||||
#endif
|
#endif
|
||||||
for(i=1; i<num_cur_pokeys; i++)
|
for(i=1; i<num_cur_pokeys; i++)
|
||||||
{
|
{
|
||||||
buffer[i] = (SWORD)floor((generate_sample(pokey_states + i) - MAX_SAMPLE / 2.0)
|
buffer[i] = (SWORD)floor(generate_sample(pokey_states + i)
|
||||||
* (65535.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
* (65535.0 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95) + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);
|
||||||
}
|
}
|
||||||
buffer += num_cur_pokeys;
|
buffer += num_cur_pokeys;
|
||||||
nsam -= num_cur_pokeys;
|
nsam -= num_cur_pokeys;
|
||||||
@@ -2434,16 +2443,16 @@ static void generate_sync(unsigned int num_ticks)
|
|||||||
advance_ticks(pokey_states + i, ticks);
|
advance_ticks(pokey_states + i, ticks);
|
||||||
if (POKEYSND_snd_flags & POKEYSND_BIT16) {
|
if (POKEYSND_snd_flags & POKEYSND_BIT16) {
|
||||||
*((SWORD *)buffer) = (SWORD)floor(
|
*((SWORD *)buffer) = (SWORD)floor(
|
||||||
(interp_read_resam_all(pokey_states + i, samp_pos) - MAX_SAMPLE / 2.0)
|
interp_read_resam_all(pokey_states + i, samp_pos)
|
||||||
* (65535.0 / MAX_SAMPLE / 4 * M_PI * 0.95)
|
* (volume.s16 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95)
|
||||||
+ 0.5 + 0.5 * rand() / RAND_MAX - 0.25
|
+ 0.5 + 0.5 * rand() / RAND_MAX - 0.25
|
||||||
);
|
);
|
||||||
buffer += 2;
|
buffer += 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*buffer++ = (UBYTE)floor(
|
*buffer++ = (UBYTE)floor(
|
||||||
(interp_read_resam_all(pokey_states + i, samp_pos) - MAX_SAMPLE / 2.0)
|
interp_read_resam_all(pokey_states + i, samp_pos)
|
||||||
* (255.0 / MAX_SAMPLE / 4 * M_PI * 0.95)
|
* (volume.s8 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95)
|
||||||
+ 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25
|
+ 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -168,6 +168,8 @@ int POKEYSND_bienias_fix = TRUE; /* when TRUE, high frequencies get emulated: b
|
|||||||
int POKEYSND_stereo_enabled = FALSE;
|
int POKEYSND_stereo_enabled = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int POKEYSND_volume = 0x100;
|
||||||
|
|
||||||
/* multiple sound engine interface */
|
/* multiple sound engine interface */
|
||||||
static void pokeysnd_process_8(void *sndbuffer, int sndn);
|
static void pokeysnd_process_8(void *sndbuffer, int sndn);
|
||||||
static void pokeysnd_process_16(void *sndbuffer, int sndn);
|
static void pokeysnd_process_16(void *sndbuffer, int sndn);
|
||||||
@@ -1246,6 +1248,16 @@ static void Update_serio_sound_rf(int out, UBYTE data)
|
|||||||
}
|
}
|
||||||
#endif /* SERIO_SOUND */
|
#endif /* SERIO_SOUND */
|
||||||
|
|
||||||
|
void POKEYSND_SetVolume(int vol)
|
||||||
|
{
|
||||||
|
if (vol > 100)
|
||||||
|
vol = 100;
|
||||||
|
if (vol < 0)
|
||||||
|
vol = 0;
|
||||||
|
|
||||||
|
POKEYSND_volume = vol * 0x100 / 100;
|
||||||
|
}
|
||||||
|
|
||||||
static void pokeysnd_process_16(void *sndbuffer, int sndn)
|
static void pokeysnd_process_16(void *sndbuffer, int sndn)
|
||||||
{
|
{
|
||||||
UWORD *buffer = (UWORD *) sndbuffer;
|
UWORD *buffer = (UWORD *) sndbuffer;
|
||||||
@@ -1254,7 +1266,11 @@ static void pokeysnd_process_16(void *sndbuffer, int sndn)
|
|||||||
pokeysnd_process_8(buffer, sndn);
|
pokeysnd_process_8(buffer, sndn);
|
||||||
|
|
||||||
for (i = sndn - 1; i >= 0; i--) {
|
for (i = sndn - 1; i >= 0; i--) {
|
||||||
int smp = ((int) (((UBYTE *) buffer)[i]) - 0x80) * 0x100;
|
#ifndef POKEYSND_SIGNED_SAMPLES
|
||||||
|
int smp = ((int) (((UBYTE *) buffer)[i]) - 0x80) * POKEYSND_volume;
|
||||||
|
#else
|
||||||
|
int smp = ((int) ((SBYTE *) buffer)[i]) * POKEYSND_volume;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (smp > 32767)
|
if (smp > 32767)
|
||||||
smp = 32767;
|
smp = 32767;
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ extern "C" {
|
|||||||
extern SLONG POKEYSND_playback_freq;
|
extern SLONG POKEYSND_playback_freq;
|
||||||
extern UBYTE POKEYSND_num_pokeys;
|
extern UBYTE POKEYSND_num_pokeys;
|
||||||
extern int POKEYSND_snd_flags;
|
extern int POKEYSND_snd_flags;
|
||||||
|
extern int POKEYSND_volume;
|
||||||
|
|
||||||
extern int POKEYSND_enable_new_pokey;
|
extern int POKEYSND_enable_new_pokey;
|
||||||
extern int POKEYSND_stereo_enabled;
|
extern int POKEYSND_stereo_enabled;
|
||||||
|
|||||||
Reference in New Issue
Block a user