MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / StartSound

Function StartSound

src/sound.cpp:98–121  ·  view source on GitHub ↗

Low level sound player */

Source from the content-addressed store, hash-verified

96
97/* Low level sound player */
98static void StartSound(SoundID sound_id, float pan, uint volume)
99{
100 if (volume == 0) return;
101
102 SoundEntry *sound = GetSound(sound_id);
103 if (sound == nullptr) return;
104
105 if (sound->rate == 0) {
106 /* If the sound's sample rate is not set then the sound needs to be loaded, but if the sound's file pointer
107 * is empty then an attempt was already made to load the sound but it failed. We don't want to try again. */
108 if (sound->file == nullptr) return;
109 }
110
111 MixerChannel *mc = MxAllocateChannel();
112 if (mc == nullptr) return;
113
114 if (!SetBankSource(mc, sound, sound_id)) return;
115
116 /* Apply the sound effect's own volume. */
117 volume = sound->volume * volume;
118
119 MxSetChannelVolume(mc, volume, pan);
120 MxActivateChannel(mc);
121}
122
123
124static const uint8_t _vol_factor_by_zoom[] = {255, 255, 255, 190, 134, 87};

Callers 2

SndPlayScreenCoordFxFunction · 0.85
SndPlayFxFunction · 0.85

Calls 5

GetSoundFunction · 0.85
MxAllocateChannelFunction · 0.85
SetBankSourceFunction · 0.85
MxSetChannelVolumeFunction · 0.85
MxActivateChannelFunction · 0.85

Tested by

no test coverage detected