From c7b379483e3cd359c58ba56efe740ec456d2578f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 29 Sep 2019 22:54:13 +0200 Subject: [PATCH] - reordering code a bit to see where the stream must be started. --- src/sound/backend/i_soundinternal.h | 2 ++ src/sound/music/i_music.h | 1 + src/sound/musicformats/music_midistream.cpp | 27 ++++++++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/sound/backend/i_soundinternal.h b/src/sound/backend/i_soundinternal.h index d4df22733..e53761f59 100644 --- a/src/sound/backend/i_soundinternal.h +++ b/src/sound/backend/i_soundinternal.h @@ -121,8 +121,10 @@ const char *GetSampleTypeName(enum SampleType type); const char *GetChannelConfigName(enum ChannelConfig chan); class MusInfo; +class SoundStream; struct MusPlayingInfo { + SoundStream* musicStream; FString name; MusInfo *handle; int baseorder; diff --git a/src/sound/music/i_music.h b/src/sound/music/i_music.h index 31cf33093..655d3e355 100644 --- a/src/sound/music/i_music.h +++ b/src/sound/music/i_music.h @@ -82,6 +82,7 @@ public: virtual void ChangeSettingInt(const char *setting, int value); // FluidSynth settings virtual void ChangeSettingNum(const char *setting, double value); // " virtual void ChangeSettingString(const char *setting, const char *value); // " + virtual SoundStreamInfo GetStreamInfo() const { return { 0,0,0 }; } void Start(bool loop, float rel_vol = -1.f, int subsong = 0); diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index eea775621..31237422d 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -92,6 +92,7 @@ public: void ChangeSettingString(const char* setting, const char* value) override; int ServiceEvent(); void SetMIDISource(MIDISource* _source); + SoundStreamInfo GetStreamInfo() const override; int GetDeviceType() const override; @@ -142,7 +143,9 @@ protected: int LoopLimit; FString Args; std::unique_ptr source; + std::unique_ptr Stream; + }; @@ -425,21 +428,13 @@ bool MIDIStreamer::InitPlayback() source->CheckCaps(MIDI->GetTechnology()); if (!MIDI->CanHandleSysex()) source->SkipSysex(); - auto streamInfo = MIDI->GetStreamInfo(); - if (streamInfo.mBufferSize > 0) - { - Stream.reset(GSnd->CreateStream(FillStream, streamInfo.mBufferSize, streamInfo.mNumChannels == 1 ? SoundStream::Float | SoundStream::Mono : SoundStream::Float, streamInfo.mSampleRate, MIDI.get())); - } - StartPlayback(); if (MIDI == nullptr) { // The MIDI file had no content and has been automatically closed. return false; } - int res = 1; - if (Stream) res = Stream->Play(true, 1); - if (res) res = MIDI->Resume(); + int res = MIDI->Resume(); if (res) { @@ -448,10 +443,24 @@ bool MIDIStreamer::InitPlayback() else { m_Status = STATE_Playing; + + auto streamInfo = MIDI->GetStreamInfo(); + if (streamInfo.mBufferSize > 0) + { + Stream.reset(GSnd->CreateStream(FillStream, streamInfo.mBufferSize, streamInfo.mNumChannels == 1 ? SoundStream::Float | SoundStream::Mono : SoundStream::Float, streamInfo.mSampleRate, MIDI.get())); + } + + if (Stream) res = Stream->Play(true, 1); return true; } } +SoundStreamInfo MIDIStreamer::GetStreamInfo() const +{ + if (MIDI) return MIDI->GetStreamInfo(); + else return { 0, 0, 0 }; +} + //========================================================================== // // MIDIStreamer :: StartPlayback