Added vorbis-tools.
[vorbis-lancer-gcc.git] / vorbis-tools-1.2.0 / ogg123 / audio.c
blobf4a6d8911fc7cb2f37f943c62c0b89041ffd450f
1 /********************************************************************
2 * *
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7 * *
8 * THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2001 *
9 * by Stan Seibert <volsung@xiph.org> AND OTHER CONTRIBUTORS *
10 * http://www.xiph.org/ *
11 * *
12 ********************************************************************
14 last mod: $Id: audio.c,v 1.2 2001/12/19 02:52:53 volsung Exp $
16 ********************************************************************/
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
22 #include <stdio.h>
23 #include <string.h>
24 #include <limits.h>
26 #include "audio.h"
29 int audio_format_equal (audio_format_t *a, audio_format_t *b)
31 return
32 a->big_endian == b->big_endian &&
33 a->word_size == b->word_size &&
34 a->signed_sample == b->signed_sample &&
35 a->rate == b->rate &&
36 a->channels == b->channels;
40 audio_device_t *append_audio_device(audio_device_t *devices_list,
41 int driver_id,
42 ao_option *options, char *filename)
44 audio_device_t *head = devices_list;
46 if (devices_list != NULL) {
47 while (devices_list->next_device != NULL)
48 devices_list = devices_list->next_device;
49 devices_list = devices_list->next_device =
50 malloc(sizeof(audio_device_t));
51 } else {
52 head = devices_list = (audio_device_t *) malloc(sizeof(audio_device_t));
54 devices_list->driver_id = driver_id;
55 devices_list->options = options;
56 devices_list->filename = filename;
57 devices_list->device = NULL;
58 devices_list->next_device = NULL;
60 return devices_list;
64 int audio_devices_write(audio_device_t *d, void *ptr, int nbytes)
67 while (d != NULL) {
68 if (ao_play(d->device, ptr, nbytes) == 0)
69 return 0; /* error occurred */
70 d = d->next_device;
73 return 1;
76 int add_ao_option(ao_option **op_h, const char *optstring)
78 char *key, *value;
79 int result;
81 key = strdup(optstring);
82 if (key == NULL)
83 return 0;
85 value = strchr(key, ':');
86 if (value == NULL) {
87 free(key);
88 return 0;
91 /* split by replacing the separator with a null */
92 *value++ = '\0';
94 result = ao_append_option(op_h, key, value);
95 free(key);
97 return (result);
100 void close_audio_devices (audio_device_t *devices)
102 audio_device_t *current = devices;
104 while (current != NULL) {
105 if (current->device)
106 ao_close(current->device);
107 current->device = NULL;
108 current = current->next_device;
112 void free_audio_devices (audio_device_t *devices)
114 audio_device_t *current;
116 while (devices != NULL) {
117 current = devices->next_device;
118 free (devices);
119 devices = current;
123 void ao_onexit (void *arg)
125 audio_device_t *devices = (audio_device_t *) arg;
127 close_audio_devices (devices);
128 free_audio_devices (devices);
130 ao_shutdown();