mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 10:53:54 +00:00
Rename some sound decoder class member variables and functions
This commit is contained in:
parent
9656456d30
commit
efae7dfe83
6 changed files with 72 additions and 71 deletions
|
@ -9,21 +9,21 @@ namespace MWSound
|
||||||
static void fail(const std::string &msg)
|
static void fail(const std::string &msg)
|
||||||
{ throw std::runtime_error("FFmpeg exception: "+msg); }
|
{ throw std::runtime_error("FFmpeg exception: "+msg); }
|
||||||
|
|
||||||
void FFmpeg_Decoder::Open(const std::string &fname)
|
void FFmpeg_Decoder::open(const std::string &fname)
|
||||||
{
|
{
|
||||||
fail("Not currently working");
|
fail("Not currently working");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFmpeg_Decoder::Close()
|
void FFmpeg_Decoder::close()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFmpeg_Decoder::GetInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
|
void FFmpeg_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
|
||||||
{
|
{
|
||||||
fail("Not currently working");
|
fail("Not currently working");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t FFmpeg_Decoder::Read(char *buffer, size_t bytes)
|
size_t FFmpeg_Decoder::read(char *buffer, size_t bytes)
|
||||||
{
|
{
|
||||||
fail("Not currently working");
|
fail("Not currently working");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -36,7 +36,7 @@ FFmpeg_Decoder::FFmpeg_Decoder()
|
||||||
|
|
||||||
FFmpeg_Decoder::~FFmpeg_Decoder()
|
FFmpeg_Decoder::~FFmpeg_Decoder()
|
||||||
{
|
{
|
||||||
Close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
class FFmpeg_Decoder : public Sound_Decoder
|
class FFmpeg_Decoder : public Sound_Decoder
|
||||||
{
|
{
|
||||||
virtual void Open(const std::string &fname);
|
virtual void open(const std::string &fname);
|
||||||
virtual void Close();
|
virtual void close();
|
||||||
|
|
||||||
virtual void GetInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
||||||
virtual size_t Read(char *buffer, size_t bytes);
|
virtual size_t read(char *buffer, size_t bytes);
|
||||||
|
|
||||||
FFmpeg_Decoder();
|
FFmpeg_Decoder();
|
||||||
virtual ~FFmpeg_Decoder();
|
virtual ~FFmpeg_Decoder();
|
||||||
|
|
|
@ -12,103 +12,104 @@ static void fail(const std::string &msg)
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
{
|
{
|
||||||
|
|
||||||
void MpgSnd_Decoder::Open(const std::string &fname)
|
void MpgSnd_Decoder::open(const std::string &fname)
|
||||||
{
|
{
|
||||||
Close();
|
close();
|
||||||
|
|
||||||
SF_INFO info;
|
SF_INFO info;
|
||||||
sndFile = sf_open(fname.c_str(), SFM_READ, &info);
|
mSndFile = sf_open(fname.c_str(), SFM_READ, &info);
|
||||||
if(sndFile)
|
if(mSndFile)
|
||||||
{
|
{
|
||||||
if(info.channels == 1)
|
if(info.channels == 1)
|
||||||
chanConfig = MonoChannels;
|
mChanConfig = MonoChannels;
|
||||||
else if(info.channels == 2)
|
else if(info.channels == 2)
|
||||||
chanConfig = StereoChannels;
|
mChanConfig = StereoChannels;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sf_close(sndFile);
|
sf_close(mSndFile);
|
||||||
sndFile = NULL;
|
mSndFile = NULL;
|
||||||
fail("Unsupported channel count in "+fname);
|
fail("Unsupported channel count in "+fname);
|
||||||
}
|
}
|
||||||
sampleRate = info.samplerate;
|
mSampleRate = info.samplerate;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpgFile = mpg123_new(NULL, NULL);
|
mMpgFile = mpg123_new(NULL, NULL);
|
||||||
if(mpgFile && mpg123_open(mpgFile, fname.c_str()) == MPG123_OK)
|
if(mMpgFile && mpg123_open(mMpgFile, fname.c_str()) == MPG123_OK)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int encoding, channels;
|
int encoding, channels;
|
||||||
long rate;
|
long rate;
|
||||||
if(mpg123_getformat(mpgFile, &rate, &channels, &encoding) != MPG123_OK)
|
if(mpg123_getformat(mMpgFile, &rate, &channels, &encoding) != MPG123_OK)
|
||||||
fail("Failed to get audio format");
|
fail("Failed to get audio format");
|
||||||
if(encoding != MPG123_ENC_SIGNED_16)
|
if(encoding != MPG123_ENC_SIGNED_16)
|
||||||
fail("Unsupported encoding in "+fname);
|
fail("Unsupported encoding in "+fname);
|
||||||
if(channels != 1 && channels != 2)
|
if(channels != 1 && channels != 2)
|
||||||
fail("Unsupported channel count in "+fname);
|
fail("Unsupported channel count in "+fname);
|
||||||
chanConfig = ((channels==2)?StereoChannels:MonoChannels);
|
mChanConfig = ((channels==2)?StereoChannels:MonoChannels);
|
||||||
sampleRate = rate;
|
mSampleRate = rate;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
mpg123_close(mpgFile);
|
mpg123_close(mMpgFile);
|
||||||
mpg123_delete(mpgFile);
|
mpg123_delete(mMpgFile);
|
||||||
|
mMpgFile = NULL;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
mpg123_close(mpgFile);
|
mpg123_close(mMpgFile);
|
||||||
}
|
}
|
||||||
if(mpgFile)
|
if(mMpgFile)
|
||||||
mpg123_delete(mpgFile);
|
mpg123_delete(mMpgFile);
|
||||||
mpgFile = NULL;
|
mMpgFile = NULL;
|
||||||
|
|
||||||
fail("Unsupported file type: "+fname);
|
fail("Unsupported file type: "+fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpgSnd_Decoder::Close()
|
void MpgSnd_Decoder::close()
|
||||||
{
|
{
|
||||||
if(sndFile)
|
if(mSndFile)
|
||||||
sf_close(sndFile);
|
sf_close(mSndFile);
|
||||||
sndFile = NULL;
|
mSndFile = NULL;
|
||||||
|
|
||||||
if(mpgFile)
|
if(mMpgFile)
|
||||||
{
|
{
|
||||||
mpg123_close(mpgFile);
|
mpg123_close(mMpgFile);
|
||||||
mpg123_delete(mpgFile);
|
mpg123_delete(mMpgFile);
|
||||||
mpgFile = NULL;
|
mMpgFile = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpgSnd_Decoder::GetInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
|
void MpgSnd_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
|
||||||
{
|
{
|
||||||
if(!sndFile && !mpgFile)
|
if(!mSndFile && !mMpgFile)
|
||||||
fail("No open file");
|
fail("No open file");
|
||||||
|
|
||||||
*samplerate = sampleRate;
|
*samplerate = mSampleRate;
|
||||||
*chans = chanConfig;
|
*chans = mChanConfig;
|
||||||
*type = Int16Sample;
|
*type = Int16Sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MpgSnd_Decoder::Read(char *buffer, size_t bytes)
|
size_t MpgSnd_Decoder::read(char *buffer, size_t bytes)
|
||||||
{
|
{
|
||||||
size_t got = 0;
|
size_t got = 0;
|
||||||
|
|
||||||
if(sndFile)
|
if(mSndFile)
|
||||||
{
|
{
|
||||||
got = sf_read_short(sndFile, (short*)buffer, bytes/2)*2;
|
got = sf_read_short(mSndFile, (short*)buffer, bytes/2)*2;
|
||||||
}
|
}
|
||||||
else if(mpgFile)
|
else if(mMpgFile)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
err = mpg123_read(mpgFile, (unsigned char*)buffer, bytes, &got);
|
err = mpg123_read(mMpgFile, (unsigned char*)buffer, bytes, &got);
|
||||||
if(err != MPG123_OK && err != MPG123_DONE)
|
if(err != MPG123_OK && err != MPG123_DONE)
|
||||||
fail("Failed to read from file");
|
fail("Failed to read from file");
|
||||||
}
|
}
|
||||||
return got;
|
return got;
|
||||||
}
|
}
|
||||||
|
|
||||||
MpgSnd_Decoder::MpgSnd_Decoder() : sndFile(NULL), mpgFile(NULL)
|
MpgSnd_Decoder::MpgSnd_Decoder() : mSndFile(NULL), mMpgFile(NULL)
|
||||||
{
|
{
|
||||||
static bool initdone = false;
|
static bool initdone = false;
|
||||||
if(!initdone)
|
if(!initdone)
|
||||||
|
@ -118,7 +119,7 @@ MpgSnd_Decoder::MpgSnd_Decoder() : sndFile(NULL), mpgFile(NULL)
|
||||||
|
|
||||||
MpgSnd_Decoder::~MpgSnd_Decoder()
|
MpgSnd_Decoder::~MpgSnd_Decoder()
|
||||||
{
|
{
|
||||||
Close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,17 +13,17 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
class MpgSnd_Decoder : public Sound_Decoder
|
class MpgSnd_Decoder : public Sound_Decoder
|
||||||
{
|
{
|
||||||
SNDFILE *sndFile;
|
SNDFILE *mSndFile;
|
||||||
mpg123_handle *mpgFile;
|
mpg123_handle *mMpgFile;
|
||||||
|
|
||||||
ChannelConfig chanConfig;
|
ChannelConfig mChanConfig;
|
||||||
int sampleRate;
|
int mSampleRate;
|
||||||
|
|
||||||
virtual void Open(const std::string &fname);
|
virtual void open(const std::string &fname);
|
||||||
virtual void Close();
|
virtual void close();
|
||||||
|
|
||||||
virtual void GetInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
||||||
virtual size_t Read(char *buffer, size_t bytes);
|
virtual size_t read(char *buffer, size_t bytes);
|
||||||
|
|
||||||
MpgSnd_Decoder();
|
MpgSnd_Decoder();
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -55,12 +55,12 @@ ALuint LoadBuffer(DecoderPtr decoder)
|
||||||
Sound_Decoder::SampleType type;
|
Sound_Decoder::SampleType type;
|
||||||
ALenum format;
|
ALenum format;
|
||||||
|
|
||||||
decoder->GetInfo(&srate, &chans, &type);
|
decoder->getInfo(&srate, &chans, &type);
|
||||||
format = getALFormat(chans, type);
|
format = getALFormat(chans, type);
|
||||||
|
|
||||||
std::vector<char> data(32768);
|
std::vector<char> data(32768);
|
||||||
size_t got, total = 0;
|
size_t got, total = 0;
|
||||||
while((got=decoder->Read(&data[total], data.size()-total)) > 0)
|
while((got=decoder->read(&data[total], data.size()-total)) > 0)
|
||||||
{
|
{
|
||||||
total += got;
|
total += got;
|
||||||
data.resize(total*2);
|
data.resize(total*2);
|
||||||
|
@ -139,7 +139,7 @@ OpenAL_SoundStream::OpenAL_SoundStream(DecoderPtr decoder)
|
||||||
Sound_Decoder::ChannelConfig chans;
|
Sound_Decoder::ChannelConfig chans;
|
||||||
Sound_Decoder::SampleType type;
|
Sound_Decoder::SampleType type;
|
||||||
|
|
||||||
mDecoder->GetInfo(&srate, &chans, &type);
|
mDecoder->getInfo(&srate, &chans, &type);
|
||||||
mFormat = getALFormat(chans, type);
|
mFormat = getALFormat(chans, type);
|
||||||
mSampleRate = srate;
|
mSampleRate = srate;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ OpenAL_SoundStream::~OpenAL_SoundStream()
|
||||||
alDeleteSources(1, &mSource);
|
alDeleteSources(1, &mSource);
|
||||||
alDeleteBuffers(sNumBuffers, mBuffers);
|
alDeleteBuffers(sNumBuffers, mBuffers);
|
||||||
alGetError();
|
alGetError();
|
||||||
mDecoder->Close();
|
mDecoder->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenAL_SoundStream::Play(float volume, float pitch)
|
void OpenAL_SoundStream::Play(float volume, float pitch)
|
||||||
|
@ -172,7 +172,7 @@ void OpenAL_SoundStream::Play(float volume, float pitch)
|
||||||
for(ALuint i = 0;i < sNumBuffers;i++)
|
for(ALuint i = 0;i < sNumBuffers;i++)
|
||||||
{
|
{
|
||||||
size_t got;
|
size_t got;
|
||||||
got = mDecoder->Read(&data[0], data.size());
|
got = mDecoder->read(&data[0], data.size());
|
||||||
alBufferData(mBuffers[i], mFormat, &data[0], got, mSampleRate);
|
alBufferData(mBuffers[i], mFormat, &data[0], got, mSampleRate);
|
||||||
}
|
}
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
@ -208,7 +208,7 @@ bool OpenAL_SoundStream::isPlaying()
|
||||||
alSourceUnqueueBuffers(mSource, 1, &bufid);
|
alSourceUnqueueBuffers(mSource, 1, &bufid);
|
||||||
processed--;
|
processed--;
|
||||||
|
|
||||||
got = mDecoder->Read(&data[0], data.size());
|
got = mDecoder->read(&data[0], data.size());
|
||||||
if(got > 0)
|
if(got > 0)
|
||||||
{
|
{
|
||||||
alBufferData(bufid, mFormat, &data[0], got, mSampleRate);
|
alBufferData(bufid, mFormat, &data[0], got, mSampleRate);
|
||||||
|
@ -326,13 +326,13 @@ Sound* OpenAL_Output::playSound(const std::string &fname, float volume, float pi
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
|
||||||
DecoderPtr decoder = mManager.getDecoder();
|
DecoderPtr decoder = mManager.getDecoder();
|
||||||
decoder->Open(fname);
|
decoder->open(fname);
|
||||||
|
|
||||||
ALuint src=0, buf=0;
|
ALuint src=0, buf=0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buf = LoadBuffer(decoder);
|
buf = LoadBuffer(decoder);
|
||||||
decoder->Close();
|
decoder->close();
|
||||||
alGenSources(1, &src);
|
alGenSources(1, &src);
|
||||||
throwALerror();
|
throwALerror();
|
||||||
}
|
}
|
||||||
|
@ -375,13 +375,13 @@ Sound* OpenAL_Output::playSound3D(const std::string &fname, const float *pos, fl
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
|
||||||
DecoderPtr decoder = mManager.getDecoder();
|
DecoderPtr decoder = mManager.getDecoder();
|
||||||
decoder->Open(fname);
|
decoder->open(fname);
|
||||||
|
|
||||||
ALuint src=0, buf=0;
|
ALuint src=0, buf=0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buf = LoadBuffer(decoder);
|
buf = LoadBuffer(decoder);
|
||||||
decoder->Close();
|
decoder->close();
|
||||||
alGenSources(1, &src);
|
alGenSources(1, &src);
|
||||||
throwALerror();
|
throwALerror();
|
||||||
}
|
}
|
||||||
|
@ -424,7 +424,7 @@ Sound* OpenAL_Output::streamSound(const std::string &fname, float volume, float
|
||||||
std::auto_ptr<OpenAL_SoundStream> sound;
|
std::auto_ptr<OpenAL_SoundStream> sound;
|
||||||
|
|
||||||
DecoderPtr decoder = mManager.getDecoder();
|
DecoderPtr decoder = mManager.getDecoder();
|
||||||
decoder->Open(fname);
|
decoder->open(fname);
|
||||||
|
|
||||||
sound.reset(new OpenAL_SoundStream(decoder));
|
sound.reset(new OpenAL_SoundStream(decoder));
|
||||||
sound->Play(volume, pitch);
|
sound->Play(volume, pitch);
|
||||||
|
|
|
@ -14,11 +14,11 @@ namespace MWSound
|
||||||
MonoChannels,
|
MonoChannels,
|
||||||
StereoChannels
|
StereoChannels
|
||||||
};
|
};
|
||||||
virtual void Open(const std::string &fname) = 0;
|
virtual void open(const std::string &fname) = 0;
|
||||||
virtual void Close() = 0;
|
virtual void close() = 0;
|
||||||
|
|
||||||
virtual void GetInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0;
|
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0;
|
||||||
virtual size_t Read(char *buffer, size_t bytes) = 0;
|
virtual size_t read(char *buffer, size_t bytes) = 0;
|
||||||
|
|
||||||
virtual ~Sound_Decoder() { }
|
virtual ~Sound_Decoder() { }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue