coastline 0.0.4
Loading...
Searching...
No Matches
soundmix.h
Go to the documentation of this file.
1#ifndef COASTLINE_SOUND_MIX_H
2#define COASTLINE_SOUND_MIX_H
3
4#include "common/types.h"
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#define SAMPLE_RATE 11000.0f
11#define STEP_ONE 4294967296.0
12
13#if TGR_BOSS_RALLY
15typedef long double SoundReal;
16#else
18typedef f32 SoundReal;
19#endif
20
22static inline u64 FrequencyStep(SoundReal frequency) {
23#if TGR_BOSS_RALLY
24 long double scaled = frequency * (1.0f / SAMPLE_RATE) * STEP_ONE;
25 return scaled >= -0x1p63L && scaled < 0x1p63L ? (u64)(s64)scaled : ((u64)1 << 63);
26#else
27 return (u64)((double)(frequency * (1.0f / SAMPLE_RATE)) * STEP_ONE);
28#endif
29}
30
32static inline f32 UpperVolume(s32 volume, f32 upper) {
33 return (f32)((s32)((f32)volume * upper) << 16);
34}
35
37static inline u32 PackVolume(s32 volume, f32 upper, f32 lower) {
38#if TGR_BOSS_RALLY
39 long double upperProduct = (long double)volume * upper;
40 long double lowerProduct = (long double)volume * lower;
41 u32 upperWord = upperProduct >= -0x1p63L && upperProduct < 0x1p63L ? (u32)(s64)upperProduct : 0;
42 u32 lowerWord = lowerProduct >= -0x1p63L && lowerProduct < 0x1p63L ? (u32)(s64)lowerProduct : 0;
43 return (upperWord << 16) + lowerWord;
44#else
45 return (u32)(UpperVolume(volume, upper) + lower * (f32)volume);
46#endif
47}
48
49#ifdef __cplusplus
50}
51#endif
52
53#endif /* COASTLINE_SOUND_MIX_H */
#define SAMPLE_RATE
Definition soundmix.h:10
#define STEP_ONE
Definition soundmix.h:11
static u64 FrequencyStep(SoundReal frequency)
Definition soundmix.h:22
f32 SoundReal
The precision used for Nintendo 64 sound-mixing calculations.
Definition soundmix.h:18
static f32 UpperVolume(s32 volume, f32 upper)
Definition soundmix.h:32
static u32 PackVolume(s32 volume, f32 upper, f32 lower)
Definition soundmix.h:37
The integer and floating-point types of the console, for headers shared with Windows.
unsigned int u32
Definition ultratypes.h:20
float f32
Definition ultratypes.h:38
long long s64
Definition ultratypes.h:26
int s32
Definition ultratypes.h:25
unsigned long long u64
Definition ultratypes.h:21