mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
Make ASS's mixing functions take a pointer to a voice instead of passing a bunch of parameters separately
git-svn-id: https://svn.eduke32.com/eduke32@7121 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
6d226cf0da
commit
6513d9f3e3
4 changed files with 82 additions and 61 deletions
|
@ -56,21 +56,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#define MIX_VOLUME(volume) ((max(0, min((volume), 255)) * (MV_MAXVOLUME + 1)) >> 8)
|
||||
|
||||
template <typename T>
|
||||
static inline conditional_t< is_signed<T>::value, make_unsigned_t<T>, make_signed_t<T> > MV_FLIP_SIGNEDNESS(T src)
|
||||
static inline conditional_t< is_signed<T>::value, make_unsigned_t<T>, make_signed_t<T> > FLIP_SIGN(T src)
|
||||
{
|
||||
static constexpr make_unsigned_t<T> msb = ((make_unsigned_t<T>)1) << (sizeof(T) * CHAR_BIT - 1u);
|
||||
return src ^ msb;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline enable_if_t<is_signed<T>::value, T> MV_VOLUME(T src, float volume)
|
||||
static inline enable_if_t<is_signed<T>::value, T> SCALE_SAMPLE(T src, float volume)
|
||||
{
|
||||
return (T)Blrintf((float)src * volume);
|
||||
}
|
||||
template <typename T>
|
||||
static inline enable_if_t<is_unsigned<T>::value, T> MV_VOLUME(T src, float volume)
|
||||
static inline enable_if_t<is_unsigned<T>::value, T> SCALE_SAMPLE(T src, float volume)
|
||||
{
|
||||
return MV_FLIP_SIGNEDNESS(MV_VOLUME(MV_FLIP_SIGNEDNESS(src), volume));
|
||||
return FLIP_SIGN(SCALE_SAMPLE(FLIP_SIGN(src), volume));
|
||||
}
|
||||
|
||||
struct split16_t
|
||||
|
@ -110,7 +110,7 @@ typedef struct VoiceNode
|
|||
|
||||
playbackstatus (*GetSound)(struct VoiceNode *voice);
|
||||
|
||||
void (*mix)(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void (*mix)(struct VoiceNode *voice, uint32_t length);
|
||||
|
||||
const char *sound;
|
||||
|
||||
|
@ -186,7 +186,8 @@ extern Pan MV_PanTable[ MV_NUMPANPOSITIONS ][ MV_MAXVOLUME + 1 ];
|
|||
extern int32_t MV_ErrorCode;
|
||||
extern int32_t MV_Installed;
|
||||
extern int32_t MV_MixRate;
|
||||
typedef char HARSH_CLIP_TABLE_8[ MV_NUMVOICES * 256 ];
|
||||
|
||||
using HARSH_CLIP_TABLE_8 = char[MV_NUMVOICES * 256];
|
||||
|
||||
#define MV_SetErrorCode(status) MV_ErrorCode = (status);
|
||||
|
||||
|
@ -213,17 +214,17 @@ void MV_ReleaseXAVoice(VoiceNode *voice);
|
|||
void MV_ReleaseXMPVoice(VoiceNode *voice);
|
||||
|
||||
// implemented in mix.c
|
||||
void MV_Mix16BitMono(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void MV_Mix16BitStereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void MV_Mix16BitMono16(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void MV_Mix16BitStereo16(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void MV_Mix16BitMono(struct VoiceNode *voice, uint32_t length);
|
||||
void MV_Mix16BitStereo(struct VoiceNode *voice, uint32_t length);
|
||||
void MV_Mix16BitMono16(struct VoiceNode *voice, uint32_t length);
|
||||
void MV_Mix16BitStereo16(struct VoiceNode *voice, uint32_t length);
|
||||
void MV_16BitReverb( char const *src, char *dest, int16_t *volume, int32_t count );
|
||||
|
||||
// implemented in mixst.c
|
||||
void MV_Mix16BitMono8Stereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void MV_Mix16BitStereo8Stereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void MV_Mix16BitMono16Stereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void MV_Mix16BitStereo16Stereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume);
|
||||
void MV_Mix16BitMono8Stereo(struct VoiceNode *voice, uint32_t length);
|
||||
void MV_Mix16BitStereo8Stereo(struct VoiceNode *voice, uint32_t length);
|
||||
void MV_Mix16BitMono16Stereo(struct VoiceNode *voice, uint32_t length);
|
||||
void MV_Mix16BitStereo16Stereo(struct VoiceNode *voice, uint32_t length);
|
||||
|
||||
extern char *MV_MixDestination; // pointer to the next output sample
|
||||
extern uint32_t MV_MixPosition; // return value of where the source pointer got to
|
||||
|
|
|
@ -29,19 +29,21 @@
|
|||
*/
|
||||
|
||||
// 8-bit mono source, 16-bit mono output
|
||||
void MV_Mix16BitMono(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
void MV_Mix16BitMono(struct VoiceNode *voice, uint32_t length)
|
||||
{
|
||||
auto const source = (uint8_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
auto const source = (uint8_t const *)voice->sound;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
uint32_t position = voice->position;
|
||||
uint32_t const rate = voice->RateScale;
|
||||
float const volume = voice->volume;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
uint8_t const usample0 = MV_VOLUME(source[position >> 16], volume);
|
||||
uint8_t const usample0 = SCALE_SAMPLE(source[position >> 16], volume);
|
||||
|
||||
position += rate;
|
||||
|
||||
*dest = (int16_t)clamp(MV_LeftVolume[usample0] + *dest, INT16_MIN, INT16_MAX);
|
||||
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
|
@ -50,21 +52,23 @@ void MV_Mix16BitMono(uint32_t position, uint32_t rate, const char *start, uint32
|
|||
}
|
||||
|
||||
// 8-bit mono source, 16-bit stereo output
|
||||
void MV_Mix16BitStereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
void MV_Mix16BitStereo(struct VoiceNode *voice, uint32_t length)
|
||||
{
|
||||
auto const source = (uint8_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
auto const source = (uint8_t const *)voice->sound;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
uint32_t position = voice->position;
|
||||
uint32_t const rate = voice->RateScale;
|
||||
float const volume = voice->volume;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
uint8_t const usample0 = MV_VOLUME(source[position >> 16], volume);
|
||||
uint8_t const usample0 = SCALE_SAMPLE(source[position >> 16], volume);
|
||||
|
||||
position += rate;
|
||||
|
||||
*dest = (int16_t)clamp(MV_LeftVolume[usample0] + *dest, INT16_MIN, INT16_MAX);
|
||||
*(dest + (MV_RightChannelOffset >> 1))
|
||||
= (int16_t)clamp(MV_RightVolume[usample0] + *(dest + (MV_RightChannelOffset >> 1)), INT16_MIN, INT16_MAX);
|
||||
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
|
@ -73,21 +77,24 @@ void MV_Mix16BitStereo(uint32_t position, uint32_t rate, const char *start, uint
|
|||
}
|
||||
|
||||
// 16-bit mono source, 16-bit mono output
|
||||
void MV_Mix16BitMono16(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
void MV_Mix16BitMono16(struct VoiceNode *voice, uint32_t length)
|
||||
{
|
||||
auto const source = (int16_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
auto const source = (int16_t const *)voice->sound;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
uint32_t position = voice->position;
|
||||
uint32_t const rate = voice->RateScale;
|
||||
float const volume = voice->volume;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
int16_t const isample0 = B_LITTLE16(source[position >> 16]);
|
||||
split16_t const usample0{MV_FLIP_SIGNEDNESS(MV_VOLUME(isample0, volume))};
|
||||
split16_t const usample0{FLIP_SIGN(SCALE_SAMPLE(isample0, volume))};
|
||||
|
||||
position += rate;
|
||||
|
||||
int32_t const sample0 = (MV_LeftVolume[usample0.l()] >> 8) + MV_LeftVolume[usample0.h()] + 128;
|
||||
*dest = (int16_t)clamp(sample0 + *dest, INT16_MIN, INT16_MAX);
|
||||
|
||||
*dest = (int16_t)clamp(sample0 + *dest, INT16_MIN, INT16_MAX);
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
|
@ -96,24 +103,27 @@ void MV_Mix16BitMono16(uint32_t position, uint32_t rate, const char *start, uint
|
|||
}
|
||||
|
||||
// 16-bit mono source, 16-bit stereo output
|
||||
void MV_Mix16BitStereo16(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
void MV_Mix16BitStereo16(struct VoiceNode *voice, uint32_t length)
|
||||
{
|
||||
auto const source = (int16_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
auto const source = (int16_t const *)voice->sound;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
uint32_t position = voice->position;
|
||||
uint32_t const rate = voice->RateScale;
|
||||
float const volume = voice->volume;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
int16_t const isample0 = B_LITTLE16(source[position >> 16]);
|
||||
split16_t const usample0{MV_FLIP_SIGNEDNESS(MV_VOLUME(isample0, volume))};
|
||||
split16_t const usample0{FLIP_SIGN(SCALE_SAMPLE(isample0, volume))};
|
||||
|
||||
position += rate;
|
||||
|
||||
int32_t const sample0 = (MV_LeftVolume[usample0.l()] >> 8) + MV_LeftVolume[usample0.h()] + 128;
|
||||
int32_t const sample1 = (MV_RightVolume[usample0.l()] >> 8) + MV_RightVolume[usample0.h()] + 128;
|
||||
|
||||
*dest = (int16_t)clamp(sample0 + *dest, INT16_MIN, INT16_MAX);
|
||||
*(dest + (MV_RightChannelOffset >> 1))
|
||||
= (int16_t)clamp(sample1 + *(dest + (MV_RightChannelOffset >> 1)), INT16_MIN, INT16_MAX);
|
||||
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,23 +21,25 @@
|
|||
#include "_multivc.h"
|
||||
|
||||
/*
|
||||
position = offset of starting sample in start
|
||||
rate = resampling increment
|
||||
start = sound data
|
||||
length = count of samples to mix
|
||||
position = offset of starting sample in source
|
||||
rate = resampling increment
|
||||
volume = direct volume adjustment, 1.0 = no change
|
||||
*/
|
||||
|
||||
// 8-bit stereo source, 16-bit mono output
|
||||
void MV_Mix16BitMono8Stereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
void MV_Mix16BitMono8Stereo(struct VoiceNode *voice, uint32_t length)
|
||||
{
|
||||
auto const source = (uint8_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
auto const source = (uint8_t const *)voice->sound;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
uint32_t position = voice->position;
|
||||
uint32_t const rate = voice->RateScale;
|
||||
float const volume = voice->volume;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
uint8_t const usample0 = MV_VOLUME(source[(position >> 16) << 1], volume);
|
||||
uint8_t const usample1 = MV_VOLUME(source[((position >> 16) << 1) + 1], volume);
|
||||
uint8_t const usample0 = SCALE_SAMPLE(source[(position >> 16) << 1], volume);
|
||||
uint8_t const usample1 = SCALE_SAMPLE(source[((position >> 16) << 1) + 1], volume);
|
||||
|
||||
position += rate;
|
||||
|
||||
|
@ -50,22 +52,24 @@ void MV_Mix16BitMono8Stereo(uint32_t position, uint32_t rate, const char *start,
|
|||
}
|
||||
|
||||
// 8-bit stereo source, 16-bit stereo output
|
||||
void MV_Mix16BitStereo8Stereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
void MV_Mix16BitStereo8Stereo(struct VoiceNode *voice, uint32_t length)
|
||||
{
|
||||
auto const source = (uint8_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
auto const source = (uint8_t const *)voice->sound;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
uint32_t position = voice->position;
|
||||
uint32_t const rate = voice->RateScale;
|
||||
float const volume = voice->volume;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
uint8_t const usample0 = MV_VOLUME(source[(position >> 16) << 1], volume);
|
||||
uint8_t const usample1 = MV_VOLUME(source[((position >> 16) << 1) + 1], volume);
|
||||
uint8_t const usample0 = SCALE_SAMPLE(source[(position >> 16) << 1], volume);
|
||||
uint8_t const usample1 = SCALE_SAMPLE(source[((position >> 16) << 1) + 1], volume);
|
||||
|
||||
position += rate;
|
||||
|
||||
*dest = (int16_t)clamp(MV_LeftVolume[usample0] + *dest, INT16_MIN, INT16_MAX);
|
||||
*(dest + (MV_RightChannelOffset >> 1))
|
||||
= (int16_t)clamp(MV_RightVolume[usample1] + *(dest + (MV_RightChannelOffset >> 1)), INT16_MIN, INT16_MAX);
|
||||
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
|
@ -74,24 +78,27 @@ void MV_Mix16BitStereo8Stereo(uint32_t position, uint32_t rate, const char *star
|
|||
}
|
||||
|
||||
// 16-bit stereo source, 16-bit mono output
|
||||
void MV_Mix16BitMono16Stereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
void MV_Mix16BitMono16Stereo(struct VoiceNode *voice, uint32_t length)
|
||||
{
|
||||
auto const source = (int16_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
auto const source = (int16_t const *)voice->sound;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
uint32_t position = voice->position;
|
||||
uint32_t const rate = voice->RateScale;
|
||||
float const volume = voice->volume;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
int16_t const isample0 = B_LITTLE16(source[(position >> 16) << 1]);
|
||||
int16_t const isample1 = B_LITTLE16(source[((position >> 16) << 1) + 1]);
|
||||
split16_t const usample0{MV_FLIP_SIGNEDNESS(MV_VOLUME(isample0, volume))};
|
||||
split16_t const usample1{MV_FLIP_SIGNEDNESS(MV_VOLUME(isample1, volume))};
|
||||
split16_t const usample0{FLIP_SIGN(SCALE_SAMPLE(isample0, volume))};
|
||||
split16_t const usample1{FLIP_SIGN(SCALE_SAMPLE(isample1, volume))};
|
||||
|
||||
position += rate;
|
||||
|
||||
int32_t const sample0 = (MV_LeftVolume[usample0.l()] >> 8) + MV_LeftVolume[usample0.h()] + 128;
|
||||
int32_t const sample1 = (MV_LeftVolume[usample1.l()] >> 8) + MV_LeftVolume[usample1.h()] + 128;
|
||||
*dest = (int16_t)clamp(((sample0 + sample1) >> 1) + *dest, INT16_MIN, INT16_MAX);
|
||||
|
||||
*dest = (int16_t)clamp(((sample0 + sample1) >> 1) + *dest, INT16_MIN, INT16_MAX);
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
|
@ -100,26 +107,29 @@ void MV_Mix16BitMono16Stereo(uint32_t position, uint32_t rate, const char *start
|
|||
}
|
||||
|
||||
// 16-bit stereo source, 16-bit stereo output
|
||||
void MV_Mix16BitStereo16Stereo(uint32_t position, uint32_t rate, const char *start, uint32_t length, float volume)
|
||||
void MV_Mix16BitStereo16Stereo(struct VoiceNode *voice, uint32_t length)
|
||||
{
|
||||
auto const source = (int16_t const *)start;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
auto const source = (int16_t const *)voice->sound;
|
||||
int16_t * dest = (int16_t *)MV_MixDestination;
|
||||
uint32_t position = voice->position;
|
||||
uint32_t const rate = voice->RateScale;
|
||||
float const volume = voice->volume;
|
||||
|
||||
while (length--)
|
||||
{
|
||||
int16_t const isample0 = B_LITTLE16(source[(position >> 16) << 1]);
|
||||
int16_t const isample1 = B_LITTLE16(source[((position >> 16) << 1) + 1]);
|
||||
split16_t const usample0{MV_FLIP_SIGNEDNESS(MV_VOLUME(isample0, volume))};
|
||||
split16_t const usample1{MV_FLIP_SIGNEDNESS(MV_VOLUME(isample1, volume))};
|
||||
split16_t const usample0{FLIP_SIGN(SCALE_SAMPLE(isample0, volume))};
|
||||
split16_t const usample1{FLIP_SIGN(SCALE_SAMPLE(isample1, volume))};
|
||||
|
||||
position += rate;
|
||||
|
||||
int32_t const sample0 = (MV_LeftVolume[usample0.l()] >> 8) + MV_LeftVolume[usample0.h()] + 128;
|
||||
int32_t const sample1 = (MV_RightVolume[usample1.l()] >> 8) + MV_RightVolume[usample1.h()] + 128;
|
||||
|
||||
*dest = (int16_t)clamp(sample0 + *dest, INT16_MIN, INT16_MAX);
|
||||
*(dest + (MV_RightChannelOffset >> 1))
|
||||
= (int16_t)clamp(sample1 + *(dest + (MV_RightChannelOffset >> 1)), INT16_MIN, INT16_MAX);
|
||||
|
||||
dest += MV_SampleSize >> 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ static void MV_Mix(VoiceNode *voice, int const buffer)
|
|||
voclength = length;
|
||||
|
||||
if (voice->mix)
|
||||
voice->mix(position, rate, start, voclength, voice->volume);
|
||||
voice->mix(voice, voclength);
|
||||
|
||||
voice->position = MV_MixPosition;
|
||||
|
||||
|
|
Loading…
Reference in a new issue