MCPcopy Create free account
hub / github.com/EasyRPG/Player / PlayOnChannel

Method PlayOnChannel

src/audio_generic.cpp:220–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220bool GenericAudio::PlayOnChannel(BgmChannel& chan, Filesystem_Stream::InputStream filestream, int volume, int pitch, int fadein) {
221 chan.paused = true; // Pause channel so the audio thread doesn't work on it
222 chan.stopped = false; // Unstop channel so the audio thread doesn't delete it
223
224 if (!filestream) {
225 Output::Warning("BGM file not readable: {}", filestream.GetName());
226 return false;
227 }
228
229 // Midiout is only supported on channel 0 because this is an exclusive resource
230 if (chan.id == 0 && GenericAudioMidiOut::IsSupported(filestream)) {
231 chan.decoder.reset();
232
233 // Order is Fluidsynth, WildMidi, Native, FmMidi
234 bool fluidsynth = Audio().GetFluidsynthEnabled() && MidiDecoder::CreateFluidsynth(true);
235 bool wildmidi = Audio().GetWildMidiEnabled() && MidiDecoder::CreateWildMidi(true);
236
237 if (!fluidsynth && !wildmidi && Audio().GetNativeMidiEnabled()) {
238 CreateAndGetMidiOut();
239
240 if (midi_thread) {
241 midi_thread->LockMutex();
242 auto &midi_out = midi_thread->GetMidiOut();
243 if (midi_out.Open(std::move(filestream))) {
244 midi_out.SetPitch(pitch);
245 midi_out.SetVolume(0);
246 midi_out.SetFade(volume, std::chrono::milliseconds(fadein));
247 midi_out.SetLooping(true);
248 midi_out.Resume();
249 chan.paused = false;
250 chan.midi_out_used = true;
251 midi_thread->UnlockMutex();
252 return true;
253 }
254 midi_thread->UnlockMutex();
255 }
256 }
257 }
258
259 if (midi_thread) {
260 midi_thread->GetMidiOut().Reset();
261 }
262
263 chan.decoder = AudioDecoder::Create(filestream);
264 chan.midi_out_used = false;
265 if (chan.decoder && chan.decoder->Open(std::move(filestream))) {
266 chan.decoder->SetPitch(pitch);
267 chan.decoder->SetFormat(output_format.frequency, output_format.format, output_format.channels);
268 chan.decoder->SetVolume(0);
269 chan.decoder->SetFade(volume, std::chrono::milliseconds(fadein));
270 chan.decoder->SetLooping(true);
271 chan.paused = false; // Unpause channel -> Play it.
272
273 return true;
274 } else {
275 Output::Warning("Couldn't play BGM {}. Format not supported", filestream.GetName());
276 }
277

Callers

nothing calls this directly

Calls 15

GetFluidsynthEnabledMethod · 0.80
GetWildMidiEnabledMethod · 0.80
GetNativeMidiEnabledMethod · 0.80
CreateSeDecoderMethod · 0.80
GetNameMethod · 0.45
resetMethod · 0.45
LockMutexMethod · 0.45
OpenMethod · 0.45
SetPitchMethod · 0.45
SetVolumeMethod · 0.45
SetFadeMethod · 0.45
SetLoopingMethod · 0.45

Tested by

no test coverage detected