MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / create

Function create

src/Audio/src/AudioEngine.cpp:272–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

270 }
271
272 AudioHandle create(BufferId buffer, ChannelId channel, const AudioAttributes& attribs)
273 {
274 uint32_t idx = static_cast<uint32_t>(_instances.size());
275 for (uint32_t i = 0; i < _instances.size(); ++i)
276 {
277 if (!_instances[i].active)
278 {
279 idx = i;
280 break;
281 }
282 }
283
284 uint32_t sourceId = 0;
285 if (idx < _instances.size())
286 {
287 sourceId = _instances[idx].sourceId;
288 }
289 else
290 {
291 alGenSources(1, &sourceId);
292 _alSources.push_back(sourceId);
293 }
294 alSourcei(sourceId, AL_BUFFER, static_cast<ALint>(buffer));
295
296 AudioInstance inst{};
297 inst.sourceId = sourceId;
298 inst.channel = channel;
299 inst.attribs = attribs;
300 inst.active = true;
301
302 if (idx == _instances.size())
303 {
304 _instances.push_back(inst);
305 }
306 else
307 {
308 _instances[idx] = inst;
309 }
310
311 applyVolume(_instances[idx]);
312 applyPitch(_instances[idx]);
313 applyPan(sourceId, attribs.pan);
314 alSourcei(sourceId, AL_LOOPING, attribs.loop ? AL_TRUE : AL_FALSE);
315
316 return static_cast<AudioHandle>(idx);
317 }
318
319 void destroy(AudioHandle handle)
320 {

Callers

nothing calls this directly

Calls 5

applyVolumeFunction · 0.85
applyPitchFunction · 0.85
applyPanFunction · 0.85
push_backMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected