diff options
Diffstat (limited to 'audio/out/ao_openal.c')
-rw-r--r-- | audio/out/ao_openal.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c index 64d957e893..7172908e70 100644 --- a/audio/out/ao_openal.c +++ b/audio/out/ao_openal.c @@ -19,8 +19,6 @@ * License along with mpv. If not, see <http://www.gnu.org/licenses/>. */ -#include "config.h" - #include <stdlib.h> #include <stdio.h> #include <inttypes.h> @@ -58,7 +56,7 @@ struct priv { ALenum al_format; int num_buffers; int num_samples; - int direct_channels; + bool direct_channels; }; static int control(struct ao *ao, enum aocontrol cmd, void *arg) @@ -67,13 +65,13 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg) case AOCONTROL_GET_VOLUME: case AOCONTROL_SET_VOLUME: { ALfloat volume; - ao_control_vol_t *vol = (ao_control_vol_t *)arg; + float *vol = arg; if (cmd == AOCONTROL_SET_VOLUME) { - volume = (vol->left + vol->right) / 200.0; + volume = *vol / 100.0; alListenerf(AL_GAIN, volume); } alGetListenerf(AL_GAIN, &volume); - vol->left = vol->right = volume * 100; + *vol = volume * 100; return CONTROL_TRUE; } case AOCONTROL_GET_MUTE: @@ -175,9 +173,6 @@ static void uninit(struct ao *ao) static int init(struct ao *ao) { - MP_FATAL(ao, "broken.\n"); - return -1; - float position[3] = {0, 0, 0}; float direction[6] = {0, 0, -1, 0, 1, 0}; ALCdevice *dev = NULL; @@ -202,8 +197,14 @@ static int init(struct ao *ao) alListenerfv(AL_ORIENTATION, direction); alGenSources(1, &source); - if (p->direct_channels && alGetEnumValue((ALchar*)"AL_DIRECT_CHANNELS_SOFT")) { - alSourcei(source, alGetEnumValue((ALchar*)"AL_DIRECT_CHANNELS_SOFT"), AL_TRUE); + if (p->direct_channels) { + if (alIsExtensionPresent("AL_SOFT_direct_channels_remix")) { + alSourcei(source, + alGetEnumValue((ALchar*)"AL_DIRECT_CHANNELS_SOFT"), + alcGetEnumValue(dev, "AL_REMIX_UNMATCHED_SOFT")); + } else { + MP_WARN(ao, "Direct channels aren't supported by this version of OpenAL\n"); + } } cur_buf = 0; @@ -267,7 +268,7 @@ static int init(struct ao *ao) goto err_out; } - ao->period_size = p->num_samples; + ao->device_buffer = p->num_buffers * p->num_samples; return 0; err_out: @@ -317,7 +318,7 @@ static bool audio_write(struct ao *ao, void **data, int samples) for (int i = 0; i < num; i++) { char *d = *data; buffer_size[cur_buf] = - MPMIN(samples - num * p->num_samples, p->num_samples); + MPMIN(samples - i * p->num_samples, p->num_samples); d += i * buffer_size[cur_buf] * ao->sstride; alBufferData(buffers[cur_buf], p->al_format, d, buffer_size[cur_buf] * ao->sstride, ao->samplerate); @@ -341,18 +342,18 @@ static void get_state(struct ao *ao, struct mp_pcm_state *state) unqueue_buffers(ao); alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); - double soft_source_latency = 0; + double source_offset = 0; if(alIsExtensionPresent("AL_SOFT_source_latency")) { ALdouble offsets[2]; LPALGETSOURCEDVSOFT alGetSourcedvSOFT = alGetProcAddress("alGetSourcedvSOFT"); alGetSourcedvSOFT(source, AL_SEC_OFFSET_LATENCY_SOFT, offsets); // Additional latency to the play buffer, the remaining seconds to be // played minus the offset (seconds already played) - soft_source_latency = offsets[1] - offsets[0]; + source_offset = offsets[1] - offsets[0]; } else { float offset = 0; alGetSourcef(source, AL_SEC_OFFSET, &offset); - soft_source_latency = -offset; + source_offset = -offset; } int queued_samples = 0; @@ -361,10 +362,14 @@ static void get_state(struct ao *ao, struct mp_pcm_state *state) index = (index + 1) % p->num_buffers; } - state->delay = queued_samples / (double)ao->samplerate + soft_source_latency; + state->delay = queued_samples / (double)ao->samplerate + source_offset; state->queued_samples = queued_samples; state->free_samples = MPMAX(p->num_buffers - queued, 0) * p->num_samples; + + ALint source_state = 0; + alGetSourcei(source, AL_SOURCE_STATE, &source_state); + state->playing = source_state == AL_PLAYING; } #define OPT_BASE_STRUCT struct priv @@ -384,12 +389,12 @@ const struct ao_driver audio_out_openal = { .priv_defaults = &(const struct priv) { .num_buffers = 4, .num_samples = 8192, - .direct_channels = 0, + .direct_channels = true, }, .options = (const struct m_option[]) { {"num-buffers", OPT_INT(num_buffers), M_RANGE(2, MAX_BUF)}, {"num-samples", OPT_INT(num_samples), M_RANGE(256, MAX_SAMPLES)}, - {"direct-channels", OPT_FLAG(direct_channels)}, + {"direct-channels", OPT_BOOL(direct_channels)}, {0} }, .options_prefix = "openal", |