mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 20:21:26 +00:00
- use FileWriter for the Timidity MIDI dumper
This commit is contained in:
parent
e8735e2782
commit
5e7dfa7cce
2 changed files with 20 additions and 20 deletions
|
@ -239,7 +239,7 @@ public:
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FILE *File;
|
FileWriter *File;
|
||||||
};
|
};
|
||||||
|
|
||||||
// WildMidi implementation of a MIDI device ---------------------------------
|
// WildMidi implementation of a MIDI device ---------------------------------
|
||||||
|
|
|
@ -89,7 +89,7 @@ struct FmtChunk
|
||||||
|
|
||||||
TimidityMIDIDevice::TimidityMIDIDevice(const char *args)
|
TimidityMIDIDevice::TimidityMIDIDevice(const char *args)
|
||||||
{
|
{
|
||||||
Renderer = NULL;
|
Renderer = nullptr;
|
||||||
Renderer = new Timidity::Renderer((float)SampleRate, args);
|
Renderer = new Timidity::Renderer((float)SampleRate, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ TimidityMIDIDevice::TimidityMIDIDevice(const char *args)
|
||||||
TimidityMIDIDevice::~TimidityMIDIDevice()
|
TimidityMIDIDevice::~TimidityMIDIDevice()
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
if (Renderer != NULL)
|
if (Renderer != nullptr)
|
||||||
{
|
{
|
||||||
delete Renderer;
|
delete Renderer;
|
||||||
}
|
}
|
||||||
|
@ -246,10 +246,10 @@ FString TimidityMIDIDevice::GetStats()
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
TimidityWaveWriterMIDIDevice::TimidityWaveWriterMIDIDevice(const char *filename, int rate)
|
TimidityWaveWriterMIDIDevice::TimidityWaveWriterMIDIDevice(const char *filename, int rate)
|
||||||
:TimidityMIDIDevice(NULL)
|
:TimidityMIDIDevice(nullptr)
|
||||||
{
|
{
|
||||||
File = fopen(filename, "wb");
|
File = FileWriter::Open(filename);
|
||||||
if (File != NULL)
|
if (File != nullptr)
|
||||||
{ // Write wave header
|
{ // Write wave header
|
||||||
uint32_t work[3];
|
uint32_t work[3];
|
||||||
FmtChunk fmt;
|
FmtChunk fmt;
|
||||||
|
@ -257,7 +257,7 @@ TimidityWaveWriterMIDIDevice::TimidityWaveWriterMIDIDevice(const char *filename,
|
||||||
work[0] = MAKE_ID('R','I','F','F');
|
work[0] = MAKE_ID('R','I','F','F');
|
||||||
work[1] = 0; // filled in later
|
work[1] = 0; // filled in later
|
||||||
work[2] = MAKE_ID('W','A','V','E');
|
work[2] = MAKE_ID('W','A','V','E');
|
||||||
if (3 != fwrite(work, 4, 3, File)) goto fail;
|
if (4*3 != File->Write(work, 4 * 3)) goto fail;
|
||||||
|
|
||||||
fmt.ChunkID = MAKE_ID('f','m','t',' ');
|
fmt.ChunkID = MAKE_ID('f','m','t',' ');
|
||||||
fmt.ChunkLen = LittleLong(uint32_t(sizeof(fmt) - 8));
|
fmt.ChunkLen = LittleLong(uint32_t(sizeof(fmt) - 8));
|
||||||
|
@ -281,17 +281,17 @@ TimidityWaveWriterMIDIDevice::TimidityWaveWriterMIDIDevice(const char *filename,
|
||||||
fmt.SubFormatD[5] = 0x38;
|
fmt.SubFormatD[5] = 0x38;
|
||||||
fmt.SubFormatD[6] = 0x9b;
|
fmt.SubFormatD[6] = 0x9b;
|
||||||
fmt.SubFormatD[7] = 0x71;
|
fmt.SubFormatD[7] = 0x71;
|
||||||
if (1 != fwrite(&fmt, sizeof(fmt), 1, File)) goto fail;
|
if (sizeof(fmt) != File->Write(&fmt, sizeof(fmt))) goto fail;
|
||||||
|
|
||||||
work[0] = MAKE_ID('d','a','t','a');
|
work[0] = MAKE_ID('d','a','t','a');
|
||||||
work[1] = 0; // filled in later
|
work[1] = 0; // filled in later
|
||||||
if (2 != fwrite(work, 4, 2, File)) goto fail;
|
if (8 !=File->Write(work, 8)) goto fail;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
fail:
|
fail:
|
||||||
Printf("Failed to write %s: %s\n", filename, strerror(errno));
|
Printf("Failed to write %s: %s\n", filename, strerror(errno));
|
||||||
fclose(File);
|
delete File;
|
||||||
File = NULL;
|
File = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,30 +303,30 @@ fail:
|
||||||
|
|
||||||
TimidityWaveWriterMIDIDevice::~TimidityWaveWriterMIDIDevice()
|
TimidityWaveWriterMIDIDevice::~TimidityWaveWriterMIDIDevice()
|
||||||
{
|
{
|
||||||
if (File != NULL)
|
if (File != nullptr)
|
||||||
{
|
{
|
||||||
long pos = ftell(File);
|
long pos = File->Tell();
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
|
||||||
// data chunk size
|
// data chunk size
|
||||||
size = LittleLong(uint32_t(pos - 8));
|
size = LittleLong(uint32_t(pos - 8));
|
||||||
if (0 == fseek(File, 4, SEEK_SET))
|
if (0 == File->Seek(4, SEEK_SET))
|
||||||
{
|
{
|
||||||
if (1 == fwrite(&size, 4, 1, File))
|
if (4 == File->Write(&size, 4))
|
||||||
{
|
{
|
||||||
size = LittleLong(uint32_t(pos - 12 - sizeof(FmtChunk) - 8));
|
size = LittleLong(uint32_t(pos - 12 - sizeof(FmtChunk) - 8));
|
||||||
if (0 == fseek(File, 4 + sizeof(FmtChunk) + 4, SEEK_CUR))
|
if (0 == File->Seek(4 + sizeof(FmtChunk) + 4, SEEK_CUR))
|
||||||
{
|
{
|
||||||
if (1 == fwrite(&size, 4, 1, File))
|
if (1 == File->Write(&size, 4))
|
||||||
{
|
{
|
||||||
fclose(File);
|
delete File;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Printf("Could not finish writing wave file: %s\n", strerror(errno));
|
Printf("Could not finish writing wave file: %s\n", strerror(errno));
|
||||||
fclose(File);
|
delete File;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ int TimidityWaveWriterMIDIDevice::Resume()
|
||||||
|
|
||||||
while (ServiceStream(writebuffer, sizeof(writebuffer)))
|
while (ServiceStream(writebuffer, sizeof(writebuffer)))
|
||||||
{
|
{
|
||||||
if (fwrite(writebuffer, sizeof(writebuffer), 1, File) != 1)
|
if (File->Write(writebuffer, sizeof(writebuffer)) != sizeof(writebuffer))
|
||||||
{
|
{
|
||||||
Printf("Could not write entire wave file: %s\n", strerror(errno));
|
Printf("Could not write entire wave file: %s\n", strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue