[c47208]: / ogg123 / audio.c  Maximize  Restore  History

Download this file

128 lines (100 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
* THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
* PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2001 *
* by Stan Seibert <volsung@xiph.org> AND OTHER CONTRIBUTORS *
* http://www.xiph.org/ *
* *
********************************************************************
last mod: $Id: audio.c,v 1.2 2001/12/19 02:52:53 volsung Exp $
********************************************************************/
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "audio.h"
int audio_format_equal (audio_format_t *a, audio_format_t *b)
{
return
a->big_endian == b->big_endian &&
a->word_size == b->word_size &&
a->signed_sample == b->signed_sample &&
a->rate == b->rate &&
a->channels == b->channels;
}
audio_device_t *append_audio_device(audio_device_t *devices_list,
int driver_id,
ao_option *options, char *filename)
{
audio_device_t *head = devices_list;
if (devices_list != NULL) {
while (devices_list->next_device != NULL)
devices_list = devices_list->next_device;
devices_list = devices_list->next_device =
malloc(sizeof(audio_device_t));
} else {
head = devices_list = (audio_device_t *) malloc(sizeof(audio_device_t));
}
devices_list->driver_id = driver_id;
devices_list->options = options;
devices_list->filename = filename;
devices_list->device = NULL;
devices_list->next_device = NULL;
return devices_list;
}
int audio_devices_write(audio_device_t *d, void *ptr, int nbytes)
{
while (d != NULL) {
if (ao_play(d->device, ptr, nbytes) == 0)
return 0; /* error occurred */
d = d->next_device;
}
return 1;
}
int add_ao_option(ao_option **op_h, const char *optstring)
{
char *key, *value;
int result;
key = strdup(optstring);
if (key == NULL)
return 0;
value = strchr(key, ':');
if (value == NULL) {
free(key);
return 0;
}
/* split by replacing the separator with a null */
*value++ = '\0';
result = ao_append_option(op_h, key, value);
free(key);
return (result);
}
void close_audio_devices (audio_device_t *devices)
{
audio_device_t *current = devices;
while (current != NULL) {
if (current->device)
ao_close(current->device);
current->device = NULL;
current = current->next_device;
}
}
void free_audio_devices (audio_device_t *devices)
{
audio_device_t *current;
while (devices != NULL) {
current = devices->next_device;
free (devices);
devices = current;
}
}
void ao_onexit (void *arg)
{
audio_device_t *devices = (audio_device_t *) arg;
close_audio_devices (devices);
free_audio_devices (devices);
ao_shutdown();
}