forked from mirror/openmw-tes3mp
Support float samples with ffmpeg
Requires the AL_EXT_FLOAT32 extension in OpenAL
This commit is contained in:
parent
1a43d86d9e
commit
ceafcc2ebb
5 changed files with 53 additions and 1 deletions
|
@ -404,6 +404,8 @@ public:
|
|||
*type = MWSound::SampleType_UInt8;
|
||||
else if(mAVStream->codec->sample_fmt == AV_SAMPLE_FMT_S16)
|
||||
*type = MWSound::SampleType_Int16;
|
||||
else if(mAVStream->codec->sample_fmt == AV_SAMPLE_FMT_FLT)
|
||||
*type = MWSound::SampleType_Float32;
|
||||
else
|
||||
fail(std::string("Unsupported sample format: ")+
|
||||
av_get_sample_fmt_name(mAVStream->codec->sample_fmt));
|
||||
|
|
|
@ -224,6 +224,8 @@ void FFmpeg_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *
|
|||
*type = SampleType_UInt8;
|
||||
else if((*mStream)->codec->sample_fmt == AV_SAMPLE_FMT_S16)
|
||||
*type = SampleType_Int16;
|
||||
else if((*mStream)->codec->sample_fmt == AV_SAMPLE_FMT_FLT)
|
||||
*type = SampleType_Float32;
|
||||
else
|
||||
fail(std::string("Unsupported sample format: ")+
|
||||
av_get_sample_fmt_name((*mStream)->codec->sample_fmt));
|
||||
|
|
|
@ -88,6 +88,51 @@ static ALenum getALFormat(ChannelConfig chans, SampleType type)
|
|||
}
|
||||
}
|
||||
}
|
||||
if(alIsExtensionPresent("AL_EXT_FLOAT32"))
|
||||
{
|
||||
static const struct {
|
||||
char name[32];
|
||||
ChannelConfig chans;
|
||||
SampleType type;
|
||||
} fltfmtlist[] = {
|
||||
{ "AL_FORMAT_MONO_FLOAT32", ChannelConfig_Mono, SampleType_Float32 },
|
||||
{ "AL_FORMAT_STEREO_FLOAT32", ChannelConfig_Stereo, SampleType_Float32 },
|
||||
};
|
||||
static const size_t fltfmtlistsize = sizeof(fltfmtlist)/sizeof(fltfmtlist[0]);
|
||||
|
||||
for(size_t i = 0;i < fltfmtlistsize;i++)
|
||||
{
|
||||
if(fltfmtlist[i].chans == chans && fltfmtlist[i].type == type)
|
||||
{
|
||||
ALenum format = alGetEnumValue(fltfmtlist[i].name);
|
||||
if(format != 0 && format != -1)
|
||||
return format;
|
||||
}
|
||||
}
|
||||
if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
|
||||
{
|
||||
static const struct {
|
||||
char name[32];
|
||||
ChannelConfig chans;
|
||||
SampleType type;
|
||||
} fltmcfmtlist[] = {
|
||||
{ "AL_FORMAT_QUAD32", ChannelConfig_Quad, SampleType_Float32 },
|
||||
{ "AL_FORMAT_51CHN32", ChannelConfig_5point1, SampleType_Float32 },
|
||||
{ "AL_FORMAT_71CHN32", ChannelConfig_7point1, SampleType_Float32 },
|
||||
};
|
||||
static const size_t fltmcfmtlistsize = sizeof(fltmcfmtlist)/sizeof(fltmcfmtlist[0]);
|
||||
|
||||
for(size_t i = 0;i < fltmcfmtlistsize;i++)
|
||||
{
|
||||
if(fltmcfmtlist[i].chans == chans && fltmcfmtlist[i].type == type)
|
||||
{
|
||||
ALenum format = alGetEnumValue(fltmcfmtlist[i].name);
|
||||
if(format != 0 && format != -1)
|
||||
return format;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fail(std::string("Unsupported sound format (")+getChannelConfigName(chans)+", "+getSampleTypeName(type)+")");
|
||||
return AL_NONE;
|
||||
|
|
|
@ -9,7 +9,8 @@ namespace MWSound
|
|||
{
|
||||
enum SampleType {
|
||||
SampleType_UInt8,
|
||||
SampleType_Int16
|
||||
SampleType_Int16,
|
||||
SampleType_Float32
|
||||
};
|
||||
const char *getSampleTypeName(SampleType type);
|
||||
|
||||
|
|
|
@ -607,6 +607,7 @@ namespace MWSound
|
|||
{
|
||||
case SampleType_UInt8: return "U8";
|
||||
case SampleType_Int16: return "S16";
|
||||
case SampleType_Float32: return "Float32";
|
||||
}
|
||||
return "(unknown sample type)";
|
||||
}
|
||||
|
@ -638,6 +639,7 @@ namespace MWSound
|
|||
{
|
||||
case SampleType_UInt8: frames *= 1; break;
|
||||
case SampleType_Int16: frames *= 2; break;
|
||||
case SampleType_Float32: frames *= 4; break;
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue