summaryrefslogtreecommitdiff
path: root/audio.h
blob: c22a768f22b18c9da215cea2d92a5487bb845093 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * madplay - MPEG audio decoder and player
 * Copyright (C) 2000-2004 Robert Leslie
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: audio.h,v 1.38 2004/01/23 09:41:31 rob Exp $
 */

# ifndef AUDIO_H
# define AUDIO_H

# include <mad.h>

# define MAX_RESAMPLEFACTOR	6
# define MAX_NSAMPLES		(1152 * MAX_RESAMPLEFACTOR)

enum audio_command {
  AUDIO_COMMAND_INIT,
  AUDIO_COMMAND_CONFIG,
  AUDIO_COMMAND_PLAY,
  AUDIO_COMMAND_STOP,
  AUDIO_COMMAND_FINISH
};

enum audio_mode {
  AUDIO_MODE_ROUND,
  AUDIO_MODE_DITHER
};

struct audio_stats {
  unsigned long clipped_samples;
  mad_fixed_t peak_clipping;
  mad_fixed_t peak_sample;
};

union audio_control {
  enum audio_command command;

  struct audio_init {
    enum audio_command command;
    char const *path;
  } init;

  struct audio_config {
    enum audio_command command;
    unsigned int channels;
    unsigned int speed;
    unsigned int precision;
  } config;

  struct audio_play {
    enum audio_command command;
    unsigned int nsamples;
    mad_fixed_t const *samples[2];
    enum audio_mode mode;
    struct audio_stats *stats;
  } play;

  struct audio_stop {
    enum audio_command command;
    int flush;
  } stop;

  struct audio_finish {
    enum audio_command command;
  } finish;
};

struct audio_dither {
  mad_fixed_t error[3];
  mad_fixed_t random;
};

extern char const *audio_error;

typedef int audio_ctlfunc_t(union audio_control *);

audio_ctlfunc_t *audio_output(char const **);

audio_ctlfunc_t audio_alsa;
audio_ctlfunc_t audio_carbon;
audio_ctlfunc_t audio_empeg;
audio_ctlfunc_t audio_esd;
audio_ctlfunc_t audio_jaguar;
audio_ctlfunc_t audio_nas;
audio_ctlfunc_t audio_oss;
audio_ctlfunc_t audio_qnx;
audio_ctlfunc_t audio_sun;
audio_ctlfunc_t audio_win32;

audio_ctlfunc_t audio_aiff;
audio_ctlfunc_t audio_cdda;
audio_ctlfunc_t audio_hex;
audio_ctlfunc_t audio_null;
audio_ctlfunc_t audio_raw;
audio_ctlfunc_t audio_snd;
audio_ctlfunc_t audio_wave;

void audio_control_init(union audio_control *, enum audio_command);

signed long audio_linear_round(unsigned int, mad_fixed_t,
			       struct audio_stats *);
signed long audio_linear_dither(unsigned int, mad_fixed_t,
				struct audio_dither *, struct audio_stats *);

unsigned char audio_mulaw_round(mad_fixed_t, struct audio_stats *);
unsigned char audio_mulaw_dither(mad_fixed_t, struct audio_dither *,
				 struct audio_stats *);

typedef unsigned int audio_pcmfunc_t(unsigned char *, unsigned int,
				     mad_fixed_t const *, mad_fixed_t const *,
				     enum audio_mode, struct audio_stats *);

audio_pcmfunc_t audio_pcm_u8;

audio_pcmfunc_t audio_pcm_s8;
audio_pcmfunc_t audio_pcm_s16le;
audio_pcmfunc_t audio_pcm_s16be;
audio_pcmfunc_t audio_pcm_s24le;
audio_pcmfunc_t audio_pcm_s24be;
audio_pcmfunc_t audio_pcm_s32le;
audio_pcmfunc_t audio_pcm_s32be;

audio_pcmfunc_t audio_pcm_mulaw;

# endif