Main Page   Data Structures   File List   Data Fields   Globals  

daisylibao.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006 by André Lindhjem <belgarat@sdf.lonestar.org>,     *
00003  *                         Kjetil Holien <kjetil.holien@gmail.com>,        *
00004  *                         Terje Risa <terje.risa@gmail.com> &             *
00005  *                         Øyvind Nerbråten <oyvind@nerbraten.com>         *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************
00022  *
00023  * \file daisylibao.c
00024  * \author André Lindhjem, Kjetil Holien, Terje Risa & Øyvind Nerbråten
00025  * \date 15.02.2006
00026  *
00027  * An interface against libao. Audio decoders should use this instead of using libao directly.
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  *          Static function declarations              *
00046  * ************************************************** */
00047 
00048 static
00049 void ao_open_live_error (void);
00050 
00051 
00052 
00053 /* ************************************************** *
00054  *          Static function definitions               *
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  *          Global function definitions               *
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; /* Do decoder always give us 16bits? */
00115 /*  format.byte_format = AO_FMT_LITTLE; */
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 }

Generated on Tue Sep 5 12:14:07 2006 for libdaisy by doxygen1.2.15