mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 07:53:52 +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)
|
||||
{ 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");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
size_t FFmpeg_Decoder::Read(char *buffer, size_t bytes)
|
||||
size_t FFmpeg_Decoder::read(char *buffer, size_t bytes)
|
||||
{
|
||||
fail("Not currently working");
|
||||
return 0;
|
||||
|
@ -36,7 +36,7 @@ FFmpeg_Decoder::FFmpeg_Decoder()
|
|||
|
||||
FFmpeg_Decoder::~FFmpeg_Decoder()
|
||||
{
|
||||
Close();
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ namespace MWSound
|
|||
{
|
||||
class FFmpeg_Decoder : public Sound_Decoder
|
||||
{
|
||||
virtual void Open(const std::string &fname);
|
||||
virtual void Close();
|
||||
virtual void open(const std::string &fname);
|
||||
virtual void close();
|
||||
|
||||
virtual void GetInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
||||
virtual size_t Read(char *buffer, size_t bytes);
|
||||
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
||||
virtual size_t read(char *buffer, size_t bytes);
|
||||
|
||||
FFmpeg_Decoder();
|
||||
virtual ~FFmpeg_Decoder();
|
||||
|
|
|
@ -12,103 +12,104 @@ static void fail(const std::string &msg)
|
|||
namespace MWSound
|
||||
{
|
||||
|
||||
void MpgSnd_Decoder::Open(const std::string &fname)
|
||||
void MpgSnd_Decoder::open(const std::string &fname)
|
||||
{
|
||||
Close();
|
||||
close();
|
||||
|
||||
SF_INFO info;
|
||||
sndFile = sf_open(fname.c_str(), SFM_READ, &info);
|
||||
if(sndFile)
|
||||
mSndFile = sf_open(fname.c_str(), SFM_READ, &info);
|
||||
if(mSndFile)
|
||||
{
|
||||
if(info.channels == 1)
|
||||
chanConfig = MonoChannels;
|
||||
mChanConfig = MonoChannels;
|
||||
else if(info.channels == 2)
|
||||
chanConfig = StereoChannels;
|
||||
mChanConfig = StereoChannels;
|
||||
else
|
||||
{
|
||||
sf_close(sndFile);
|
||||
sndFile = NULL;
|
||||
sf_close(mSndFile);
|
||||
mSndFile = NULL;
|
||||
fail("Unsupported channel count in "+fname);
|
||||
}
|
||||
sampleRate = info.samplerate;
|
||||
mSampleRate = info.samplerate;
|
||||
return;
|
||||
}
|
||||
|
||||
mpgFile = mpg123_new(NULL, NULL);
|
||||
if(mpgFile && mpg123_open(mpgFile, fname.c_str()) == MPG123_OK)
|
||||
mMpgFile = mpg123_new(NULL, NULL);
|
||||
if(mMpgFile && mpg123_open(mMpgFile, fname.c_str()) == MPG123_OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
int encoding, channels;
|
||||
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");
|
||||
if(encoding != MPG123_ENC_SIGNED_16)
|
||||
fail("Unsupported encoding in "+fname);
|
||||
if(channels != 1 && channels != 2)
|
||||
fail("Unsupported channel count in "+fname);
|
||||
chanConfig = ((channels==2)?StereoChannels:MonoChannels);
|
||||
sampleRate = rate;
|
||||
mChanConfig = ((channels==2)?StereoChannels:MonoChannels);
|
||||
mSampleRate = rate;
|
||||
return;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
mpg123_close(mpgFile);
|
||||
mpg123_delete(mpgFile);
|
||||
mpg123_close(mMpgFile);
|
||||
mpg123_delete(mMpgFile);
|
||||
mMpgFile = NULL;
|
||||
throw;
|
||||
}
|
||||
mpg123_close(mpgFile);
|
||||
mpg123_close(mMpgFile);
|
||||
}
|
||||
if(mpgFile)
|
||||
mpg123_delete(mpgFile);
|
||||
mpgFile = NULL;
|
||||
if(mMpgFile)
|
||||
mpg123_delete(mMpgFile);
|
||||
mMpgFile = NULL;
|
||||
|
||||
fail("Unsupported file type: "+fname);
|
||||
}
|
||||
|
||||
void MpgSnd_Decoder::Close()
|
||||
void MpgSnd_Decoder::close()
|
||||
{
|
||||
if(sndFile)
|
||||
sf_close(sndFile);
|
||||
sndFile = NULL;
|
||||
if(mSndFile)
|
||||
sf_close(mSndFile);
|
||||
mSndFile = NULL;
|
||||
|
||||
if(mpgFile)
|
||||
if(mMpgFile)
|
||||
{
|
||||
mpg123_close(mpgFile);
|
||||
mpg123_delete(mpgFile);
|
||||
mpgFile = NULL;
|
||||
mpg123_close(mMpgFile);
|
||||
mpg123_delete(mMpgFile);
|
||||
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");
|
||||
|
||||
*samplerate = sampleRate;
|
||||
*chans = chanConfig;
|
||||
*samplerate = mSampleRate;
|
||||
*chans = mChanConfig;
|
||||
*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;
|
||||
|
||||
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;
|
||||
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)
|
||||
fail("Failed to read from file");
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
MpgSnd_Decoder::MpgSnd_Decoder() : sndFile(NULL), mpgFile(NULL)
|
||||
MpgSnd_Decoder::MpgSnd_Decoder() : mSndFile(NULL), mMpgFile(NULL)
|
||||
{
|
||||
static bool initdone = false;
|
||||
if(!initdone)
|
||||
|
@ -118,7 +119,7 @@ MpgSnd_Decoder::MpgSnd_Decoder() : sndFile(NULL), mpgFile(NULL)
|
|||
|
||||
MpgSnd_Decoder::~MpgSnd_Decoder()
|
||||
{
|
||||
Close();
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,17 +13,17 @@ namespace MWSound
|
|||
{
|
||||
class MpgSnd_Decoder : public Sound_Decoder
|
||||
{
|
||||
SNDFILE *sndFile;
|
||||
mpg123_handle *mpgFile;
|
||||
SNDFILE *mSndFile;
|
||||
mpg123_handle *mMpgFile;
|
||||
|
||||
ChannelConfig chanConfig;
|
||||
int sampleRate;
|
||||
ChannelConfig mChanConfig;
|
||||
int mSampleRate;
|
||||
|
||||
virtual void Open(const std::string &fname);
|
||||
virtual void Close();
|
||||
virtual void open(const std::string &fname);
|
||||
virtual void close();
|
||||
|
||||
virtual void GetInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
||||
virtual size_t Read(char *buffer, size_t bytes);
|
||||
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type);
|
||||
virtual size_t read(char *buffer, size_t bytes);
|
||||
|
||||
MpgSnd_Decoder();
|
||||
public:
|
||||
|
|
|
@ -55,12 +55,12 @@ ALuint LoadBuffer(DecoderPtr decoder)
|
|||
Sound_Decoder::SampleType type;
|
||||
ALenum format;
|
||||
|
||||
decoder->GetInfo(&srate, &chans, &type);
|
||||
decoder->getInfo(&srate, &chans, &type);
|
||||
format = getALFormat(chans, type);
|
||||
|
||||
std::vector<char> data(32768);
|
||||
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;
|
||||
data.resize(total*2);
|
||||
|
@ -139,7 +139,7 @@ OpenAL_SoundStream::OpenAL_SoundStream(DecoderPtr decoder)
|
|||
Sound_Decoder::ChannelConfig chans;
|
||||
Sound_Decoder::SampleType type;
|
||||
|
||||
mDecoder->GetInfo(&srate, &chans, &type);
|
||||
mDecoder->getInfo(&srate, &chans, &type);
|
||||
mFormat = getALFormat(chans, type);
|
||||
mSampleRate = srate;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ OpenAL_SoundStream::~OpenAL_SoundStream()
|
|||
alDeleteSources(1, &mSource);
|
||||
alDeleteBuffers(sNumBuffers, mBuffers);
|
||||
alGetError();
|
||||
mDecoder->Close();
|
||||
mDecoder->close();
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
throwALerror();
|
||||
|
@ -208,7 +208,7 @@ bool OpenAL_SoundStream::isPlaying()
|
|||
alSourceUnqueueBuffers(mSource, 1, &bufid);
|
||||
processed--;
|
||||
|
||||
got = mDecoder->Read(&data[0], data.size());
|
||||
got = mDecoder->read(&data[0], data.size());
|
||||
if(got > 0)
|
||||
{
|
||||
alBufferData(bufid, mFormat, &data[0], got, mSampleRate);
|
||||
|
@ -326,13 +326,13 @@ Sound* OpenAL_Output::playSound(const std::string &fname, float volume, float pi
|
|||
throwALerror();
|
||||
|
||||
DecoderPtr decoder = mManager.getDecoder();
|
||||
decoder->Open(fname);
|
||||
decoder->open(fname);
|
||||
|
||||
ALuint src=0, buf=0;
|
||||
try
|
||||
{
|
||||
buf = LoadBuffer(decoder);
|
||||
decoder->Close();
|
||||
decoder->close();
|
||||
alGenSources(1, &src);
|
||||
throwALerror();
|
||||
}
|
||||
|
@ -375,13 +375,13 @@ Sound* OpenAL_Output::playSound3D(const std::string &fname, const float *pos, fl
|
|||
throwALerror();
|
||||
|
||||
DecoderPtr decoder = mManager.getDecoder();
|
||||
decoder->Open(fname);
|
||||
decoder->open(fname);
|
||||
|
||||
ALuint src=0, buf=0;
|
||||
try
|
||||
{
|
||||
buf = LoadBuffer(decoder);
|
||||
decoder->Close();
|
||||
decoder->close();
|
||||
alGenSources(1, &src);
|
||||
throwALerror();
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ Sound* OpenAL_Output::streamSound(const std::string &fname, float volume, float
|
|||
std::auto_ptr<OpenAL_SoundStream> sound;
|
||||
|
||||
DecoderPtr decoder = mManager.getDecoder();
|
||||
decoder->Open(fname);
|
||||
decoder->open(fname);
|
||||
|
||||
sound.reset(new OpenAL_SoundStream(decoder));
|
||||
sound->Play(volume, pitch);
|
||||
|
|
|
@ -14,11 +14,11 @@ namespace MWSound
|
|||
MonoChannels,
|
||||
StereoChannels
|
||||
};
|
||||
virtual void Open(const std::string &fname) = 0;
|
||||
virtual void Close() = 0;
|
||||
virtual void open(const std::string &fname) = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
virtual void GetInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0;
|
||||
virtual size_t Read(char *buffer, size_t bytes) = 0;
|
||||
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0;
|
||||
virtual size_t read(char *buffer, size_t bytes) = 0;
|
||||
|
||||
virtual ~Sound_Decoder() { }
|
||||
|
||||
|
|
Loading…
Reference in a new issue