mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +00:00
- got rid of std::auto_ptr, courtesy of Blzut3's patch.
This commit is contained in:
parent
d880783784
commit
6bb79be85c
22 changed files with 181 additions and 167 deletions
|
@ -26,7 +26,6 @@
|
|||
#include <io.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <memory>
|
||||
|
||||
#include "i_system.h"
|
||||
#include "i_sound.h"
|
||||
|
@ -2434,7 +2433,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
|||
musicname += 7;
|
||||
}
|
||||
|
||||
std::auto_ptr<FileReader> reader;
|
||||
FileReader *reader = NULL;
|
||||
if (!FileExists (musicname))
|
||||
{
|
||||
if ((lumpnum = Wads.CheckNumForFullName (musicname, true, ns_music)) == -1)
|
||||
|
@ -2472,7 +2471,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
|||
musiccache.Resize(length);
|
||||
Wads.ReadLump(lumpnum, &musiccache[0]);
|
||||
|
||||
reader.reset(new MemoryReader((const char*)&musiccache[0], musiccache.Size()));
|
||||
reader = new MemoryReader((const char*)&musiccache[0], musiccache.Size());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2480,14 +2479,14 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
|||
{
|
||||
return false;
|
||||
}
|
||||
reader.reset(Wads.ReopenLumpNum(lumpnum));
|
||||
reader = Wads.ReopenLumpNum(lumpnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Load an external file.
|
||||
reader.reset(new FileReader(musicname));
|
||||
reader = new FileReader(musicname);
|
||||
}
|
||||
|
||||
// shutdown old music
|
||||
|
@ -2500,6 +2499,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
|||
mus_playing.name = musicname;
|
||||
mus_playing.baseorder = order;
|
||||
LastSong = musicname;
|
||||
delete reader;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2507,6 +2507,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
|||
if (handle != NULL)
|
||||
{
|
||||
mus_playing.handle = handle;
|
||||
delete reader;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -304,12 +304,12 @@ class FMODStreamCapsule : public SoundStream
|
|||
public:
|
||||
FMODStreamCapsule(FMOD::Sound *stream, FMODSoundRenderer *owner, const char *url)
|
||||
: Owner(owner), Stream(NULL), Channel(NULL),
|
||||
UserData(NULL), Callback(NULL), URL(url), Ended(false)
|
||||
UserData(NULL), Callback(NULL), URL(url), Reader(NULL), Ended(false)
|
||||
{
|
||||
SetStream(stream);
|
||||
}
|
||||
|
||||
FMODStreamCapsule(FMOD::Sound *stream, FMODSoundRenderer *owner, std::auto_ptr<FileReader> reader)
|
||||
FMODStreamCapsule(FMOD::Sound *stream, FMODSoundRenderer *owner, FileReader *reader)
|
||||
: Owner(owner), Stream(NULL), Channel(NULL),
|
||||
UserData(NULL), Callback(NULL), Reader(reader), Ended(false)
|
||||
{
|
||||
|
@ -318,7 +318,7 @@ public:
|
|||
|
||||
FMODStreamCapsule(void *udata, SoundStreamCallback callback, FMODSoundRenderer *owner)
|
||||
: Owner(owner), Stream(NULL), Channel(NULL),
|
||||
UserData(udata), Callback(callback), Ended(false)
|
||||
UserData(udata), Callback(callback), Reader(NULL), Ended(false)
|
||||
{}
|
||||
|
||||
~FMODStreamCapsule()
|
||||
|
@ -331,6 +331,7 @@ public:
|
|||
{
|
||||
Stream->release();
|
||||
}
|
||||
delete Reader;
|
||||
}
|
||||
|
||||
void SetStream(FMOD::Sound *stream)
|
||||
|
@ -600,7 +601,7 @@ private:
|
|||
FMOD::Channel *Channel;
|
||||
void *UserData;
|
||||
SoundStreamCallback Callback;
|
||||
std::auto_ptr<FileReader> Reader;
|
||||
FileReader *Reader;
|
||||
FString URL;
|
||||
bool Ended;
|
||||
bool JustStarted;
|
||||
|
@ -1645,7 +1646,7 @@ static FMOD_RESULT F_CALLBACK seek_reader_callback(void *handle, unsigned int po
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
SoundStream *FMODSoundRenderer::OpenStream(std::auto_ptr<FileReader> reader, int flags)
|
||||
SoundStream *FMODSoundRenderer::OpenStream(FileReader *reader, int flags)
|
||||
{
|
||||
FMOD_MODE mode;
|
||||
FMOD_CREATESOUNDEXINFO exinfo;
|
||||
|
@ -1681,7 +1682,7 @@ SoundStream *FMODSoundRenderer::OpenStream(std::auto_ptr<FileReader> reader, int
|
|||
exinfo.dlsname = patches;
|
||||
}
|
||||
|
||||
name.Format("_FileReader_%p", reader.get());
|
||||
name.Format("_FileReader_%p", reader);
|
||||
result = Sys->createSound(name, mode, &exinfo, &stream);
|
||||
if(result == FMOD_ERR_FORMAT && exinfo.dlsname != NULL)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
|
||||
// Streaming sounds.
|
||||
SoundStream *CreateStream (SoundStreamCallback callback, int buffsamples, int flags, int samplerate, void *userdata);
|
||||
SoundStream *OpenStream (std::auto_ptr<FileReader> reader, int flags);
|
||||
SoundStream *OpenStream (FileReader *reader, int flags);
|
||||
SoundStream *OpenStream (const char *url, int flags);
|
||||
|
||||
// Starts a sound.
|
||||
|
|
|
@ -301,7 +301,7 @@ MusInfo *MusInfo::GetWaveDumper(const char *filename, int rate)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
static MIDIStreamer *CreateMIDIStreamer(std::auto_ptr<FileReader> &reader, EMidiDevice devtype, EMIDIType miditype)
|
||||
static MIDIStreamer *CreateMIDIStreamer(FileReader &reader, EMidiDevice devtype, EMIDIType miditype)
|
||||
{
|
||||
switch (miditype)
|
||||
{
|
||||
|
@ -377,22 +377,23 @@ static EMIDIType IdentifyMIDIType(DWORD *id, int size)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
MusInfo *I_RegisterSong (std::auto_ptr<FileReader> reader, int device)
|
||||
MusInfo *I_RegisterSong (FileReader *reader, int device)
|
||||
{
|
||||
MusInfo *info = NULL;
|
||||
const char *fmt;
|
||||
DWORD id[32/4];
|
||||
int i;
|
||||
|
||||
if (nomusic)
|
||||
{
|
||||
delete reader;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(reader->Read(id, 32) != 32 || reader->Seek(-32, SEEK_CUR) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(reader->Read(id, 32) != 32 || reader->Seek(-32, SEEK_CUR) != 0)
|
||||
{
|
||||
delete reader;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
// non-Windows platforms don't support MDEV_MMAPI so map to MDEV_SNDSYS
|
||||
|
@ -403,31 +404,35 @@ MusInfo *I_RegisterSong (std::auto_ptr<FileReader> reader, int device)
|
|||
// Check for gzip compression. Some formats are expected to have players
|
||||
// that can handle it, so it simplifies things if we make all songs
|
||||
// gzippable.
|
||||
if ((id[0] & MAKE_ID(255,255,255,0)) == GZIP_ID)
|
||||
{
|
||||
int len = reader->GetLength();
|
||||
BYTE *gzipped = new BYTE[len];
|
||||
if (reader->Read(gzipped, len) != len)
|
||||
{
|
||||
delete[] gzipped;
|
||||
return NULL;
|
||||
}
|
||||
if ((id[0] & MAKE_ID(255, 255, 255, 0)) == GZIP_ID)
|
||||
{
|
||||
int len = reader->GetLength();
|
||||
BYTE *gzipped = new BYTE[len];
|
||||
if (reader->Read(gzipped, len) != len)
|
||||
{
|
||||
delete[] gzipped;
|
||||
delete reader;
|
||||
return NULL;
|
||||
}
|
||||
delete reader;
|
||||
|
||||
std::auto_ptr<MemoryArrayReader> reader2(new MemoryArrayReader(NULL, 0));
|
||||
if(!ungzip(gzipped, len, reader2->GetArray()))
|
||||
{
|
||||
delete[] gzipped;
|
||||
return 0;
|
||||
}
|
||||
delete[] gzipped;
|
||||
reader2->UpdateLength();
|
||||
MemoryArrayReader *memreader = new MemoryArrayReader(NULL, 0);
|
||||
if (!ungzip(gzipped, len, memreader->GetArray()))
|
||||
{
|
||||
delete[] gzipped;
|
||||
delete memreader;
|
||||
return 0;
|
||||
}
|
||||
delete[] gzipped;
|
||||
memreader->UpdateLength();
|
||||
|
||||
reader.reset(reader2.release());
|
||||
if(reader->Read(id, 32) != 32 || reader->Seek(-32, SEEK_CUR) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (memreader->Read(id, 32) != 32 || memreader->Seek(-32, SEEK_CUR) != 0)
|
||||
{
|
||||
delete memreader;
|
||||
return 0;
|
||||
}
|
||||
reader = memreader;
|
||||
}
|
||||
|
||||
EMIDIType miditype = IdentifyMIDIType(id, sizeof(id));
|
||||
if (miditype != MIDI_NOTMIDI)
|
||||
|
@ -435,7 +440,7 @@ MusInfo *I_RegisterSong (std::auto_ptr<FileReader> reader, int device)
|
|||
EMidiDevice devtype = (EMidiDevice)device;
|
||||
|
||||
retry_as_sndsys:
|
||||
info = CreateMIDIStreamer(reader, devtype, miditype);
|
||||
info = CreateMIDIStreamer(*reader, devtype, miditype);
|
||||
if (info != NULL && !info->IsValid())
|
||||
{
|
||||
delete info;
|
||||
|
@ -449,7 +454,7 @@ retry_as_sndsys:
|
|||
#ifdef _WIN32
|
||||
if (info == NULL && devtype != MDEV_MMAPI && snd_mididevice >= 0)
|
||||
{
|
||||
info = CreateMIDIStreamer(reader, MDEV_MMAPI, miditype);
|
||||
info = CreateMIDIStreamer(*reader, MDEV_MMAPI, miditype);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -460,17 +465,17 @@ retry_as_sndsys:
|
|||
(id[0] == MAKE_ID('D','B','R','A') && id[1] == MAKE_ID('W','O','P','L')) || // DosBox Raw OPL
|
||||
(id[0] == MAKE_ID('A','D','L','I') && *((BYTE *)id + 4) == 'B')) // Martin Fernandez's modified IMF
|
||||
{
|
||||
info = new OPLMUSSong (reader);
|
||||
info = new OPLMUSSong (*reader);
|
||||
}
|
||||
// Check for game music
|
||||
else if ((fmt = GME_CheckFormat(id[0])) != NULL && fmt[0] != '\0')
|
||||
{
|
||||
info = GME_OpenSong(reader, fmt);
|
||||
info = GME_OpenSong(*reader, fmt);
|
||||
}
|
||||
// Check for module formats
|
||||
else
|
||||
{
|
||||
info = MOD_OpenSong(reader);
|
||||
info = MOD_OpenSong(*reader);
|
||||
}
|
||||
|
||||
if (info == NULL)
|
||||
|
@ -483,6 +488,7 @@ retry_as_sndsys:
|
|||
reader->Seek(8, SEEK_CUR);
|
||||
if (reader->Read (&subid, 4) != 4)
|
||||
{
|
||||
delete reader;
|
||||
return 0;
|
||||
}
|
||||
reader->Seek(-12, SEEK_CUR);
|
||||
|
@ -490,7 +496,7 @@ retry_as_sndsys:
|
|||
if (subid == (('C')|(('D')<<8)|(('D')<<16)|(('A')<<24)))
|
||||
{
|
||||
// This is a CDDA file
|
||||
info = new CDDAFile (reader);
|
||||
info = new CDDAFile (*reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,9 +509,13 @@ retry_as_sndsys:
|
|||
{
|
||||
// Let the sound system figure out what it is.
|
||||
info = new StreamSong (reader);
|
||||
// Assumed ownership
|
||||
reader = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (reader != NULL) delete reader;
|
||||
|
||||
if (info && !info->IsValid ())
|
||||
{
|
||||
delete info;
|
||||
|
|
|
@ -34,8 +34,6 @@
|
|||
#ifndef __I_MUSIC_H__
|
||||
#define __I_MUSIC_H__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "doomdef.h"
|
||||
|
||||
class FileReader;
|
||||
|
@ -54,7 +52,7 @@ void I_SetMusicVolume (float volume);
|
|||
|
||||
// Registers a song handle to song data.
|
||||
class MusInfo;
|
||||
MusInfo *I_RegisterSong (std::auto_ptr<FileReader> reader, int device);
|
||||
MusInfo *I_RegisterSong (FileReader *reader, int device);
|
||||
MusInfo *I_RegisterCDSong (int track, int cdid = 0);
|
||||
MusInfo *I_RegisterURLSong (const char *url);
|
||||
|
||||
|
|
|
@ -501,7 +501,7 @@ protected:
|
|||
class MUSSong2 : public MIDIStreamer
|
||||
{
|
||||
public:
|
||||
MUSSong2(std::auto_ptr<FileReader> reader, EMidiDevice type);
|
||||
MUSSong2(FileReader &reader, EMidiDevice type);
|
||||
~MUSSong2();
|
||||
|
||||
MusInfo *GetOPLDumper(const char *filename);
|
||||
|
@ -527,7 +527,7 @@ protected:
|
|||
class MIDISong2 : public MIDIStreamer
|
||||
{
|
||||
public:
|
||||
MIDISong2(std::auto_ptr<FileReader> reader, EMidiDevice type);
|
||||
MIDISong2(FileReader &reader, EMidiDevice type);
|
||||
~MIDISong2();
|
||||
|
||||
MusInfo *GetOPLDumper(const char *filename);
|
||||
|
@ -584,7 +584,7 @@ protected:
|
|||
class HMISong : public MIDIStreamer
|
||||
{
|
||||
public:
|
||||
HMISong(std::auto_ptr<FileReader> reader, EMidiDevice type);
|
||||
HMISong(FileReader &reader, EMidiDevice type);
|
||||
~HMISong();
|
||||
|
||||
MusInfo *GetOPLDumper(const char *filename);
|
||||
|
@ -627,7 +627,7 @@ protected:
|
|||
class XMISong : public MIDIStreamer
|
||||
{
|
||||
public:
|
||||
XMISong(std::auto_ptr<FileReader> reader, EMidiDevice type);
|
||||
XMISong(FileReader &reader, EMidiDevice type);
|
||||
~XMISong();
|
||||
|
||||
MusInfo *GetOPLDumper(const char *filename);
|
||||
|
@ -666,7 +666,7 @@ protected:
|
|||
class StreamSong : public MusInfo
|
||||
{
|
||||
public:
|
||||
StreamSong (std::auto_ptr<FileReader> reader);
|
||||
StreamSong (FileReader *reader);
|
||||
StreamSong (const char *url);
|
||||
~StreamSong ();
|
||||
void Play (bool looping, int subsong);
|
||||
|
@ -690,7 +690,7 @@ protected:
|
|||
class OPLMUSSong : public StreamSong
|
||||
{
|
||||
public:
|
||||
OPLMUSSong (std::auto_ptr<FileReader> reader);
|
||||
OPLMUSSong (FileReader &reader);
|
||||
~OPLMUSSong ();
|
||||
void Play (bool looping, int subsong);
|
||||
bool IsPlaying ();
|
||||
|
@ -739,17 +739,17 @@ protected:
|
|||
class CDDAFile : public CDSong
|
||||
{
|
||||
public:
|
||||
CDDAFile (std::auto_ptr<FileReader> reader);
|
||||
CDDAFile (FileReader &reader);
|
||||
};
|
||||
|
||||
// Module played via foo_dumb -----------------------------------------------
|
||||
|
||||
MusInfo *MOD_OpenSong(std::auto_ptr<FileReader> &reader);
|
||||
MusInfo *MOD_OpenSong(FileReader &reader);
|
||||
|
||||
// Music played via Game Music Emu ------------------------------------------
|
||||
|
||||
const char *GME_CheckFormat(uint32 header);
|
||||
MusInfo *GME_OpenSong(std::auto_ptr<FileReader> &reader, const char *fmt);
|
||||
MusInfo *GME_OpenSong(FileReader &reader, const char *fmt);
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ extern HINSTANCE g_hInst;
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <memory>
|
||||
|
||||
#include "doomtype.h"
|
||||
#include <math.h>
|
||||
|
@ -173,8 +172,9 @@ public:
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
SoundStream *OpenStream (std::auto_ptr<FileReader> reader, int flags)
|
||||
SoundStream *OpenStream (FileReader *reader, int flags)
|
||||
{
|
||||
delete reader;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -372,17 +372,19 @@ short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes,
|
|||
SampleType type;
|
||||
int srate;
|
||||
|
||||
std::auto_ptr<SoundDecoder> decoder(CreateDecoder(&reader));
|
||||
if(!decoder.get()) return samples;
|
||||
SoundDecoder *decoder = CreateDecoder(&reader);
|
||||
if(!decoder) return samples;
|
||||
|
||||
decoder->getInfo(&srate, &chans, &type);
|
||||
if(chans != ChannelConfig_Mono || type != SampleType_Int16)
|
||||
{
|
||||
DPrintf("Sample is not 16-bit mono\n");
|
||||
delete decoder;
|
||||
return samples;
|
||||
}
|
||||
|
||||
decoder->read((char*)samples, outlen);
|
||||
delete decoder;
|
||||
return samples;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,6 @@
|
|||
#ifndef __I_SOUND__
|
||||
#define __I_SOUND__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "i_soundinternal.h"
|
||||
|
||||
|
@ -107,7 +105,7 @@ public:
|
|||
|
||||
// Streaming sounds.
|
||||
virtual SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) = 0;
|
||||
virtual SoundStream *OpenStream (std::auto_ptr<FileReader> reader, int flags) = 0;
|
||||
virtual SoundStream *OpenStream (FileReader *reader, int flags) = 0;
|
||||
virtual SoundStream *OpenStream (const char *url, int flags);
|
||||
|
||||
// Starts a sound.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef __SNDINT_H
|
||||
#define __SNDINT_H
|
||||
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "basictypes.h"
|
||||
|
|
|
@ -79,31 +79,31 @@ bool CDSong::IsPlaying ()
|
|||
return m_Status != STATE_Stopped;
|
||||
}
|
||||
|
||||
CDDAFile::CDDAFile (std::auto_ptr<FileReader> reader)
|
||||
CDDAFile::CDDAFile (FileReader &reader)
|
||||
: CDSong ()
|
||||
{
|
||||
DWORD chunk;
|
||||
WORD track;
|
||||
DWORD discid;
|
||||
long endpos = reader->Tell() + reader->GetLength() - 8;
|
||||
long endpos = reader.Tell() + reader.GetLength() - 8;
|
||||
|
||||
// I_RegisterSong already identified this as a CDDA file, so we
|
||||
// just need to check the contents we're interested in.
|
||||
reader->Seek(12, SEEK_CUR);
|
||||
reader.Seek(12, SEEK_CUR);
|
||||
|
||||
while (reader->Tell() < endpos)
|
||||
while (reader.Tell() < endpos)
|
||||
{
|
||||
reader->Read(&chunk, 4);
|
||||
reader.Read(&chunk, 4);
|
||||
if (chunk != (('f')|(('m')<<8)|(('t')<<16)|((' ')<<24)))
|
||||
{
|
||||
reader->Read(&chunk, 4);
|
||||
reader->Seek(chunk, SEEK_CUR);
|
||||
reader.Read(&chunk, 4);
|
||||
reader.Seek(chunk, SEEK_CUR);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader->Seek(6, SEEK_CUR);
|
||||
reader->Read(&track, 2);
|
||||
reader->Read(&discid, 4);
|
||||
reader.Seek(6, SEEK_CUR);
|
||||
reader.Read(&track, 2);
|
||||
reader.Read(&discid, 4);
|
||||
|
||||
if (CD_InitID (discid) && CD_CheckTrack (track))
|
||||
{
|
||||
|
|
|
@ -532,7 +532,7 @@ static DUMBFILE_SYSTEM mem_dfs = {
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, BYTE *start, std::auto_ptr<FileReader> &reader, int lenhave, int lenfull)
|
||||
DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, BYTE *start, FileReader &reader, int lenhave, int lenfull)
|
||||
{
|
||||
filestate->size = lenfull;
|
||||
filestate->offset = 0;
|
||||
|
@ -542,7 +542,7 @@ DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, BYTE *start, std::au
|
|||
{
|
||||
BYTE *mem = new BYTE[lenfull];
|
||||
memcpy(mem, start, lenhave);
|
||||
if (reader->Read(mem + lenhave, lenfull - lenhave) != (lenfull - lenhave))
|
||||
if (reader.Read(mem + lenhave, lenfull - lenhave) != (lenfull - lenhave))
|
||||
{
|
||||
delete[] mem;
|
||||
return NULL;
|
||||
|
@ -747,7 +747,7 @@ static void MOD_SetAutoChip(DUH *duh)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
MusInfo *MOD_OpenSong(std::auto_ptr<FileReader> &reader)
|
||||
MusInfo *MOD_OpenSong(FileReader &reader)
|
||||
{
|
||||
DUH *duh = 0;
|
||||
int headsize;
|
||||
|
@ -771,14 +771,14 @@ MusInfo *MOD_OpenSong(std::auto_ptr<FileReader> &reader)
|
|||
|
||||
atterm(dumb_exit);
|
||||
|
||||
int size = reader->GetLength();
|
||||
fpos = reader->Tell();
|
||||
int size = reader.GetLength();
|
||||
fpos = reader.Tell();
|
||||
|
||||
filestate.ptr = start;
|
||||
filestate.offset = 0;
|
||||
headsize = MIN((int)sizeof(start), size);
|
||||
|
||||
if (headsize != reader->Read(start, headsize))
|
||||
if (headsize != reader.Read(start, headsize))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -890,7 +890,7 @@ MusInfo *MOD_OpenSong(std::auto_ptr<FileReader> &reader)
|
|||
{
|
||||
if (!(f = dumb_read_allfile(&filestate, start, reader, headsize, size)))
|
||||
{
|
||||
reader->Seek(fpos, SEEK_SET);
|
||||
reader.Seek(fpos, SEEK_SET);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -931,13 +931,12 @@ MusInfo *MOD_OpenSong(std::auto_ptr<FileReader> &reader)
|
|||
else
|
||||
{
|
||||
// Reposition file pointer for other codecs to do their checks.
|
||||
reader->Seek(fpos, SEEK_SET);
|
||||
reader.Seek(fpos, SEEK_SET);
|
||||
}
|
||||
if (filestate.ptr != (BYTE *)start)
|
||||
{
|
||||
delete[] const_cast<BYTE *>(filestate.ptr);
|
||||
}
|
||||
if(state) reader.reset();
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ const char *GME_CheckFormat(uint32 id)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
MusInfo *GME_OpenSong(std::auto_ptr<FileReader> &reader, const char *fmt)
|
||||
MusInfo *GME_OpenSong(FileReader &reader, const char *fmt)
|
||||
{
|
||||
gme_type_t type;
|
||||
gme_err_t err;
|
||||
|
@ -125,14 +125,14 @@ MusInfo *GME_OpenSong(std::auto_ptr<FileReader> &reader, const char *fmt)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int fpos = reader->Tell();
|
||||
int len = reader->GetLength();
|
||||
int fpos = reader.Tell();
|
||||
int len = reader.GetLength();
|
||||
song = new BYTE[len];
|
||||
if (reader->Read(song, len) != len)
|
||||
if (reader.Read(song, len) != len)
|
||||
{
|
||||
delete[] song;
|
||||
gme_delete(emu);
|
||||
reader->Seek(fpos, SEEK_SET);
|
||||
reader.Seek(fpos, SEEK_SET);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -143,10 +143,9 @@ MusInfo *GME_OpenSong(std::auto_ptr<FileReader> &reader, const char *fmt)
|
|||
{
|
||||
Printf("Failed loading song: %s\n", err);
|
||||
gme_delete(emu);
|
||||
reader->Seek(fpos, SEEK_SET);
|
||||
reader.Seek(fpos, SEEK_SET);
|
||||
return NULL;
|
||||
}
|
||||
reader.reset();
|
||||
return new GMESong(emu, sample_rate);
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ extern char MIDI_CommonLengths[15];
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
HMISong::HMISong (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
||||
HMISong::HMISong (FileReader &reader, EMidiDevice type)
|
||||
: MIDIStreamer(type), MusHeader(0), Tracks(0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
@ -137,7 +137,7 @@ HMISong::HMISong (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
|||
return;
|
||||
}
|
||||
#endif
|
||||
int len = reader->GetLength();
|
||||
int len = reader.GetLength();
|
||||
if (len < 0x100)
|
||||
{ // Way too small to be HMI.
|
||||
return;
|
||||
|
@ -145,7 +145,7 @@ HMISong::HMISong (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
|||
MusHeader = new BYTE[len];
|
||||
SongLen = len;
|
||||
NumTracks = 0;
|
||||
if (reader->Read(MusHeader, len) != len)
|
||||
if (reader.Read(MusHeader, len) != len)
|
||||
return;
|
||||
|
||||
// Do some validation of the MIDI file
|
||||
|
|
|
@ -92,7 +92,7 @@ static const BYTE CtrlTranslate[15] =
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
MUSSong2::MUSSong2 (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
||||
MUSSong2::MUSSong2 (FileReader &reader, EMidiDevice type)
|
||||
: MIDIStreamer(type), MusHeader(0), MusBuffer(0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
@ -105,7 +105,7 @@ MUSSong2::MUSSong2 (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
|||
BYTE front[32];
|
||||
int start;
|
||||
|
||||
if (reader->Read(front, sizeof(front)) != sizeof(front))
|
||||
if (reader.Read(front, sizeof(front)) != sizeof(front))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -121,14 +121,14 @@ MUSSong2::MUSSong2 (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
|||
}
|
||||
|
||||
// Read the remainder of the song.
|
||||
int len = int(reader->GetLength() - start);
|
||||
int len = int(reader.GetLength() - start);
|
||||
if (len < (int)sizeof(MusHeader))
|
||||
{ // It's too short.
|
||||
return;
|
||||
}
|
||||
MusHeader = (MUSHeader *)new BYTE[len];
|
||||
memcpy(MusHeader, front + start, sizeof(front) - start);
|
||||
if (reader->Read((BYTE *)MusHeader + sizeof(front) - start, len - (sizeof(front) - start)) != (len - (32 - start)))
|
||||
if (reader.Read((BYTE *)MusHeader + sizeof(front) - start, len - (sizeof(front) - start)) != (len - (32 - start)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@ CUSTOM_CVAR (Int, opl_numchips, 2, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|||
|
||||
CVAR(Int, opl_core, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
|
||||
OPLMUSSong::OPLMUSSong (std::auto_ptr<FileReader> reader)
|
||||
OPLMUSSong::OPLMUSSong (FileReader &reader)
|
||||
{
|
||||
int samples = int(OPL_SAMPLE_RATE / 14);
|
||||
|
||||
Music = new OPLmusicFile (reader.get());
|
||||
Music = new OPLmusicFile (&reader);
|
||||
|
||||
m_Stream = GSnd->CreateStream (FillStream, samples*4,
|
||||
(opl_core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this);
|
||||
|
|
|
@ -254,12 +254,11 @@ int SndSysMIDIDevice::Open(void (*callback)(unsigned int, void *, DWORD, DWORD),
|
|||
|
||||
bool SndSysMIDIDevice::Preprocess(MIDIStreamer *song, bool looping)
|
||||
{
|
||||
std::auto_ptr<MemoryArrayReader> reader(new MemoryArrayReader(NULL, 0));
|
||||
MemoryArrayReader *reader = new MemoryArrayReader(NULL, 0);
|
||||
song->CreateSMF(reader->GetArray(), looping ? 0 : 1);
|
||||
reader->UpdateLength();
|
||||
|
||||
bLooping = looping;
|
||||
Stream = GSnd->OpenStream(std::auto_ptr<FileReader>(reader.release()),
|
||||
looping ? SoundStream::Loop : 0);
|
||||
Stream = GSnd->OpenStream(reader, looping ? SoundStream::Loop : 0);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ char MIDI_CommonLengths[15] = { 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
MIDISong2::MIDISong2 (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
||||
MIDISong2::MIDISong2 (FileReader &reader, EMidiDevice type)
|
||||
: MIDIStreamer(type), MusHeader(0), Tracks(0)
|
||||
{
|
||||
int p;
|
||||
|
@ -114,9 +114,9 @@ MIDISong2::MIDISong2 (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
|||
return;
|
||||
}
|
||||
#endif
|
||||
SongLen = reader->GetLength();
|
||||
SongLen = reader.GetLength();
|
||||
MusHeader = new BYTE[SongLen];
|
||||
if (reader->Read(MusHeader, SongLen) != SongLen)
|
||||
if (reader.Read(MusHeader, SongLen) != SongLen)
|
||||
return;
|
||||
|
||||
// Do some validation of the MIDI file
|
||||
|
|
|
@ -52,7 +52,7 @@ StreamSong::~StreamSong ()
|
|||
}
|
||||
}
|
||||
|
||||
StreamSong::StreamSong (std::auto_ptr<FileReader> reader)
|
||||
StreamSong::StreamSong (FileReader *reader)
|
||||
{
|
||||
m_Stream = GSnd->OpenStream (reader, SoundStream::Loop);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ extern char MIDI_CommonLengths[15];
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
XMISong::XMISong (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
||||
XMISong::XMISong (FileReader &reader, EMidiDevice type)
|
||||
: MIDIStreamer(type), MusHeader(0), Songs(0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
@ -117,9 +117,9 @@ XMISong::XMISong (std::auto_ptr<FileReader> reader, EMidiDevice type)
|
|||
return;
|
||||
}
|
||||
#endif
|
||||
SongLen = reader->GetLength();
|
||||
SongLen = reader.GetLength();
|
||||
MusHeader = new BYTE[SongLen];
|
||||
if (reader->Read(MusHeader, SongLen) != SongLen)
|
||||
if (reader.Read(MusHeader, SongLen) != SongLen)
|
||||
return;
|
||||
|
||||
// Find all the songs in this file.
|
||||
|
|
|
@ -82,19 +82,14 @@ void I_BuildALDeviceList(FOptionValues *opt)
|
|||
names += strlen(names) + 1;
|
||||
}
|
||||
}
|
||||
__except (CheckException(GetExceptionCode()))
|
||||
{
|
||||
}
|
||||
__except (CheckException(GetExceptionCode()))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef NO_OPENAL
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
EXTERN_CVAR (Int, snd_channels)
|
||||
EXTERN_CVAR (Int, snd_samplerate)
|
||||
|
@ -173,8 +168,8 @@ class OpenALSoundStream : public SoundStream
|
|||
ALfloat Volume;
|
||||
|
||||
|
||||
std::auto_ptr<FileReader> Reader;
|
||||
std::auto_ptr<SoundDecoder> Decoder;
|
||||
FileReader *Reader;
|
||||
SoundDecoder *Decoder;
|
||||
static bool DecoderCallback(SoundStream *_sstream, void *ptr, int length, void *user)
|
||||
{
|
||||
OpenALSoundStream *self = static_cast<OpenALSoundStream*>(_sstream);
|
||||
|
@ -230,7 +225,7 @@ class OpenALSoundStream : public SoundStream
|
|||
|
||||
public:
|
||||
OpenALSoundStream(OpenALSoundRenderer *renderer)
|
||||
: Renderer(renderer), Source(0), Playing(false), Looping(false), Volume(1.0f)
|
||||
: Renderer(renderer), Source(0), Playing(false), Looping(false), Volume(1.0f), Reader(NULL), Decoder(NULL)
|
||||
{
|
||||
Renderer->Streams.Push(this);
|
||||
memset(Buffers, 0, sizeof(Buffers));
|
||||
|
@ -256,6 +251,9 @@ public:
|
|||
|
||||
Renderer->Streams.Delete(Renderer->Streams.Find(this));
|
||||
Renderer = NULL;
|
||||
|
||||
delete Decoder;
|
||||
delete Reader;
|
||||
}
|
||||
|
||||
|
||||
|
@ -516,14 +514,19 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Init(std::auto_ptr<FileReader> reader, bool loop)
|
||||
bool Init(FileReader *reader, bool loop)
|
||||
{
|
||||
if(!SetupSource())
|
||||
{
|
||||
delete reader;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Decoder) delete Decoder;
|
||||
if(Reader) delete Reader;
|
||||
Reader = reader;
|
||||
Decoder.reset(Renderer->CreateDecoder(Reader.get()));
|
||||
if(!Decoder.get()) return false;
|
||||
Decoder = Renderer->CreateDecoder(Reader);
|
||||
if(!Decoder) return false;
|
||||
|
||||
Callback = DecoderCallback;
|
||||
UserData = NULL;
|
||||
|
@ -615,12 +618,12 @@ ALCdevice *OpenALSoundRenderer::InitDevice()
|
|||
Printf(TEXTCOLOR_RED" Could not open audio device\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
__except(CheckException(GetExceptionCode()))
|
||||
{
|
||||
Printf(TEXTCOLOR_ORANGE"Failed to load openal32.dll\n");
|
||||
}
|
||||
return device;
|
||||
}
|
||||
__except(CheckException(GetExceptionCode()))
|
||||
{
|
||||
Printf(TEXTCOLOR_ORANGE"Failed to load openal32.dll\n");
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
|
@ -652,20 +655,20 @@ OpenALSoundRenderer::OpenALSoundRenderer()
|
|||
DPrintf(" ALC Version: "TEXTCOLOR_BLUE"%d.%d\n", major, minor);
|
||||
DPrintf(" ALC Extensions: "TEXTCOLOR_ORANGE"%s\n", alcGetString(Device, ALC_EXTENSIONS));
|
||||
|
||||
std::vector<ALCint> attribs;
|
||||
TArray<ALCint> attribs;
|
||||
if(*snd_samplerate > 0)
|
||||
{
|
||||
attribs.push_back(ALC_FREQUENCY);
|
||||
attribs.push_back(*snd_samplerate);
|
||||
attribs.Push(ALC_FREQUENCY);
|
||||
attribs.Push(*snd_samplerate);
|
||||
}
|
||||
// Make sure one source is capable of stereo output with the rest doing
|
||||
// mono, without running out of voices
|
||||
attribs.push_back(ALC_MONO_SOURCES);
|
||||
attribs.push_back(std::max<ALCint>(*snd_channels, 2) - 1);
|
||||
attribs.push_back(ALC_STEREO_SOURCES);
|
||||
attribs.push_back(1);
|
||||
attribs.Push(ALC_MONO_SOURCES);
|
||||
attribs.Push(MAX<ALCint>(*snd_channels, 2) - 1);
|
||||
attribs.Push(ALC_STEREO_SOURCES);
|
||||
attribs.Push(1);
|
||||
// Other attribs..?
|
||||
attribs.push_back(0);
|
||||
attribs.Push(0);
|
||||
|
||||
Context = alcCreateContext(Device, &attribs[0]);
|
||||
if(!Context || alcMakeContextCurrent(Context) == ALC_FALSE)
|
||||
|
@ -678,7 +681,7 @@ OpenALSoundRenderer::OpenALSoundRenderer()
|
|||
Device = NULL;
|
||||
return;
|
||||
}
|
||||
attribs.clear();
|
||||
attribs.Clear();
|
||||
|
||||
DPrintf(" Vendor: "TEXTCOLOR_ORANGE"%s\n", alGetString(AL_VENDOR));
|
||||
DPrintf(" Renderer: "TEXTCOLOR_ORANGE"%s\n", alGetString(AL_RENDERER));
|
||||
|
@ -723,7 +726,7 @@ OpenALSoundRenderer::OpenALSoundRenderer()
|
|||
alcGetIntegerv(Device, ALC_MONO_SOURCES, 1, &numMono);
|
||||
alcGetIntegerv(Device, ALC_STEREO_SOURCES, 1, &numStereo);
|
||||
|
||||
Sources.Resize(std::min<int>(std::max<int>(*snd_channels, 2), numMono+numStereo));
|
||||
Sources.Resize(MIN<int>(MAX<int>(*snd_channels, 2), numMono+numStereo));
|
||||
for(size_t i = 0;i < Sources.Size();i++)
|
||||
{
|
||||
alGenSources(1, &Sources[i]);
|
||||
|
@ -1024,8 +1027,8 @@ SoundHandle OpenALSoundRenderer::LoadSound(BYTE *sfxdata, int length)
|
|||
SampleType type;
|
||||
int srate;
|
||||
|
||||
std::auto_ptr<SoundDecoder> decoder(CreateDecoder(&reader));
|
||||
if(!decoder.get()) return retval;
|
||||
SoundDecoder *decoder = CreateDecoder(&reader);
|
||||
if(!decoder) return retval;
|
||||
|
||||
decoder->getInfo(&srate, &chans, &type);
|
||||
if(chans == ChannelConfig_Mono)
|
||||
|
@ -1043,6 +1046,7 @@ SoundHandle OpenALSoundRenderer::LoadSound(BYTE *sfxdata, int length)
|
|||
{
|
||||
Printf("Unsupported audio format: %s, %s\n", GetChannelConfigName(chans),
|
||||
GetSampleTypeName(type));
|
||||
delete decoder;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -1058,10 +1062,12 @@ SoundHandle OpenALSoundRenderer::LoadSound(BYTE *sfxdata, int length)
|
|||
Printf("Failed to buffer data: %s\n", alGetString(err));
|
||||
alDeleteBuffers(1, &buffer);
|
||||
getALError();
|
||||
delete decoder;
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval.data = MAKE_PTRID(buffer);
|
||||
delete decoder;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -1096,18 +1102,24 @@ void OpenALSoundRenderer::UnloadSound(SoundHandle sfx)
|
|||
|
||||
SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata)
|
||||
{
|
||||
std::auto_ptr<OpenALSoundStream> stream(new OpenALSoundStream(this));
|
||||
if(!stream->Init(callback, buffbytes, flags, samplerate, userdata))
|
||||
return NULL;
|
||||
return stream.release();
|
||||
OpenALSoundStream *stream = new OpenALSoundStream(this);
|
||||
if (!stream->Init(callback, buffbytes, flags, samplerate, userdata))
|
||||
{
|
||||
delete stream;
|
||||
return NULL;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
SoundStream *OpenALSoundRenderer::OpenStream(std::auto_ptr<FileReader> reader, int flags)
|
||||
SoundStream *OpenALSoundRenderer::OpenStream(FileReader *reader, int flags)
|
||||
{
|
||||
std::auto_ptr<OpenALSoundStream> stream(new OpenALSoundStream(this));
|
||||
|
||||
if (!stream->Init(reader, !!(flags&SoundStream::Loop))) return NULL;
|
||||
return stream.release();
|
||||
OpenALSoundStream *stream = new OpenALSoundStream(this);
|
||||
if (!stream->Init(reader, !!(flags&SoundStream::Loop)))
|
||||
{
|
||||
delete stream;
|
||||
return NULL;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
FISoundChannel *OpenALSoundRenderer::StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan)
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
#ifndef OALSOUND_H
|
||||
#define OALSOUND_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "i_sound.h"
|
||||
#include "s_sound.h"
|
||||
#include "menu/menu.h"
|
||||
|
@ -82,7 +78,7 @@ public:
|
|||
|
||||
// Streaming sounds.
|
||||
virtual SoundStream *CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata);
|
||||
virtual SoundStream *OpenStream(std::auto_ptr<FileReader> reader, int flags);
|
||||
virtual SoundStream *OpenStream(FileReader *reader, int flags);
|
||||
|
||||
// Starts a sound.
|
||||
virtual FISoundChannel *StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan);
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
#include "except.h"
|
||||
|
||||
#include "sndfile_decoder.h"
|
||||
#include "templates.h"
|
||||
#include "files.h"
|
||||
#include "xs_Float.h"
|
||||
|
||||
#ifdef HAVE_SNDFILE
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
sf_count_t SndFileDecoder::file_get_filelen(void *user_data)
|
||||
{
|
||||
FileReader *reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
||||
|
@ -69,10 +69,10 @@ bool SndFileDecoder::open(FileReader *reader)
|
|||
SndFile = 0;
|
||||
}
|
||||
}
|
||||
__except (CheckException(GetExceptionCode()))
|
||||
{
|
||||
// this means that the delay loaded decoder DLL was not found.
|
||||
}
|
||||
__except (CheckException(GetExceptionCode()))
|
||||
{
|
||||
// this means that the delay loaded decoder DLL was not found.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -103,14 +103,14 @@ size_t SndFileDecoder::read(char *buffer, size_t bytes)
|
|||
// could be more.
|
||||
while(total < frames)
|
||||
{
|
||||
size_t todo = std::min<size_t>(frames-total, 64/SndInfo.channels);
|
||||
size_t todo = MIN<size_t>(frames-total, 64/SndInfo.channels);
|
||||
float tmp[64];
|
||||
|
||||
size_t got = (size_t)sf_readf_float(SndFile, tmp, todo);
|
||||
if(got < todo) frames = total + got;
|
||||
|
||||
for(size_t i = 0;i < got*SndInfo.channels;i++)
|
||||
*out++ = (short)((std::min)((std::max)(tmp[i] * 32767.f, -32768.f), 32767.f));
|
||||
*out++ = (short)xs_CRoundToInt(clamp(tmp[i] * 32767.f, -32768.f, 32767.f));
|
||||
total += got;
|
||||
}
|
||||
return total * SndInfo.channels * 2;
|
||||
|
|
Loading…
Reference in a new issue