Fixed crash in MIDI to wave writer

This commit is contained in:
alexey.lysiuk 2018-03-08 11:38:02 +02:00
parent 6ab58e56ad
commit 7f17121df8
3 changed files with 10 additions and 5 deletions

View File

@ -198,7 +198,7 @@ protected:
class MIDIWaveWriter : public SoftSynthMIDIDevice class MIDIWaveWriter : public SoftSynthMIDIDevice
{ {
public: public:
MIDIWaveWriter(const char *filename, MIDIDevice *devtouse); MIDIWaveWriter(const char *filename, SoftSynthMIDIDevice *devtouse);
~MIDIWaveWriter(); ~MIDIWaveWriter();
int Resume(); int Resume();
int Open(MidiCallback cb, void *userdata) int Open(MidiCallback cb, void *userdata)

View File

@ -87,11 +87,11 @@ struct FmtChunk
// //
//========================================================================== //==========================================================================
MIDIWaveWriter::MIDIWaveWriter(const char *filename, MIDIDevice *playdevice) MIDIWaveWriter::MIDIWaveWriter(const char *filename, SoftSynthMIDIDevice *playdevice)
: SoftSynthMIDIDevice(playDevice->GetSampleRate()) : SoftSynthMIDIDevice(playdevice->GetSampleRate())
{ {
File = FileWriter::Open(filename); File = FileWriter::Open(filename);
playDevice = (SoftSynthMIDIDevice*) playdevice; playDevice = playdevice;
if (File != nullptr) if (File != nullptr)
{ // Write wave header { // Write wave header
uint32_t work[3]; uint32_t work[3];

View File

@ -319,8 +319,13 @@ bool MIDIStreamer::DumpWave(const char *filename, int subsong, int samplerate)
assert(MIDI == NULL); assert(MIDI == NULL);
auto devtype = SelectMIDIDevice(DeviceType); auto devtype = SelectMIDIDevice(DeviceType);
if (devtype == MDEV_MMAPI)
{
Printf("MMAPI device is not supported");
return false;
}
MIDI = CreateMIDIDevice(devtype, samplerate); MIDI = CreateMIDIDevice(devtype, samplerate);
MIDI = new MIDIWaveWriter(filename, MIDI); MIDI = new MIDIWaveWriter(filename, reinterpret_cast<SoftSynthMIDIDevice *>(MIDI));
return InitPlayback(); return InitPlayback();
} }