mirror of
https://github.com/love2d/megasource.git
synced 2026-08-18 11:44:19 +02:00
Added missing changes to the OpenAL-Soft update.
This commit is contained in:
@@ -548,6 +548,7 @@ static int audio_thread(void *userdata)
|
||||
MovieState *movState = (MovieState*)userdata;
|
||||
uint8_t *samples = NULL;
|
||||
ALsizei buffer_len;
|
||||
ALenum fmt;
|
||||
|
||||
alGenBuffers(AUDIO_BUFFER_QUEUE_SIZE, movState->audio.buffer);
|
||||
alGenSources(1, &movState->audio.source);
|
||||
@@ -557,56 +558,107 @@ static int audio_thread(void *userdata)
|
||||
|
||||
av_new_packet(&movState->audio.pkt, 0);
|
||||
|
||||
/* Find a suitable format for OpenAL. Currently does not handle surround
|
||||
* sound (everything non-mono becomes stereo). */
|
||||
/* Find a suitable format for OpenAL. */
|
||||
movState->audio.format = AL_NONE;
|
||||
if(movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_U8 ||
|
||||
movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_U8P)
|
||||
{
|
||||
movState->audio.dst_sample_fmt = AV_SAMPLE_FMT_U8;
|
||||
movState->audio.frame_size = 1;
|
||||
if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_7POINT1 &&
|
||||
alIsExtensionPresent("AL_EXT_MCFORMATS") &&
|
||||
(fmt=alGetEnumValue("AL_FORMAT_71CHN8")) != AL_NONE && fmt != -1)
|
||||
{
|
||||
movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
|
||||
movState->audio.frame_size *= 8;
|
||||
movState->audio.format = fmt;
|
||||
}
|
||||
if((movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1 ||
|
||||
movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
|
||||
alIsExtensionPresent("AL_EXT_MCFORMATS") &&
|
||||
(fmt=alGetEnumValue("AL_FORMAT_51CHN8")) != AL_NONE && fmt != -1)
|
||||
{
|
||||
movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
|
||||
movState->audio.frame_size *= 6;
|
||||
movState->audio.format = fmt;
|
||||
}
|
||||
if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_MONO)
|
||||
{
|
||||
movState->audio.dst_ch_layout = AV_CH_LAYOUT_MONO;
|
||||
movState->audio.frame_size *= 1;
|
||||
movState->audio.format = AL_FORMAT_MONO8;
|
||||
}
|
||||
else
|
||||
if(movState->audio.format == AL_NONE)
|
||||
{
|
||||
movState->audio.dst_ch_layout = AV_CH_LAYOUT_STEREO;
|
||||
movState->audio.frame_size *= 2;
|
||||
movState->audio.format = AL_FORMAT_STEREO8;
|
||||
}
|
||||
}
|
||||
else if((movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_FLT ||
|
||||
movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_FLTP) &&
|
||||
alIsExtensionPresent("AL_EXT_FLOAT32"))
|
||||
if((movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_FLT ||
|
||||
movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_FLTP) &&
|
||||
alIsExtensionPresent("AL_EXT_FLOAT32"))
|
||||
{
|
||||
movState->audio.dst_sample_fmt = AV_SAMPLE_FMT_FLT;
|
||||
movState->audio.frame_size = 4;
|
||||
if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_7POINT1 &&
|
||||
alIsExtensionPresent("AL_EXT_MCFORMATS") &&
|
||||
(fmt=alGetEnumValue("AL_FORMAT_71CHN32")) != AL_NONE && fmt != -1)
|
||||
{
|
||||
movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
|
||||
movState->audio.frame_size *= 8;
|
||||
movState->audio.format = fmt;
|
||||
}
|
||||
if((movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1 ||
|
||||
movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
|
||||
alIsExtensionPresent("AL_EXT_MCFORMATS") &&
|
||||
(fmt=alGetEnumValue("AL_FORMAT_51CHN32")) != AL_NONE && fmt != -1)
|
||||
{
|
||||
movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
|
||||
movState->audio.frame_size *= 6;
|
||||
movState->audio.format = fmt;
|
||||
}
|
||||
if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_MONO)
|
||||
{
|
||||
movState->audio.dst_ch_layout = AV_CH_LAYOUT_MONO;
|
||||
movState->audio.frame_size *= 1;
|
||||
movState->audio.format = AL_FORMAT_MONO_FLOAT32;
|
||||
}
|
||||
else
|
||||
if(movState->audio.format == AL_NONE)
|
||||
{
|
||||
movState->audio.dst_ch_layout = AV_CH_LAYOUT_STEREO;
|
||||
movState->audio.frame_size *= 2;
|
||||
movState->audio.format = AL_FORMAT_STEREO_FLOAT32;
|
||||
}
|
||||
}
|
||||
else
|
||||
if(movState->audio.format == AL_NONE)
|
||||
{
|
||||
movState->audio.dst_sample_fmt = AV_SAMPLE_FMT_S16;
|
||||
movState->audio.frame_size = 2;
|
||||
if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_7POINT1 &&
|
||||
alIsExtensionPresent("AL_EXT_MCFORMATS") &&
|
||||
(fmt=alGetEnumValue("AL_FORMAT_71CHN16")) != AL_NONE && fmt != -1)
|
||||
{
|
||||
movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
|
||||
movState->audio.frame_size *= 8;
|
||||
movState->audio.format = fmt;
|
||||
}
|
||||
if((movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1 ||
|
||||
movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
|
||||
alIsExtensionPresent("AL_EXT_MCFORMATS") &&
|
||||
(fmt=alGetEnumValue("AL_FORMAT_51CHN16")) != AL_NONE && fmt != -1)
|
||||
{
|
||||
movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
|
||||
movState->audio.frame_size *= 6;
|
||||
movState->audio.format = fmt;
|
||||
}
|
||||
if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_MONO)
|
||||
{
|
||||
movState->audio.dst_ch_layout = AV_CH_LAYOUT_MONO;
|
||||
movState->audio.frame_size *= 1;
|
||||
movState->audio.format = AL_FORMAT_MONO16;
|
||||
}
|
||||
else
|
||||
if(movState->audio.format == AL_NONE)
|
||||
{
|
||||
movState->audio.dst_ch_layout = AV_CH_LAYOUT_STEREO;
|
||||
movState->audio.frame_size *= 2;
|
||||
@@ -632,7 +684,9 @@ static int audio_thread(void *userdata)
|
||||
movState->audio.dst_ch_layout,
|
||||
movState->audio.dst_sample_fmt,
|
||||
movState->audio.st->codec->sample_rate,
|
||||
movState->audio.st->codec->channel_layout,
|
||||
movState->audio.st->codec->channel_layout ?
|
||||
movState->audio.st->codec->channel_layout :
|
||||
av_get_default_channel_layout(movState->audio.st->codec->channels),
|
||||
movState->audio.st->codec->sample_fmt,
|
||||
movState->audio.st->codec->sample_rate,
|
||||
0, NULL
|
||||
|
||||
@@ -65,13 +65,13 @@ void SDLCALL RenderSDLSamples(void *userdata, Uint8 *stream, int len)
|
||||
* buffer ID. */
|
||||
static ALuint CreateSineWave(void)
|
||||
{
|
||||
ALshort data[44100];
|
||||
ALshort data[44100*4];
|
||||
ALuint buffer;
|
||||
ALenum err;
|
||||
ALuint i;
|
||||
|
||||
for(i = 0;i < 44100;i++)
|
||||
data[i] = (ALshort)(sin(i * 441.0 / 44100.0 * 2.0*M_PI)*32767.0);
|
||||
for(i = 0;i < 44100*4;i++)
|
||||
data[i] = (ALshort)(sin(i/44100.0 * 1000.0 * 2.0*M_PI) * 32767.0);
|
||||
|
||||
/* Buffer the audio data into a new buffer object. */
|
||||
buffer = 0;
|
||||
|
||||
Reference in New Issue
Block a user