- reordering code a bit to see where the stream must be started.

This commit is contained in:
Christoph Oelckers 2019-09-29 22:54:13 +02:00
parent d06ec56c2e
commit c7b379483e
3 changed files with 21 additions and 9 deletions

View file

@ -121,8 +121,10 @@ const char *GetSampleTypeName(enum SampleType type);
const char *GetChannelConfigName(enum ChannelConfig chan); const char *GetChannelConfigName(enum ChannelConfig chan);
class MusInfo; class MusInfo;
class SoundStream;
struct MusPlayingInfo struct MusPlayingInfo
{ {
SoundStream* musicStream;
FString name; FString name;
MusInfo *handle; MusInfo *handle;
int baseorder; int baseorder;

View file

@ -82,6 +82,7 @@ public:
virtual void ChangeSettingInt(const char *setting, int value); // FluidSynth settings virtual void ChangeSettingInt(const char *setting, int value); // FluidSynth settings
virtual void ChangeSettingNum(const char *setting, double value); // " virtual void ChangeSettingNum(const char *setting, double value); // "
virtual void ChangeSettingString(const char *setting, const char *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); void Start(bool loop, float rel_vol = -1.f, int subsong = 0);

View file

@ -92,6 +92,7 @@ public:
void ChangeSettingString(const char* setting, const char* value) override; void ChangeSettingString(const char* setting, const char* value) override;
int ServiceEvent(); int ServiceEvent();
void SetMIDISource(MIDISource* _source); void SetMIDISource(MIDISource* _source);
SoundStreamInfo GetStreamInfo() const override;
int GetDeviceType() const override; int GetDeviceType() const override;
@ -142,7 +143,9 @@ protected:
int LoopLimit; int LoopLimit;
FString Args; FString Args;
std::unique_ptr<MIDISource> source; std::unique_ptr<MIDISource> source;
std::unique_ptr<SoundStream> Stream; std::unique_ptr<SoundStream> Stream;
}; };
@ -425,21 +428,13 @@ bool MIDIStreamer::InitPlayback()
source->CheckCaps(MIDI->GetTechnology()); source->CheckCaps(MIDI->GetTechnology());
if (!MIDI->CanHandleSysex()) source->SkipSysex(); 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(); StartPlayback();
if (MIDI == nullptr) if (MIDI == nullptr)
{ // The MIDI file had no content and has been automatically closed. { // The MIDI file had no content and has been automatically closed.
return false; return false;
} }
int res = 1; int res = MIDI->Resume();
if (Stream) res = Stream->Play(true, 1);
if (res) res = MIDI->Resume();
if (res) if (res)
{ {
@ -448,10 +443,24 @@ bool MIDIStreamer::InitPlayback()
else else
{ {
m_Status = STATE_Playing; 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; return true;
} }
} }
SoundStreamInfo MIDIStreamer::GetStreamInfo() const
{
if (MIDI) return MIDI->GetStreamInfo();
else return { 0, 0, 0 };
}
//========================================================================== //==========================================================================
// //
// MIDIStreamer :: StartPlayback // MIDIStreamer :: StartPlayback