Support building beastpatcher with MinGW.
[kugel-rb.git] / firmware / export / audio.h
blob6236c6d5d1e03887907c66fac82308119fe56f22
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef AUDIO_H
22 #define AUDIO_H
24 #include <stdbool.h>
25 #include <sys/types.h>
26 #include "config.h"
27 /* These must always be included with audio.h for this to compile under
28 cetain conditions. Do it here or else spread the complication around to
29 many files. */
30 #if CONFIG_CODEC == SWCODEC
31 #include "pcm_sampr.h"
32 #include "pcm.h"
33 #ifdef HAVE_RECORDING
34 #include "enc_base.h"
35 #endif /* HAVE_RECORDING */
36 #endif /* CONFIG_CODEC == SWCODEC */
39 #ifdef SIMULATOR
40 #define audio_play(x) sim_audio_play(x)
41 #endif
43 #define AUDIO_STATUS_PLAY 0x0001
44 #define AUDIO_STATUS_PAUSE 0x0002
45 #define AUDIO_STATUS_RECORD 0x0004
46 #define AUDIO_STATUS_PRERECORD 0x0008
47 #define AUDIO_STATUS_ERROR 0x0010
48 #define AUDIO_STATUS_WARNING 0x0020
50 #define AUDIOERR_DISK_FULL 1
52 #define AUDIO_GAIN_LINEIN 0
53 #define AUDIO_GAIN_MIC 1
56 struct audio_debug
58 int audiobuflen;
59 int audiobuf_write;
60 int audiobuf_swapwrite;
61 int audiobuf_read;
63 int last_dma_chunk_size;
65 bool dma_on;
66 bool playing;
67 bool play_pending;
68 bool is_playing;
69 bool filling;
70 bool dma_underrun;
72 int unplayed_space;
73 int playable_space;
74 int unswapped_space;
76 int low_watermark_level;
77 int lowest_watermark_level;
80 void audio_init(void);
81 void audio_play(long offset);
82 void audio_stop(void);
83 void audio_pause(void);
84 void audio_resume(void);
85 void audio_next(void);
86 void audio_prev(void);
87 int audio_status(void);
88 void audio_ff_rewind(long newtime);
89 void audio_flush_and_reload_tracks(void);
90 struct mp3entry* audio_current_track(void);
91 struct mp3entry* audio_next_track(void);
92 void audio_get_debugdata(struct audio_debug *dbgdata);
93 #ifdef HAVE_DISK_STORAGE
94 void audio_set_buffer_margin(int seconds);
95 #endif
96 unsigned int audio_error(void);
97 void audio_error_clear(void);
98 int audio_get_file_pos(void);
99 void audio_beep(int duration);
100 void audio_init_playback(void);
102 /* Required call when audio buffer is required for some other purpose */
103 unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size);
104 /* only implemented in playback.c, but called from firmware */
106 #if CONFIG_CODEC == SWCODEC
107 enum audio_buffer_state
109 AUDIOBUF_STATE_TRASHED = -1, /* trashed; must be reset */
110 AUDIOBUF_STATE_INITIALIZED = 0, /* voice+audio OR audio-only */
111 AUDIOBUF_STATE_VOICED_ONLY = 1, /* voice-only */
113 int audio_buffer_state(void);
114 #endif
116 /* channel modes */
117 enum rec_channel_modes
119 __CHN_MODE_START_INDEX = -1,
121 CHN_MODE_STEREO,
122 CHN_MODE_MONO,
124 CHN_NUM_MODES
127 #if CONFIG_CODEC == SWCODEC
128 /* channel mode capability bits */
129 #define CHN_CAP_STEREO (1 << CHN_MODE_STEREO)
130 #define CHN_CAP_MONO (1 << CHN_MODE_MONO)
131 #define CHN_CAP_ALL (CHN_CAP_STEREO | CHN_CAP_MONO)
132 #endif /* CONFIG_CODEC == SWCODEC */
134 /* the enums below must match prestr[] in recording.c */
135 enum audio_sources
137 AUDIO_SRC_PLAYBACK = -1, /* Virtual source */
138 HAVE_MIC_IN_(AUDIO_SRC_MIC,)
139 HAVE_LINE_IN_(AUDIO_SRC_LINEIN,)
140 HAVE_SPDIF_IN_(AUDIO_SRC_SPDIF,)
141 HAVE_FMRADIO_IN_(AUDIO_SRC_FMRADIO,)
142 AUDIO_NUM_SOURCES,
143 AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1,
144 AUDIO_SRC_DEFAULT = AUDIO_SRC_PLAYBACK
147 extern int audio_channels;
148 extern int audio_output_source;
150 #ifdef HAVE_RECORDING
151 /* Recordable source implies it has the input as well */
153 /* For now there's no restrictions on any targets with which inputs
154 are recordable so define them as equivalent - if they do differ,
155 special handling is needed right now. */
156 enum rec_sources
158 __REC_SRC_FIRST = -1,
159 HAVE_MIC_REC_(REC_SRC_MIC,)
160 HAVE_LINE_REC_(REC_SRC_LINEIN,)
161 HAVE_SPDIF_REC_(REC_SRC_SPDIF,)
162 HAVE_FMRADIO_REC_(REC_SRC_FMRADIO,)
163 REC_NUM_SOURCES
165 #endif /* HAVE_RECORDING */
167 #if CONFIG_CODEC == SWCODEC
168 /* selects a source to monitor for recording or playback */
169 #define SRCF_PLAYBACK 0x0000 /* default */
170 #define SRCF_RECORDING 0x1000
171 #if CONFIG_TUNER
172 /* for AUDIO_SRC_FMRADIO */
173 #define SRCF_FMRADIO_PLAYING 0x0000 /* default */
174 #define SRCF_FMRADIO_PAUSED 0x2000
175 #endif
176 #endif
178 #ifdef HAVE_RECORDING
179 /* parameters for audio_set_recording_options */
180 struct audio_recording_options
182 int rec_source;
183 int rec_frequency;
184 int rec_channels;
185 int rec_prerecord_time;
186 #if CONFIG_CODEC == SWCODEC
187 int rec_mono_mode;
188 int rec_source_flags; /* for rec_set_source */
189 struct encoder_config enc_config;
190 #else
191 int rec_quality;
192 bool rec_editable;
193 #endif
196 /* audio recording functions */
197 void audio_init_recording(unsigned int buffer_offset);
198 void audio_close_recording(void);
199 void audio_record(const char *filename);
200 void audio_stop_recording(void);
201 void audio_pause_recording(void);
202 void audio_resume_recording(void);
203 void audio_new_file(const char *filename);
204 void audio_set_recording_options(struct audio_recording_options *options);
205 void audio_set_recording_gain(int left, int right, int type);
206 unsigned long audio_recorded_time(void);
207 unsigned long audio_num_recorded_bytes(void);
209 #if CONFIG_CODEC == SWCODEC
210 /* SWCODEC recording functions */
211 /* playback.c */
212 bool audio_load_encoder(int afmt);
213 void audio_remove_encoder(void);
214 unsigned char *audio_get_recording_buffer(size_t *buffer_size);
215 #endif /* CONFIG_CODEC == SWCODEC */
217 #endif /* HAVE_RECORDING */
219 #if CONFIG_CODEC == SWCODEC
220 /* SWCODEC misc. audio functions */
221 #if INPUT_SRC_CAPS != 0
222 /* audio.c */
223 void audio_set_input_source(int source, unsigned flags);
224 /* audio_input_mux: target-specific implementation used by audio_set_source
225 to set hardware inputs and audio paths */
226 void audio_input_mux(int source, unsigned flags);
227 void audio_set_output_source(int source);
228 #endif /* INPUT_SRC_CAPS */
229 #endif /* CONFIG_CODEC == SWCODEC */
231 #ifdef HAVE_SPDIF_IN
232 /* returns index into rec_master_sampr_list */
233 int audio_get_spdif_sample_rate(void);
234 /* > 0: monitor EBUin, 0: Monitor IISrecv, <0: reset only */
235 void audio_spdif_set_monitor(int monitor_spdif);
236 #endif /* HAVE_SPDIF_IN */
238 unsigned long audio_prev_elapsed(void);
241 /***********************************************************************/
242 /* audio event handling */
244 /* subscribe to one or more audio event(s) by OR'ing together the desired */
245 /* event IDs (defined below); a handler is called with a solitary event ID */
246 /* (so switch() is okay) and possibly some useful data (depending on the */
247 /* event); a handler must return one of the return codes defined below */
249 typedef int (*AUDIO_EVENT_HANDLER)(unsigned short event, unsigned long data);
251 void audio_register_event_handler(AUDIO_EVENT_HANDLER handler, unsigned short mask);
253 /***********************************************************************/
254 /* handler return codes */
256 #define AUDIO_EVENT_RC_IGNORED 200
257 /* indicates that no action was taken or the event was not recognized */
259 #define AUDIO_EVENT_RC_HANDLED 201
260 /* indicates that the event was handled and some action was taken which renders
261 the original event invalid; USE WITH CARE!; this return code aborts all further
262 processing of the given event */
264 /***********************************************************************/
265 /* audio event IDs */
267 #define AUDIO_EVENT_POS_REPORT (1<<0)
268 /* sends a periodic song position report to handlers; a report is sent on
269 each kernal tick; the number of ticks per second is defined by HZ; on each
270 report the current song position is passed in 'data'; if a handler takes an
271 action that changes the song or the song position it must return
272 AUDIO_EVENT_RC_HANDLED which suppresses the event for any remaining handlers */
274 #define AUDIO_EVENT_END_OF_TRACK (1<<1)
275 /* generated when the end of the currently playing track is reached; no
276 data is passed; if the handler implements some alternate end-of-track
277 processing it should return AUDIO_EVENT_RC_HANDLED which suppresses the
278 event for any remaining handlers as well as the normal end-of-track
279 processing */
281 #endif