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)
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.
30 #include <ao/plugin.h>
32 static char *ao_raw_options
[] = {"byteorder"};
33 static ao_info ao_raw_info
=
38 "Stan Seibert <indigo@aztec.asu.edu>",
39 "Writes raw audio samples to a file",
46 typedef struct ao_raw_internal
52 static int ao_raw_test(void)
54 return 1; /* Always works */
58 static ao_info
*ao_raw_driver_info(void)
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
));
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
,
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
;
93 return 0; /* Bad option value */
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
;
111 * play the sample to the already opened file descriptor
113 static int ao_raw_play(ao_device
*device
, const char *output_samples
,
116 if (fwrite(output_samples
, sizeof(char), num_bytes
,
117 device
->file
) < num_bytes
)
124 static int ao_raw_close(ao_device
*device
)
126 /* No closeout needed */
131 static void ao_raw_device_clear(ao_device
*device
)
133 ao_raw_internal
*internal
= (ao_raw_internal
*) device
->internal
;
139 ao_functions ao_raw
= {