Recognizes if input is ogg or not.
[xiph.git] / ao / src / ao_raw.c
blobc5b872c25412a7ed65cd15be00e30bb25fdecd7c
1 /*
3 * ao_raw.c
5 * Copyright (C) Stan Seibert - January 2001, July 2001
7 * This file is part of libao, a cross-platform audio output library. See
8 * README for a history of this source code.
10 * libao is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
15 * libao is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with GNU Make; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <stdio.h>
27 #include <string.h>
28 #include <errno.h>
29 #include <ao/ao.h>
30 #include <ao/plugin.h>
32 static char *ao_raw_options[] = {"byteorder"};
33 static ao_info ao_raw_info =
35 AO_TYPE_FILE,
36 "RAW sample output",
37 "raw",
38 "Stan Seibert <indigo@aztec.asu.edu>",
39 "Writes raw audio samples to a file",
40 AO_FMT_NATIVE,
42 ao_raw_options,
46 typedef struct ao_raw_internal
48 int byte_order;
49 } ao_raw_internal;
52 static int ao_raw_test(void)
54 return 1; /* Always works */
58 static ao_info *ao_raw_driver_info(void)
60 return &ao_raw_info;
64 static int ao_raw_device_init(ao_device *device)
66 ao_raw_internal *internal;
68 internal = (ao_raw_internal *) malloc(sizeof(ao_raw_internal));
70 if (internal == NULL)
71 return 0; /* Could not initialize device memory */
73 internal->byte_order = AO_FMT_NATIVE;
75 device->internal = internal;
77 return 1; /* Memory alloc successful */
80 static int ao_raw_set_option(ao_device *device, const char *key,
81 const char *value)
83 ao_raw_internal *internal = (ao_raw_internal *)device->internal;
85 if (!strcmp(key, "byteorder")) {
86 if (!strcmp(value, "native"))
87 internal->byte_order = AO_FMT_NATIVE;
88 else if (!strcmp(value, "big"))
89 internal->byte_order = AO_FMT_BIG;
90 else if (!strcmp(value, "little"))
91 internal->byte_order = AO_FMT_LITTLE;
92 else
93 return 0; /* Bad option value */
96 return 1;
100 static int ao_raw_open(ao_device *device, ao_sample_format *format)
102 ao_raw_internal *internal = (ao_raw_internal *)device->internal;
104 device->driver_byte_format = internal->byte_order;
106 return 1;
111 * play the sample to the already opened file descriptor
113 static int ao_raw_play(ao_device *device, const char *output_samples,
114 uint_32 num_bytes)
116 if (fwrite(output_samples, sizeof(char), num_bytes,
117 device->file) < num_bytes)
118 return 0;
119 else
120 return 1;
124 static int ao_raw_close(ao_device *device)
126 /* No closeout needed */
127 return 1;
131 static void ao_raw_device_clear(ao_device *device)
133 ao_raw_internal *internal = (ao_raw_internal *) device->internal;
135 free(internal);
139 ao_functions ao_raw = {
140 ao_raw_test,
141 ao_raw_driver_info,
142 ao_raw_device_init,
143 ao_raw_set_option,
144 ao_raw_open,
145 ao_raw_play,
146 ao_raw_close,
147 ao_raw_device_clear