1 /* 2 * madplay - MPEG audio decoder and player 3 * Copyright (C) 2000-2004 Robert Leslie 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * $Id: audio.h,v 1.38 2004/01/23 09:41:31 rob Exp $ 20 */ 21 22 # ifndef AUDIO_H 23 # define AUDIO_H 24 25 # include <mad.h> 26 27 # define MAX_RESAMPLEFACTOR 6 28 # define MAX_NSAMPLES (1152 * MAX_RESAMPLEFACTOR) 29 30 enum audio_command { 31 AUDIO_COMMAND_INIT, 32 AUDIO_COMMAND_CONFIG, 33 AUDIO_COMMAND_PLAY, 34 AUDIO_COMMAND_STOP, 35 AUDIO_COMMAND_FINISH 36 }; 37 38 enum audio_mode { 39 AUDIO_MODE_ROUND, 40 AUDIO_MODE_DITHER 41 }; 42 43 struct audio_stats { 44 unsigned long clipped_samples; 45 mad_fixed_t peak_clipping; 46 mad_fixed_t peak_sample; 47 }; 48 49 union audio_control { 50 enum audio_command command; 51 52 struct audio_init { 53 enum audio_command command; 54 char const *path; 55 } init; 56 57 struct audio_config { 58 enum audio_command command; 59 unsigned int channels; 60 unsigned int speed; 61 unsigned int precision; 62 } config; 63 64 struct audio_play { 65 enum audio_command command; 66 unsigned int nsamples; 67 mad_fixed_t const *samples[2]; 68 enum audio_mode mode; 69 struct audio_stats *stats; 70 } play; 71 72 struct audio_stop { 73 enum audio_command command; 74 int flush; 75 } stop; 76 77 struct audio_finish { 78 enum audio_command command; 79 } finish; 80 }; 81 82 struct audio_dither { 83 mad_fixed_t error[3]; 84 mad_fixed_t random; 85 }; 86 87 extern char const *audio_error; 88 89 typedef int audio_ctlfunc_t(union audio_control *); 90 91 audio_ctlfunc_t *audio_output(char const **); 92 93 audio_ctlfunc_t audio_alsa; 94 audio_ctlfunc_t audio_carbon; 95 audio_ctlfunc_t audio_empeg; 96 audio_ctlfunc_t audio_esd; 97 audio_ctlfunc_t audio_jaguar; 98 audio_ctlfunc_t audio_nas; 99 audio_ctlfunc_t audio_oss; 100 audio_ctlfunc_t audio_qnx; 101 audio_ctlfunc_t audio_sndio; 102 audio_ctlfunc_t audio_sun; 103 audio_ctlfunc_t audio_win32; 104 105 audio_ctlfunc_t audio_aiff; 106 audio_ctlfunc_t audio_cdda; 107 audio_ctlfunc_t audio_hex; 108 audio_ctlfunc_t audio_null; 109 audio_ctlfunc_t audio_raw; 110 audio_ctlfunc_t audio_snd; 111 audio_ctlfunc_t audio_wave; 112 113 void audio_control_init(union audio_control *, enum audio_command); 114 115 signed long audio_linear_round(unsigned int, mad_fixed_t, 116 struct audio_stats *); 117 signed long audio_linear_dither(unsigned int, mad_fixed_t, 118 struct audio_dither *, struct audio_stats *); 119 120 unsigned char audio_mulaw_round(mad_fixed_t, struct audio_stats *); 121 unsigned char audio_mulaw_dither(mad_fixed_t, struct audio_dither *, 122 struct audio_stats *); 123 124 typedef unsigned int audio_pcmfunc_t(unsigned char *, unsigned int, 125 mad_fixed_t const *, mad_fixed_t const *, 126 enum audio_mode, struct audio_stats *); 127 128 audio_pcmfunc_t audio_pcm_u8; 129 130 audio_pcmfunc_t audio_pcm_s8; 131 audio_pcmfunc_t audio_pcm_s16le; 132 audio_pcmfunc_t audio_pcm_s16be; 133 audio_pcmfunc_t audio_pcm_s24le; 134 audio_pcmfunc_t audio_pcm_s24be; 135 audio_pcmfunc_t audio_pcm_s32le; 136 audio_pcmfunc_t audio_pcm_s32be; 137 138 audio_pcmfunc_t audio_pcm_mulaw; 139 140 # endif 141