00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <ao/ao.h>
00031 #include <stdio.h>
00032 #include <stdbool.h>
00033 #include <errno.h>
00034 #include <assert.h>
00035
00036 #include "daisylibao.h"
00037 #include "common.h"
00038 #include "audio.h"
00039 #include "report.h"
00040 #include "snprintf/snprintf.h"
00041
00042
00043
00044
00045
00046
00047
00048 static
00049 void ao_open_live_error (void);
00050
00051
00052
00053
00054
00055
00056
00061 static
00062 void ao_open_live_error (void)
00063 {
00064 switch (errno)
00065 {
00066 case AO_ENODRIVER:
00067 report ("No driver corresponts to driver ID.", REP_ERROR);
00068 break;
00069 case AO_ENOTLIVE:
00070 report ("This driver is not a live output device.", REP_ERROR);
00071 break;
00072 case AO_EBADOPTION:
00073 report ("A valid option key has an invalid value.", REP_ERROR);
00074 break;
00075 case AO_EOPENDEVICE:
00076 report ("Cannot open the device.", REP_ERROR);
00077 break;
00078 case AO_EFAIL:
00079 report ("Unknown reason.", REP_ERROR);
00080 break;
00081 default:
00082 report ("ao_open_live_error called with unknown error", REP_ERROR);
00083 break;
00084 }
00085 }
00086
00087
00088
00089
00090
00091
00092
00101 ao_device * libao_initiate (int byte_format, int channels, int samplerate)
00102 {
00103 ao_device *device = NULL;
00104
00105 ao_sample_format format;
00106 int libao_driver_id = -1;
00107
00108 ao_initialize ();
00109 libao_driver_id = ao_default_driver_id ();
00110 if (libao_driver_id == -1) {
00111 report("Could not get a valid driver ID", REP_ERROR);
00112 return false;
00113 }
00114 format.bits = 16;
00115
00116 format.byte_format = byte_format;
00117 format.channels = channels;
00118 format.rate = samplerate;
00119
00120 device = ao_open_live (libao_driver_id, &format, NULL);
00121 if (device == NULL)
00122 {
00123 ao_open_live_error();
00124 return NULL;
00125 }
00126 else if (DEBUG_LIBAO)
00127 {
00128 char msg[STRLEN];
00129 report ("libao initialized", REP_DEBUG);
00130 snprintf (msg, STRLEN, "libao info:\n\tbyte_format: %d\n\tchannels: %d\n\tsamplerate: %d", byte_format, channels, samplerate);
00131 report (msg, REP_DEBUG);
00132 }
00133 return device;
00134 }
00135
00143 int libao_play (ao_device *device, void *output_samples, int num_bytes)
00144 {
00145 return ao_play(device, output_samples, num_bytes);
00146 }
00147
00152 void libao_terminate (ao_device *device)
00153 {
00154 ao_close (device);
00155 ao_shutdown ();
00156 if (DEBUG_LIBAO) report ("libao closed", REP_DEBUG);
00157 }