102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
samples.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
7#include <math.h>
8#include <stdarg.h>
9#include <string.h>
10
11// Original pcdogs.exe: 0x4381f0
12// Ends playback on all nine sample handles and then stops the active music stream.
14{
15 for (int slot_index = 0; slot_index < AUDIO_CHANNEL_COUNT; ++slot_index)
16 AIL_end_sample(g_soundSlots[slot_index].sample_handle);
17
19}
20
21// Original pcdogs.exe: 0x438310
22// Reports playing status only when the indexed slot has a nonzero cached base rate; the slot index is unchecked.
23int32_t Audio_IsSamplePlaying(int32_t slot_index)
24{
25 return (g_soundSlots[slot_index].base_playback_rate && AIL_sample_status(g_soundSlots[slot_index].sample_handle) == AUDIO_PLAYBACK_PLAYING);
26}
27
28// Original pcdogs.exe: 0x438340
29// Folds the wrapped Q12 pan angle into the Miles pan range and updates an initialized slot only when its cached value changes.
30void Audio_SetSamplePan(int32_t slot_index, int32_t pan_fp12)
31{
32 if (!g_soundSlots[slot_index].base_playback_rate)
33 return;
34
35 int32_t folded_pan_q12 = pan_fp12 & AUDIO_PAN_WRAP_MASK;
36
37 if (folded_pan_q12 > AUDIO_PAN_HALF_TURN)
38 folded_pan_q12 = AUDIO_Q12_ONE - folded_pan_q12;
39
40 int32_t pan = folded_pan_q12 >> AUDIO_PAN_TO_MILES_SHIFT;
41
42 if (pan >= (AUDIO_MILES_CONTROL_MAX + 1))
44
45 if (pan != g_soundSlots[slot_index].cached_pan)
46 {
47 g_soundSlots[slot_index].cached_pan = pan;
48 AIL_set_sample_pan(g_soundSlots[slot_index].sample_handle, pan);
49 }
50}
51
52// Original pcdogs.exe: 0x4383a0
53// Converts Q12 volume to the Miles scale and updates an initialized slot only when its cached value changes. The unsigned converted value is capped at 128.
54void Audio_SetSampleVolume(int32_t slot_index, int32_t volume_fp12)
55{
56 if (!g_soundSlots[slot_index].base_playback_rate)
57 return;
58
59 int32_t volume = (uint32_t)volume_fp12 >> AUDIO_VOLUME_TO_MILES_SHIFT;
60
61 if (volume >= (AUDIO_MILES_CONTROL_MAX + 1))
63
64 if (volume != g_soundSlots[slot_index].cached_volume)
65 {
66 g_soundSlots[slot_index].cached_volume = volume;
67 AIL_set_sample_volume(g_soundSlots[slot_index].sample_handle, volume);
68 }
69}
70
71// Original pcdogs.exe: 0x4383f0
72// Scales an initialized slot's base playback rate by the Q12 pitch factor and updates Miles only when the cached rate changes. The rate retains the low 32 bits after the product shift.
73void Audio_SetSamplePitch(int32_t slot_index, int32_t pitch_scale_q12)
74{
75 int32_t base_playback_rate = g_soundSlots[slot_index].base_playback_rate;
76
77 if (!base_playback_rate)
78 return;
79
80 int64_t scaled_rate = (int64_t)pitch_scale_q12 * base_playback_rate;
81 int32_t playback_rate = (int32_t)((uint64_t)scaled_rate >> AUDIO_Q12_SHIFT);
82
83 if (playback_rate != g_soundSlots[slot_index].cached_playback_rate)
84 {
85 g_soundSlots[slot_index].cached_playback_rate = playback_rate;
86 AIL_set_sample_playback_rate(g_soundSlots[slot_index].sample_handle, playback_rate);
87 }
88}
#define AUDIO_PAN_WRAP_MASK
Definition constants.h:28
#define AUDIO_VOLUME_TO_MILES_SHIFT
Definition constants.h:31
@ AUDIO_PLAYBACK_PLAYING
Definition constants.h:63
#define AUDIO_Q12_ONE
Definition constants.h:24
#define AUDIO_MILES_CONTROL_MAX
Definition constants.h:29
#define AUDIO_PAN_HALF_TURN
Definition constants.h:26
#define AUDIO_PAN_TO_MILES_SHIFT
Definition constants.h:32
#define AUDIO_CHANNEL_COUNT
Definition constants.h:41
#define AUDIO_Q12_SHIFT
Definition constants.h:22
void Audio_StopMusicAndPause(void)
Definition music.c:245
#define g_soundSlots
Definition globals.h:27
int32_t AIL_set_sample_playback_rate(AIL_HSAMPLE sample, int32_t playback_rate)
int32_t AIL_sample_status(AIL_HSAMPLE sample)
int32_t AIL_set_sample_volume(AIL_HSAMPLE sample, int32_t volume)
int32_t AIL_end_sample(AIL_HSAMPLE sample)
int32_t AIL_set_sample_pan(AIL_HSAMPLE sample, int32_t pan)
void Audio_SetSamplePan(int32_t slot_index, int32_t pan_fp12)
Definition samples.c:30
void Audio_SetSampleVolume(int32_t slot_index, int32_t volume_fp12)
Definition samples.c:54
void Audio_StopAllSamples()
Definition samples.c:13
int32_t Audio_IsSamplePlaying(int32_t slot_index)
Definition samples.c:23
void Audio_SetSamplePitch(int32_t slot_index, int32_t pitch_scale_q12)
Definition samples.c:73