mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-24 01:40:11 +00:00
Now works for both FLT and S16 formats. The output format is hard coded in the MovieAudioDecoder constructor (default S16).
This commit is contained in:
parent
8429dab271
commit
a7371eda4d
1 changed files with 18 additions and 11 deletions
|
@ -317,7 +317,8 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder
|
||||||
|
|
||||||
SwrContext *mSwr; /* non-zero indicates FLTP format */
|
SwrContext *mSwr; /* non-zero indicates FLTP format */
|
||||||
int mSamplesAllChannels;
|
int mSamplesAllChannels;
|
||||||
int mOutputSampleSize;
|
float mOutputSampleRatio;
|
||||||
|
enum AVSampleFormat mOutputSampleFormat;
|
||||||
|
|
||||||
AutoAVPacket mPacket;
|
AutoAVPacket mPacket;
|
||||||
AVFrame *mFrame; /* AVFrame is now defined in libavutil/frame.h (used to be libavcodec/avcodec.h) */
|
AVFrame *mFrame; /* AVFrame is now defined in libavutil/frame.h (used to be libavcodec/avcodec.h) */
|
||||||
|
@ -437,7 +438,8 @@ public:
|
||||||
, mAudioDiffAvgCount(0)
|
, mAudioDiffAvgCount(0)
|
||||||
, mSwr(0)
|
, mSwr(0)
|
||||||
, mSamplesAllChannels(0)
|
, mSamplesAllChannels(0)
|
||||||
, mOutputSampleSize(0)
|
, mOutputSampleRatio(1)
|
||||||
|
, mOutputSampleFormat(AV_SAMPLE_FMT_S16)
|
||||||
{ }
|
{ }
|
||||||
virtual ~MovieAudioDecoder()
|
virtual ~MovieAudioDecoder()
|
||||||
{
|
{
|
||||||
|
@ -457,8 +459,12 @@ public:
|
||||||
else if(mAVStream->codec->sample_fmt == AV_SAMPLE_FMT_FLTP)
|
else if(mAVStream->codec->sample_fmt == AV_SAMPLE_FMT_FLTP)
|
||||||
{
|
{
|
||||||
// resample to a known format for OpenAL_SoundStream
|
// resample to a known format for OpenAL_SoundStream
|
||||||
// TODO: allow different size sample format, e.g. Int16
|
if(mOutputSampleFormat == AV_SAMPLE_FMT_S16)
|
||||||
|
*type = MWSound::SampleType_Int16;
|
||||||
|
else if(mOutputSampleFormat == AV_SAMPLE_FMT_FLT)
|
||||||
*type = MWSound::SampleType_Float32;
|
*type = MWSound::SampleType_Float32;
|
||||||
|
else
|
||||||
|
*type = MWSound::SampleType_Int16; // default
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fail(std::string("Unsupported sample format: ")+
|
fail(std::string("Unsupported sample format: ")+
|
||||||
|
@ -507,13 +513,14 @@ public:
|
||||||
av_opt_set_int(mSwr, "in_sample_rate", mAVStream->codec->sample_rate, 0);
|
av_opt_set_int(mSwr, "in_sample_rate", mAVStream->codec->sample_rate, 0);
|
||||||
av_opt_set_int(mSwr, "out_sample_rate", mAVStream->codec->sample_rate, 0);
|
av_opt_set_int(mSwr, "out_sample_rate", mAVStream->codec->sample_rate, 0);
|
||||||
av_opt_set_sample_fmt(mSwr, "in_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
|
av_opt_set_sample_fmt(mSwr, "in_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
|
||||||
av_opt_set_sample_fmt(mSwr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0); // TODO: Try S16
|
av_opt_set_sample_fmt(mSwr, "out_sample_fmt", mOutputSampleFormat, 0);
|
||||||
swr_init(mSwr);
|
swr_init(mSwr);
|
||||||
}
|
|
||||||
|
|
||||||
mSamplesAllChannels = av_get_bytes_per_sample(mAVStream->codec->sample_fmt) *
|
mSamplesAllChannels = av_get_bytes_per_sample(mOutputSampleFormat)
|
||||||
mAVStream->codec->channels;
|
* mAVStream->codec->channels;
|
||||||
mOutputSampleSize = av_get_bytes_per_sample(AV_SAMPLE_FMT_FLT);
|
mOutputSampleRatio = av_get_bytes_per_sample(AV_SAMPLE_FMT_FLTP)
|
||||||
|
/ av_get_bytes_per_sample(mOutputSampleFormat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -545,6 +552,7 @@ public:
|
||||||
size_t read(char *stream, size_t len)
|
size_t read(char *stream, size_t len)
|
||||||
{
|
{
|
||||||
int sample_skip = synchronize_audio();
|
int sample_skip = synchronize_audio();
|
||||||
|
if(mSwr) sample_skip /= mOutputSampleRatio;
|
||||||
size_t total = 0;
|
size_t total = 0;
|
||||||
|
|
||||||
while(total < len)
|
while(total < len)
|
||||||
|
@ -558,8 +566,7 @@ public:
|
||||||
/* If error, we're done */
|
/* If error, we're done */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// for FLT sample format mFrameSize returned by audio_decode_frame is:
|
if(mSwr) mFrameSize /= mOutputSampleRatio;
|
||||||
// 1920 samples x 4 bytes/sample x 2 channels = 15360 bytes
|
|
||||||
|
|
||||||
mFramePos = std::min<ssize_t>(mFrameSize, sample_skip);
|
mFramePos = std::min<ssize_t>(mFrameSize, sample_skip);
|
||||||
sample_skip -= mFramePos;
|
sample_skip -= mFramePos;
|
||||||
|
|
Loading…
Reference in a new issue