mirror of
https://github.com/ZDoom/Raze.git
synced 2025-05-30 08:51:08 +00:00
Add per-sound volume support to audiolib. This allows you to control the volume of sounds independently from the distance-based system exposed through CON. To use this, you must define your sounds via the .def syntax and set the "volume" property--default is 1.0.
git-svn-id: https://svn.eduke32.com/eduke32@7117 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
98f42cba6f
commit
374a09536d
16 changed files with 297 additions and 352 deletions
|
@ -21,160 +21,137 @@
|
|||
#include "_multivc.h"
|
||||
|
||||
/*
|
||||
JBF:
|
||||
|
||||
position = offset of starting sample in start
|
||||
rate = resampling increment
|
||||
start = sound data
|
||||
length = count of samples to mix
|
||||
volume = direct volume adjustment, 1.0 = no change
|
||||
*/
|
||||
|
||||
// 8-bit mono source, 16-bit mono output
|
||||
void MV_Mix16BitMono(uint32_t position, uint32_t rate, const char *start, uint32_t length)
|
||||
void MV_Mix16BitMono(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
{
|
||||
uint8_t const * const source = (uint8_t const *) start;
|
||||
int16_t *dest = (int16_t *) MV_MixDestination;
|
||||
int32_t sample0;
|
||||
auto const source = (uint8_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
|
||||
while (length--) {
|
||||
sample0 = source[position >> 16];
|
||||
while (length--)
|
||||
{
|
||||
int const sample0 = MV_VOLUME(source[position >> 16]);
|
||||
position += rate;
|
||||
|
||||
sample0 = MV_LeftVolume[sample0] + *dest;
|
||||
if (sample0 < -32768) sample0 = -32768;
|
||||
else if (sample0 > 32767) sample0 = 32767;
|
||||
|
||||
*dest = (int16_t) sample0;
|
||||
|
||||
dest += MV_SampleSize / 2;
|
||||
*dest = (int16_t)clamp(MV_LeftVolume[sample0] + *dest, INT16_MIN, INT16_MAX);
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
MV_MixPosition = position;
|
||||
MV_MixDestination = (char *) dest;
|
||||
MV_MixPosition = position;
|
||||
MV_MixDestination = (char *)dest;
|
||||
}
|
||||
|
||||
// 8-bit mono source, 16-bit stereo output
|
||||
void MV_Mix16BitStereo(uint32_t position, uint32_t rate, const char *start, uint32_t length)
|
||||
void MV_Mix16BitStereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
{
|
||||
uint8_t const * const source = (uint8_t const *) start;
|
||||
int16_t *dest = (int16_t *) MV_MixDestination;
|
||||
int32_t sample0, sample1;
|
||||
auto const source = (uint8_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
|
||||
while (length--) {
|
||||
sample0 = source[position >> 16];
|
||||
sample1 = sample0;
|
||||
while (length--)
|
||||
{
|
||||
int const sample0 = MV_VOLUME(source[position >> 16]);
|
||||
position += rate;
|
||||
|
||||
sample0 = MV_LeftVolume[sample0] + *dest;
|
||||
sample1 = MV_RightVolume[sample1] + *(dest + MV_RightChannelOffset / 2);
|
||||
if (sample0 < -32768) sample0 = -32768;
|
||||
else if (sample0 > 32767) sample0 = 32767;
|
||||
if (sample1 < -32768) sample1 = -32768;
|
||||
else if (sample1 > 32767) sample1 = 32767;
|
||||
|
||||
*dest = (int16_t) sample0;
|
||||
*(dest + MV_RightChannelOffset/2) = (int16_t) sample1;
|
||||
|
||||
dest += MV_SampleSize / 2;
|
||||
*dest = (int16_t)clamp(MV_LeftVolume[sample0] + *dest, INT16_MIN, INT16_MAX);
|
||||
*(dest + (MV_RightChannelOffset >> 1))
|
||||
= (int16_t)clamp(MV_RightVolume[sample0] + *(dest + (MV_RightChannelOffset >> 1)), INT16_MIN, INT16_MAX);
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
MV_MixPosition = position;
|
||||
MV_MixDestination = (char *) dest;
|
||||
MV_MixPosition = position;
|
||||
MV_MixDestination = (char *)dest;
|
||||
}
|
||||
|
||||
// 16-bit mono source, 16-bit mono output
|
||||
void MV_Mix16BitMono16(uint32_t position, uint32_t rate, const char *start, uint32_t length)
|
||||
void MV_Mix16BitMono16(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
{
|
||||
uint16_t const * const source = (uint16_t const *) start;
|
||||
int16_t *dest = (int16_t *) MV_MixDestination;
|
||||
int32_t sample0l, sample0h, sample0;
|
||||
auto const source = (uint16_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
|
||||
while (length--) {
|
||||
sample0 = source[position >> 16];
|
||||
while (length--)
|
||||
{
|
||||
int const sample0 = MV_VOLUME(source[position >> 16]);
|
||||
#ifdef BIGENDIAN
|
||||
sample0l = sample0 >> 8;
|
||||
sample0h = (sample0 & 255) ^ 128;
|
||||
int sample0l = sample0 >> 8;
|
||||
int sample0h = (sample0 & 255) ^ 128;
|
||||
#else
|
||||
sample0l = sample0 & 255;
|
||||
sample0h = (sample0 >> 8) ^ 128;
|
||||
int sample0l = sample0 & 255;
|
||||
int sample0h = (sample0 >> 8) ^ 128;
|
||||
#endif
|
||||
position += rate;
|
||||
|
||||
sample0l = MV_LeftVolume[sample0l] >> 8;
|
||||
sample0h = MV_LeftVolume[sample0h];
|
||||
sample0 = sample0l + sample0h + 128 + *dest;
|
||||
if (sample0 < -32768) sample0 = -32768;
|
||||
else if (sample0 > 32767) sample0 = 32767;
|
||||
|
||||
*dest = (int16_t) sample0;
|
||||
*dest = (int16_t)clamp(sample0l + sample0h + 128 + *dest, INT16_MIN, INT16_MAX);
|
||||
|
||||
dest += MV_SampleSize / 2;
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
MV_MixPosition = position;
|
||||
MV_MixDestination = (char *) dest;
|
||||
MV_MixPosition = position;
|
||||
MV_MixDestination = (char *)dest;
|
||||
}
|
||||
|
||||
// 16-bit mono source, 16-bit stereo output
|
||||
void MV_Mix16BitStereo16(uint32_t position, uint32_t rate, const char *start, uint32_t length)
|
||||
void MV_Mix16BitStereo16(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
{
|
||||
uint16_t const * const source = (uint16_t const *) start;
|
||||
int16_t *dest = (int16_t *) MV_MixDestination;
|
||||
int32_t sample0l, sample0h, sample0;
|
||||
int32_t sample1l, sample1h, sample1;
|
||||
auto const source = (uint16_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
|
||||
while (length--) {
|
||||
sample0 = source[position >> 16];
|
||||
#ifdef BIGENDIAN
|
||||
sample0l = sample0 >> 8;
|
||||
sample0h = (sample0 & 255) ^ 128;
|
||||
#else
|
||||
sample0l = sample0 & 255;
|
||||
sample0h = (sample0 >> 8) ^ 128;
|
||||
#endif
|
||||
sample1l = sample0l;
|
||||
sample1h = sample0h;
|
||||
while (length--)
|
||||
{
|
||||
int const sample0 = MV_VOLUME(source[position >> 16]);
|
||||
position += rate;
|
||||
|
||||
#ifdef BIGENDIAN
|
||||
int sample0l = sample0 >> 8;
|
||||
int sample0h = (sample0 & 255) ^ 128;
|
||||
#else
|
||||
int sample0l = sample0 & 255;
|
||||
int sample0h = (sample0 >> 8) ^ 128;
|
||||
#endif
|
||||
|
||||
int const sample1l = MV_RightVolume[sample0l] >> 8;
|
||||
int const sample1h = MV_RightVolume[sample0h];
|
||||
|
||||
sample0l = MV_LeftVolume[sample0l] >> 8;
|
||||
sample0h = MV_LeftVolume[sample0h];
|
||||
sample1l = MV_RightVolume[sample1l] >> 8;
|
||||
sample1h = MV_RightVolume[sample1h];
|
||||
sample0 = sample0l + sample0h + 128 + *dest;
|
||||
sample1 = sample1l + sample1h + 128 + *(dest + MV_RightChannelOffset/2);
|
||||
if (sample0 < -32768) sample0 = -32768;
|
||||
else if (sample0 > 32767) sample0 = 32767;
|
||||
if (sample1 < -32768) sample1 = -32768;
|
||||
else if (sample1 > 32767) sample1 = 32767;
|
||||
|
||||
*dest = (int16_t) sample0;
|
||||
*(dest + MV_RightChannelOffset/2) = (int16_t) sample1;
|
||||
*dest = (int16_t)clamp(sample0l + sample0h + 128 + *dest, INT16_MIN, INT16_MAX);
|
||||
*(dest + (MV_RightChannelOffset >> 1))
|
||||
= (int16_t)clamp(sample1l + sample1h + 128 + *(dest + (MV_RightChannelOffset >> 1)), INT16_MIN, INT16_MAX);
|
||||
|
||||
dest += MV_SampleSize / 2;
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
MV_MixPosition = position;
|
||||
MV_MixDestination = (char *) dest;
|
||||
MV_MixPosition = position;
|
||||
MV_MixDestination = (char *)dest;
|
||||
}
|
||||
|
||||
void MV_16BitReverb(char const *src, char *dest, int16_t *volume, int32_t count)
|
||||
{
|
||||
uint16_t const * input = (uint16_t const *) src;
|
||||
int16_t * output = (int16_t *) dest;
|
||||
int16_t sample0l, sample0h, sample0;
|
||||
auto input = (uint16_t const *)src;
|
||||
int16_t *output = (int16_t *)dest;
|
||||
|
||||
do {
|
||||
sample0 = *input++;
|
||||
#if 0 //def BIGENDIAN
|
||||
sample0l = sample0 >> 8;
|
||||
sample0h = (sample0 & 255) ^ 128;
|
||||
do
|
||||
{
|
||||
int const sample0 = *input++;
|
||||
#if 0 // def BIGENDIAN
|
||||
int sample0l = sample0 >> 8;
|
||||
int sample0h = (sample0 & 255) ^ 128;
|
||||
#else
|
||||
sample0l = sample0 & 255;
|
||||
sample0h = (sample0 >> 8) ^ 128;
|
||||
int sample0l = sample0 & 255;
|
||||
int sample0h = (sample0 >> 8) ^ 128;
|
||||
#endif
|
||||
|
||||
sample0l = ((int16_t *) volume)[sample0l] >> 8;
|
||||
sample0h = ((int16_t *) volume)[sample0h];
|
||||
*output++ = (int16_t) (sample0l + sample0h + 128);
|
||||
sample0l = ((int16_t *)volume)[sample0l] >> 8;
|
||||
sample0h = ((int16_t *)volume)[sample0h];
|
||||
*output++ = (int16_t)(sample0l + sample0h + 128);
|
||||
} while (--count > 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue