Replace all direct accesses to audiobuf with buffer API functions.
[kugel-rb.git] / firmware / export / audio.h
blob6757bf143bd778cd760f83d560d153cdf44eac6d
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 <string.h> /* size_t */
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 */
38 #define AUDIO_STATUS_PLAY 0x0001
39 #define AUDIO_STATUS_PAUSE 0x0002
40 #define AUDIO_STATUS_RECORD 0x0004
41 #define AUDIO_STATUS_PRERECORD 0x0008
42 #define AUDIO_STATUS_ERROR 0x0010
43 #define AUDIO_STATUS_WARNING 0x0020
45 #define AUDIOERR_DISK_FULL 1
47 #define AUDIO_GAIN_LINEIN 0
48 #define AUDIO_GAIN_MIC 1
51 void audio_init(void) INIT_ATTR;
52 void audio_play(long offset);
53 void audio_stop(void);
54 /* Stops audio from serving playback and frees resources*/
55 void audio_hard_stop(void);
56 void audio_pause(void);
57 void audio_resume(void);
58 void audio_next(void);
59 void audio_prev(void);
60 int audio_status(void);
61 void audio_ff_rewind(long newpos);
62 void audio_flush_and_reload_tracks(void);
63 struct mp3entry* audio_current_track(void);
64 struct mp3entry* audio_next_track(void);
65 bool audio_peek_track(struct mp3entry* id3, int offset);
66 #ifdef HAVE_DISK_STORAGE
67 void audio_set_buffer_margin(int setting);
68 #endif
69 void audio_error_clear(void);
70 int audio_get_file_pos(void);
71 void audio_beep(int duration);
73 /* Required call when audio buffer is required for some other purpose */
74 /* implemented in apps but called from firmware(!) */
75 unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size);
77 #if CONFIG_CODEC == SWCODEC
78 void audio_next_dir(void);
79 void audio_prev_dir(void);
81 #else /* hwcodec only */
82 struct audio_debug
84 int audiobuflen;
85 int audiobuf_write;
86 int audiobuf_swapwrite;
87 int audiobuf_read;
89 int last_dma_chunk_size;
91 bool dma_on;
92 bool playing;
93 bool play_pending;
94 bool is_playing;
95 bool filling;
96 bool dma_underrun;
98 int unplayed_space;
99 int playable_space;
100 int unswapped_space;
102 int low_watermark_level;
103 int lowest_watermark_level;
106 void audio_get_debugdata(struct audio_debug *dbgdata);
107 /* unsigned int audio_error(void); - unused function */
108 void audio_init_playback(void);
110 #define audio_next_dir() ({ })
111 #define audio_prev_dir() ({ })
113 #endif
115 /* channel modes */
116 enum rec_channel_modes
118 __CHN_MODE_START_INDEX = -1,
120 CHN_MODE_STEREO,
121 CHN_MODE_MONO,
123 CHN_NUM_MODES
126 #if CONFIG_CODEC == SWCODEC
127 /* channel mode capability bits */
128 #define CHN_CAP_STEREO (1 << CHN_MODE_STEREO)
129 #define CHN_CAP_MONO (1 << CHN_MODE_MONO)
130 #define CHN_CAP_ALL (CHN_CAP_STEREO | CHN_CAP_MONO)
131 #endif /* CONFIG_CODEC == SWCODEC */
133 /* the enums below must match prestr[] in recording.c */
134 enum audio_sources
136 AUDIO_SRC_PLAYBACK = -1, /* Virtual source */
137 HAVE_MIC_IN_(AUDIO_SRC_MIC,)
138 HAVE_LINE_IN_(AUDIO_SRC_LINEIN,)
139 HAVE_SPDIF_IN_(AUDIO_SRC_SPDIF,)
140 HAVE_FMRADIO_IN_(AUDIO_SRC_FMRADIO,)
141 AUDIO_NUM_SOURCES,
142 AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1,
143 AUDIO_SRC_DEFAULT = AUDIO_SRC_PLAYBACK
146 extern int audio_channels;
147 extern int audio_output_source;
149 #ifdef HAVE_RECORDING
150 /* Recordable source implies it has the input as well */
152 /* For now there's no restrictions on any targets with which inputs
153 are recordable so define them as equivalent - if they do differ,
154 special handling is needed right now. */
155 enum rec_sources
157 __REC_SRC_FIRST = -1,
158 HAVE_MIC_REC_(REC_SRC_MIC,)
159 HAVE_LINE_REC_(REC_SRC_LINEIN,)
160 HAVE_SPDIF_REC_(REC_SRC_SPDIF,)
161 HAVE_FMRADIO_REC_(REC_SRC_FMRADIO,)
162 REC_NUM_SOURCES
164 #endif /* HAVE_RECORDING */
166 #if CONFIG_CODEC == SWCODEC
167 /* selects a source to monitor for recording or playback */
168 #define SRCF_PLAYBACK 0x0000 /* default */
169 #define SRCF_RECORDING 0x1000
170 #if CONFIG_TUNER
171 /* for AUDIO_SRC_FMRADIO */
172 #define SRCF_FMRADIO_PLAYING 0x0000 /* default */
173 #define SRCF_FMRADIO_PAUSED 0x2000
174 #endif
175 #endif
177 #ifdef HAVE_RECORDING
178 /* parameters for audio_set_recording_options */
179 struct audio_recording_options
181 int rec_source;
182 int rec_frequency;
183 int rec_channels;
184 int rec_prerecord_time;
185 #if CONFIG_CODEC == SWCODEC
186 int rec_mono_mode;
187 int rec_source_flags; /* for rec_set_source */
188 struct encoder_config enc_config;
189 #else
190 int rec_quality;
191 bool rec_editable;
192 #endif
195 /* audio recording functions */
196 void audio_init_recording(unsigned int buffer_offset);
197 void audio_close_recording(void);
198 void audio_record(const char *filename);
199 void audio_stop_recording(void);
200 void audio_pause_recording(void);
201 void audio_resume_recording(void);
202 void audio_new_file(const char *filename);
203 void audio_set_recording_options(struct audio_recording_options *options);
204 void audio_set_recording_gain(int left, int right, int type);
205 unsigned long audio_recorded_time(void);
206 unsigned long audio_num_recorded_bytes(void);
208 #if CONFIG_CODEC == SWCODEC
209 /* SWCODEC recording functions */
210 /* playback.c */
211 bool audio_load_encoder(int afmt);
212 void audio_remove_encoder(void);
213 unsigned char *audio_get_recording_buffer(size_t *buffer_size);
214 #endif /* CONFIG_CODEC == SWCODEC */
216 #endif /* HAVE_RECORDING */
218 #if CONFIG_CODEC == SWCODEC
219 /* SWCODEC misc. audio functions */
220 #if INPUT_SRC_CAPS != 0
221 /* audio.c */
222 void audio_set_input_source(int source, unsigned flags);
223 /* audio_input_mux: target-specific implementation used by audio_set_source
224 to set hardware inputs and audio paths */
225 void audio_input_mux(int source, unsigned flags);
226 void audio_set_output_source(int source);
227 #endif /* INPUT_SRC_CAPS */
228 #endif /* CONFIG_CODEC == SWCODEC */
230 #ifdef HAVE_SPDIF_IN
231 /* returns index into rec_master_sampr_list */
232 int audio_get_spdif_sample_rate(void);
233 /* > 0: monitor EBUin, 0: Monitor IISrecv, <0: reset only */
234 void audio_spdif_set_monitor(int monitor_spdif);
235 #endif /* HAVE_SPDIF_IN */
237 unsigned long audio_prev_elapsed(void);
239 #if CONFIG_CODEC != SWCODEC
240 /***********************************************************************/
241 /* audio event handling */
243 /* subscribe to one or more audio event(s) by OR'ing together the desired */
244 /* event IDs (defined below); a handler is called with a solitary event ID */
245 /* (so switch() is okay) and possibly some useful data (depending on the */
246 /* event); a handler must return one of the return codes defined below */
248 typedef int (*AUDIO_EVENT_HANDLER)(unsigned short event, unsigned long data);
250 void audio_register_event_handler(AUDIO_EVENT_HANDLER handler, unsigned short mask);
252 /***********************************************************************/
253 /* handler return codes */
255 #define AUDIO_EVENT_RC_IGNORED 200
256 /* indicates that no action was taken or the event was not recognized */
258 #define AUDIO_EVENT_RC_HANDLED 201
259 /* indicates that the event was handled and some action was taken which renders
260 the original event invalid; USE WITH CARE!; this return code aborts all further
261 processing of the given event */
263 /***********************************************************************/
264 /* audio event IDs */
266 #define AUDIO_EVENT_POS_REPORT (1<<0)
267 /* sends a periodic song position report to handlers; a report is sent on
268 each kernal tick; the number of ticks per second is defined by HZ; on each
269 report the current song position is passed in 'data'; if a handler takes an
270 action that changes the song or the song position it must return
271 AUDIO_EVENT_RC_HANDLED which suppresses the event for any remaining handlers */
273 #define AUDIO_EVENT_END_OF_TRACK (1<<1)
274 /* generated when the end of the currently playing track is reached; no
275 data is passed; if the handler implements some alternate end-of-track
276 processing it should return AUDIO_EVENT_RC_HANDLED which suppresses the
277 event for any remaining handlers as well as the normal end-of-track
278 processing */
280 #endif
281 #endif