5 * Written by Stan Seibert - July 2001
9 * This source file is released into the public domain. It is
10 * distributed without any warranty; without even the implied
11 * warranty * of merchantability or fitness for a particular
16 * This program opens the default driver and plays a 440 Hz tone for
19 * Compilation command line (for Linux systems):
21 * gcc -lao -ldl -lm -o ao_example ao_example.c
31 int main(int argc
, char **argv
)
34 ao_sample_format format
;
42 /* -- Initialize -- */
44 fprintf(stderr
, "libao example program\n");
48 /* -- Setup for default driver -- */
50 default_driver
= ao_default_driver_id();
55 format
.byte_format
= AO_FMT_LITTLE
;
57 /* -- Open driver -- */
58 device
= ao_open_live(default_driver
, &format
, NULL
/* no options */);
60 fprintf(stderr
, "Error opening device.\n");
64 /* -- Play some stuff -- */
65 buf_size
= format
.bits
/8 * format
.channels
* format
.rate
;
66 buffer
= calloc(buf_size
,
69 for (i
= 0; i
< format
.rate
; i
++) {
70 sample
= (int)(0.75 * 32768.0 *
71 sin(2 * M_PI
* freq
* ((float) i
/format
.rate
)));
73 /* Put the same stuff in left and right channel */
74 buffer
[4*i
] = buffer
[4*i
+2] = sample
& 0xff;
75 buffer
[4*i
+1] = buffer
[4*i
+3] = (sample
>> 8) & 0xff;
77 ao_play(device
, buffer
, buf_size
);
79 /* -- Close and shutdown -- */