diff --git a/atari800/src/mzpokeysnd.c b/atari800/src/mzpokeysnd.c index 3805853..0be8d72 100644 --- a/atari800/src/mzpokeysnd.c +++ b/atari800/src/mzpokeysnd.c @@ -264,6 +264,11 @@ typedef struct stPokeyState } PokeyState; +static struct { + double s16; + double s8; +} volume; + PokeyState pokey_states[NPOKEYS]; /* Forward declarations for ResetPokeyState */ @@ -1421,6 +1426,10 @@ int MZPOKEYSND_Init(ULONG freq17, int playback_freq, UBYTE num_pokeys, #ifdef SYNCHRONIZED_SOUND init_syncsound(); #endif + + volume.s8 = POKEYSND_volume * 0xff / 256.0; + volume.s16 = POKEYSND_volume * 0xffff / 256.0; + return 0; /* OK */ } @@ -2341,16 +2350,16 @@ static void mzpokeysnd_process_8(void* sndbuffer, int sndn) #endif #ifdef VOL_ONLY_SOUND - buffer[0] = (UBYTE)floor((generate_sample(pokey_states) + POKEYSND_sampout - MAX_SAMPLE / 2.0) - * (255.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25); + buffer[0] = (UBYTE)floor((generate_sample(pokey_states) + POKEYSND_sampout) + * (255.0 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25); #else - buffer[0] = (UBYTE)floor((generate_sample(pokey_states) - MAX_SAMPLE / 2.0) - * (255.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25); + buffer[0] = (UBYTE)floor(generate_sample(pokey_states) + * (255.0 / 2 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25); #endif for(i=1; i 100) + vol = 100; + if (vol < 0) + vol = 0; + + POKEYSND_volume = vol * 0x100 / 100; +} + static void pokeysnd_process_16(void *sndbuffer, int sndn) { UWORD *buffer = (UWORD *) sndbuffer; @@ -1254,7 +1266,11 @@ static void pokeysnd_process_16(void *sndbuffer, int sndn) pokeysnd_process_8(buffer, sndn); 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) smp = 32767; diff --git a/atari800/src/pokeysnd.h b/atari800/src/pokeysnd.h index 8cf15a8..6267f18 100644 --- a/atari800/src/pokeysnd.h +++ b/atari800/src/pokeysnd.h @@ -84,6 +84,7 @@ extern "C" { extern SLONG POKEYSND_playback_freq; extern UBYTE POKEYSND_num_pokeys; extern int POKEYSND_snd_flags; +extern int POKEYSND_volume; extern int POKEYSND_enable_new_pokey; extern int POKEYSND_stereo_enabled;