summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-04 01:34:53 +0200
committerwm4 <wm4@nowhere>2013-06-04 01:34:53 +0200
commita933cf28f2727cc76fd24f675ef89681f1865db6 (patch)
treea60d93392cafd8ba2df7fdd83a96b32f5f67b11e /audio
parent774dc23ab34cc4c38f3d1d04c7d5dc6190ec923b (diff)
downloadmpv-a933cf28f2727cc76fd24f675ef89681f1865db6.tar.bz2
mpv-a933cf28f2727cc76fd24f675ef89681f1865db6.tar.xz
ao_openal: uncrustify
Diffstat (limited to 'audio')
-rw-r--r--audio/out/ao_openal.c357
1 files changed, 185 insertions, 172 deletions
diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c
index c622c5f140..c693674984 100644
--- a/audio/out/ao_openal.c
+++ b/audio/out/ao_openal.c
@@ -45,10 +45,10 @@
static const ao_info_t info =
{
- "OpenAL audio output",
- "openal",
- "Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de>",
- ""
+ "OpenAL audio output",
+ "openal",
+ "Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de>",
+ ""
};
LIBAO_EXTERN(openal)
@@ -64,49 +64,52 @@ static int unqueue_buf[MAX_CHANS];
static int16_t *tmpbuf;
-static int control(int cmd, void *arg) {
- switch (cmd) {
+static int control(int cmd, void *arg)
+{
+ switch (cmd) {
case AOCONTROL_GET_VOLUME:
case AOCONTROL_SET_VOLUME: {
- ALfloat volume;
- ao_control_vol_t *vol = (ao_control_vol_t *)arg;
- if (cmd == AOCONTROL_SET_VOLUME) {
- volume = (vol->left + vol->right) / 200.0;
- alListenerf(AL_GAIN, volume);
- }
- alGetListenerf(AL_GAIN, &volume);
- vol->left = vol->right = volume * 100;
- return CONTROL_TRUE;
+ ALfloat volume;
+ ao_control_vol_t *vol = (ao_control_vol_t *)arg;
+ if (cmd == AOCONTROL_SET_VOLUME) {
+ volume = (vol->left + vol->right) / 200.0;
+ alListenerf(AL_GAIN, volume);
+ }
+ alGetListenerf(AL_GAIN, &volume);
+ vol->left = vol->right = volume * 100;
+ return CONTROL_TRUE;
+ }
}
- }
- return CONTROL_UNKNOWN;
+ return CONTROL_UNKNOWN;
}
/**
* \brief print suboption usage help
*/
-static void print_help(void) {
- mp_msg(MSGT_AO, MSGL_FATAL,
- "\n-ao openal commandline help:\n"
- "Example: mpv -ao openal:device=subdevice\n"
- "\nOptions:\n"
- " device=subdevice\n"
- " Audio device OpenAL should use. Devices can be listed\n"
- " with -ao openal:device=help\n"
- );
+static void print_help(void)
+{
+ mp_msg(MSGT_AO, MSGL_FATAL,
+ "\n-ao openal commandline help:\n"
+ "Example: mpv -ao openal:device=subdevice\n"
+ "\nOptions:\n"
+ " device=subdevice\n"
+ " Audio device OpenAL should use. Devices can be listed\n"
+ " with -ao openal:device=help\n"
+ );
}
-static void list_devices(void) {
- if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_TRUE) {
- mp_msg(MSGT_AO, MSGL_FATAL, "Device listing not supported.\n");
- return;
- }
- const char *list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
- mp_msg(MSGT_AO, MSGL_FATAL, "OpenAL devices:\n");
- while (list && *list) {
- mp_msg(MSGT_AO, MSGL_FATAL, " '%s'\n", list);
- list = list + strlen(list) + 1;
- }
+static void list_devices(void)
+{
+ if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_TRUE) {
+ mp_msg(MSGT_AO, MSGL_FATAL, "Device listing not supported.\n");
+ return;
+ }
+ const char *list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
+ mp_msg(MSGT_AO, MSGL_FATAL, "OpenAL devices:\n");
+ while (list && *list) {
+ mp_msg(MSGT_AO, MSGL_FATAL, " '%s'\n", list);
+ list = list + strlen(list) + 1;
+ }
}
struct speaker {
@@ -130,175 +133,185 @@ static const struct speaker speaker_pos[] = {
static int init(int rate, const struct mp_chmap *channels, int format,
int flags)
{
- float position[3] = {0, 0, 0};
- float direction[6] = {0, 0, 1, 0, -1, 0};
- ALCdevice *dev = NULL;
- ALCcontext *ctx = NULL;
- ALCint freq = 0;
- ALCint attribs[] = {ALC_FREQUENCY, rate, 0, 0};
- int i;
- char *device = NULL;
- const opt_t subopts[] = {
- {"device", OPT_ARG_MSTRZ, &device, NULL},
- {NULL}
- };
- global_ao->no_persistent_volume = true;
- if (subopt_parse(ao_subdevice, subopts) != 0) {
- print_help();
- return 0;
- }
- if (device && strcmp(device, "help") == 0) {
- list_devices();
- goto err_out;
- }
- struct mp_chmap_sel sel = {0};
- for (i = 0; speaker_pos[i].id != -1; i++)
- mp_chmap_sel_add_speaker(&sel, speaker_pos[i].id);
- if (!ao_chmap_sel_adjust(&ao_data, &sel, &ao_data.channels))
- goto err_out;
- struct speaker speakers[MAX_CHANS];
- for (i = 0; i < ao_data.channels.num; i++) {
- speakers[i].id = -1;
- for (int n = 0; speaker_pos[n].id >= 0; n++) {
- if (speaker_pos[n].id == ao_data.channels.speaker[i])
- speakers[i] = speaker_pos[n];
+ float position[3] = {0, 0, 0};
+ float direction[6] = {0, 0, 1, 0, -1, 0};
+ ALCdevice *dev = NULL;
+ ALCcontext *ctx = NULL;
+ ALCint freq = 0;
+ ALCint attribs[] = {ALC_FREQUENCY, rate, 0, 0};
+ int i;
+ char *device = NULL;
+ const opt_t subopts[] = {
+ {"device", OPT_ARG_MSTRZ, &device, NULL},
+ {NULL}
+ };
+ global_ao->no_persistent_volume = true;
+ if (subopt_parse(ao_subdevice, subopts) != 0) {
+ print_help();
+ return 0;
}
- if (speakers[i].id < 0) {
- mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] Unknown channel layout\n");
- goto err_out;
+ if (device && strcmp(device, "help") == 0) {
+ list_devices();
+ goto err_out;
}
- }
- dev = alcOpenDevice(device);
- if (!dev) {
- mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] could not open device\n");
- goto err_out;
- }
- ctx = alcCreateContext(dev, attribs);
- alcMakeContextCurrent(ctx);
- alListenerfv(AL_POSITION, position);
- alListenerfv(AL_ORIENTATION, direction);
- alGenSources(ao_data.channels.num, sources);
- for (i = 0; i < ao_data.channels.num; i++) {
- cur_buf[i] = 0;
- unqueue_buf[i] = 0;
- alGenBuffers(NUM_BUF, buffers[i]);
- alSourcefv(sources[i], AL_POSITION, speakers[i].pos);
- alSource3f(sources[i], AL_VELOCITY, 0, 0, 0);
- }
- alcGetIntegerv(dev, ALC_FREQUENCY, 1, &freq);
- if (alcGetError(dev) == ALC_NO_ERROR && freq)
- rate = freq;
- ao_data.samplerate = rate;
- ao_data.format = AF_FORMAT_S16_NE;
- ao_data.bps = ao_data.channels.num * rate * 2;
- ao_data.buffersize = CHUNK_SIZE * NUM_BUF;
- ao_data.outburst = ao_data.channels.num * CHUNK_SIZE;
- tmpbuf = malloc(CHUNK_SIZE);
- free(device);
- return 1;
+ struct mp_chmap_sel sel = {0};
+ for (i = 0; speaker_pos[i].id != -1; i++)
+ mp_chmap_sel_add_speaker(&sel, speaker_pos[i].id);
+ if (!ao_chmap_sel_adjust(&ao_data, &sel, &ao_data.channels))
+ goto err_out;
+ struct speaker speakers[MAX_CHANS];
+ for (i = 0; i < ao_data.channels.num; i++) {
+ speakers[i].id = -1;
+ for (int n = 0; speaker_pos[n].id >= 0; n++) {
+ if (speaker_pos[n].id == ao_data.channels.speaker[i])
+ speakers[i] = speaker_pos[n];
+ }
+ if (speakers[i].id < 0) {
+ mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] Unknown channel layout\n");
+ goto err_out;
+ }
+ }
+ dev = alcOpenDevice(device);
+ if (!dev) {
+ mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] could not open device\n");
+ goto err_out;
+ }
+ ctx = alcCreateContext(dev, attribs);
+ alcMakeContextCurrent(ctx);
+ alListenerfv(AL_POSITION, position);
+ alListenerfv(AL_ORIENTATION, direction);
+ alGenSources(ao_data.channels.num, sources);
+ for (i = 0; i < ao_data.channels.num; i++) {
+ cur_buf[i] = 0;
+ unqueue_buf[i] = 0;
+ alGenBuffers(NUM_BUF, buffers[i]);
+ alSourcefv(sources[i], AL_POSITION, speakers[i].pos);
+ alSource3f(sources[i], AL_VELOCITY, 0, 0, 0);
+ }
+ alcGetIntegerv(dev, ALC_FREQUENCY, 1, &freq);
+ if (alcGetError(dev) == ALC_NO_ERROR && freq)
+ rate = freq;
+ ao_data.samplerate = rate;
+ ao_data.format = AF_FORMAT_S16_NE;
+ ao_data.bps = ao_data.channels.num * rate * 2;
+ ao_data.buffersize = CHUNK_SIZE * NUM_BUF;
+ ao_data.outburst = ao_data.channels.num * CHUNK_SIZE;
+ tmpbuf = malloc(CHUNK_SIZE);
+ free(device);
+ return 1;
err_out:
- free(device);
- return 0;
+ free(device);
+ return 0;
}
// close audio device
-static void uninit(int immed) {
- ALCcontext *ctx = alcGetCurrentContext();
- ALCdevice *dev = alcGetContextsDevice(ctx);
- free(tmpbuf);
- if (!immed) {
- ALint state;
- alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
- while (state == AL_PLAYING) {
- mp_sleep_us(10000);
- alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
+static void uninit(int immed)
+{
+ ALCcontext *ctx = alcGetCurrentContext();
+ ALCdevice *dev = alcGetContextsDevice(ctx);
+ free(tmpbuf);
+ if (!immed) {
+ ALint state;
+ alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
+ while (state == AL_PLAYING) {
+ mp_sleep_us(10000);
+ alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
+ }
}
- }
- reset();
- alcMakeContextCurrent(NULL);
- alcDestroyContext(ctx);
- alcCloseDevice(dev);
+ reset();
+ alcMakeContextCurrent(NULL);
+ alcDestroyContext(ctx);
+ alcCloseDevice(dev);
}
-static void unqueue_buffers(void) {
- ALint p;
- int s;
- for (s = 0; s < ao_data.channels.num; s++) {
- int till_wrap = NUM_BUF - unqueue_buf[s];
- alGetSourcei(sources[s], AL_BUFFERS_PROCESSED, &p);
- if (p >= till_wrap) {
- alSourceUnqueueBuffers(sources[s], till_wrap, &buffers[s][unqueue_buf[s]]);
- unqueue_buf[s] = 0;
- p -= till_wrap;
- }
- if (p) {
- alSourceUnqueueBuffers(sources[s], p, &buffers[s][unqueue_buf[s]]);
- unqueue_buf[s] += p;
+static void unqueue_buffers(void)
+{
+ ALint p;
+ int s;
+ for (s = 0; s < ao_data.channels.num; s++) {
+ int till_wrap = NUM_BUF - unqueue_buf[s];
+ alGetSourcei(sources[s], AL_BUFFERS_PROCESSED, &p);
+ if (p >= till_wrap) {
+ alSourceUnqueueBuffers(sources[s], till_wrap,
+ &buffers[s][unqueue_buf[s]]);
+ unqueue_buf[s] = 0;
+ p -= till_wrap;
+ }
+ if (p) {
+ alSourceUnqueueBuffers(sources[s], p, &buffers[s][unqueue_buf[s]]);
+ unqueue_buf[s] += p;
+ }
}
- }
}
/**
* \brief stop playing and empty buffers (for seeking/pause)
*/
-static void reset(void) {
- alSourceStopv(ao_data.channels.num, sources);
- unqueue_buffers();
+static void reset(void)
+{
+ alSourceStopv(ao_data.channels.num, sources);
+ unqueue_buffers();
}
/**
* \brief stop playing, keep buffers (for pause)
*/
-static void audio_pause(void) {
- alSourcePausev(ao_data.channels.num, sources);
+static void audio_pause(void)
+{
+ alSourcePausev(ao_data.channels.num, sources);
}
/**
* \brief resume playing, after audio_pause()
*/
-static void audio_resume(void) {
- alSourcePlayv(ao_data.channels.num, sources);
+static void audio_resume(void)
+{
+ alSourcePlayv(ao_data.channels.num, sources);
}
-static int get_space(void) {
- ALint queued;
- unqueue_buffers();
- alGetSourcei(sources[0], AL_BUFFERS_QUEUED, &queued);
- queued = NUM_BUF - queued - 3;
- if (queued < 0) return 0;
- return queued * CHUNK_SIZE * ao_data.channels.num;
+static int get_space(void)
+{
+ ALint queued;
+ unqueue_buffers();
+ alGetSourcei(sources[0], AL_BUFFERS_QUEUED, &queued);
+ queued = NUM_BUF - queued - 3;
+ if (queued < 0)
+ return 0;
+ return queued * CHUNK_SIZE * ao_data.channels.num;
}
/**
* \brief write data into buffer and reset underrun flag
*/
-static int play(void *data, int len, int flags) {
- ALint state;
- int i, j, k;
- int ch;
- int16_t *d = data;
- len /= ao_data.channels.num * CHUNK_SIZE;
- for (i = 0; i < len; i++) {
- for (ch = 0; ch < ao_data.channels.num; ch++) {
- for (j = 0, k = ch; j < CHUNK_SIZE / 2; j++, k += ao_data.channels.num)
- tmpbuf[j] = d[k];
- alBufferData(buffers[ch][cur_buf[ch]], AL_FORMAT_MONO16, tmpbuf,
- CHUNK_SIZE, ao_data.samplerate);
- alSourceQueueBuffers(sources[ch], 1, &buffers[ch][cur_buf[ch]]);
- cur_buf[ch] = (cur_buf[ch] + 1) % NUM_BUF;
+static int play(void *data, int len, int flags)
+{
+ ALint state;
+ int i, j, k;
+ int ch;
+ int16_t *d = data;
+ len /= ao_data.channels.num * CHUNK_SIZE;
+ for (i = 0; i < len; i++) {
+ for (ch = 0; ch < ao_data.channels.num; ch++) {
+ for (j = 0, k = ch; j < CHUNK_SIZE / 2; j++, k += ao_data.channels.num)
+ tmpbuf[j] = d[k];
+ alBufferData(buffers[ch][cur_buf[ch]], AL_FORMAT_MONO16, tmpbuf,
+ CHUNK_SIZE, ao_data.samplerate);
+ alSourceQueueBuffers(sources[ch], 1, &buffers[ch][cur_buf[ch]]);
+ cur_buf[ch] = (cur_buf[ch] + 1) % NUM_BUF;
+ }
+ d += ao_data.channels.num * CHUNK_SIZE / 2;
}
- d += ao_data.channels.num * CHUNK_SIZE / 2;
- }
- alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
- if (state != AL_PLAYING) // checked here in case of an underrun
- alSourcePlayv(ao_data.channels.num, sources);
- return len * ao_data.channels.num * CHUNK_SIZE;
+ alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
+ if (state != AL_PLAYING) // checked here in case of an underrun
+ alSourcePlayv(ao_data.channels.num, sources);
+ return len * ao_data.channels.num * CHUNK_SIZE;
}
-static float get_delay(void) {
- ALint queued;
- unqueue_buffers();
- alGetSourcei(sources[0], AL_BUFFERS_QUEUED, &queued);
- return queued * CHUNK_SIZE / 2 / (float)ao_data.samplerate;
+static float get_delay(void)
+{
+ ALint queued;
+ unqueue_buffers();
+ alGetSourcei(sources[0], AL_BUFFERS_QUEUED, &queued);
+ return queued * CHUNK_SIZE / 2 / (float)ao_data.samplerate;
}