[xiph-commits] r17710 - trunk/ao/doc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Thu Dec 2 14:07:37 PST 2010
Author: xiphmont
Date: 2010-12-02 14:07:36 -0800 (Thu, 02 Dec 2010)
New Revision: 17710
Modified:
trunk/ao/doc/ao_example.c
Log:
Update ao_example.c to not segfault on uninitialized matrix field!
Modified: trunk/ao/doc/ao_example.c
===================================================================
--- trunk/ao/doc/ao_example.c 2010-12-02 19:28:11 UTC (rev 17709)
+++ trunk/ao/doc/ao_example.c 2010-12-02 22:07:36 UTC (rev 17710)
@@ -38,47 +38,48 @@
int sample;
float freq = 440.0;
int i;
-
+
/* -- Initialize -- */
-
+
fprintf(stderr, "libao example program\n");
-
+
ao_initialize();
-
+
/* -- Setup for default driver -- */
-
+
default_driver = ao_default_driver_id();
+ memset(&format, 0, sizeof(format));
format.bits = 16;
format.channels = 2;
format.rate = 44100;
format.byte_format = AO_FMT_LITTLE;
-
+
/* -- Open driver -- */
device = ao_open_live(default_driver, &format, NULL /* no options */);
if (device == NULL) {
fprintf(stderr, "Error opening device.\n");
return 1;
- }
-
+ }
+
/* -- Play some stuff -- */
buf_size = format.bits/8 * format.channels * format.rate;
- buffer = calloc(buf_size,
+ buffer = calloc(buf_size,
sizeof(char));
-
+
for (i = 0; i < format.rate; i++) {
- sample = (int)(0.75 * 32768.0 *
+ sample = (int)(0.75 * 32768.0 *
sin(2 * M_PI * freq * ((float) i/format.rate)));
-
+
/* Put the same stuff in left and right channel */
buffer[4*i] = buffer[4*i+2] = sample & 0xff;
buffer[4*i+1] = buffer[4*i+3] = (sample >> 8) & 0xff;
}
ao_play(device, buffer, buf_size);
-
+
/* -- Close and shutdown -- */
ao_close(device);
-
+
ao_shutdown();
return (0);
More information about the commits
mailing list