D2: Fix IRAM usage, but disable it for now as Tremor does not fit ('make zip' works...
[Rockbox.git] / firmware / export / audio.h
blobc39fca428c51600ba04741e5e238d3847df2ca5c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #ifndef AUDIO_H
20 #define AUDIO_H
22 #include <stdbool.h>
23 #include <sys/types.h>
24 /* These must always be included with audio.h for this to compile under
25 cetain conditions. Do it here or else spread the complication around to
26 many files. */
27 #if CONFIG_CODEC == SWCODEC
28 #include "pcm_sampr.h"
29 #include "pcm.h"
30 #ifdef HAVE_RECORDING
31 #include "pcm_record.h"
32 #include "id3.h"
33 #include "enc_base.h"
34 #endif /* HAVE_RECORDING */
35 #endif /* CONFIG_CODEC == SWCODEC */
38 #ifdef SIMULATOR
39 #define audio_play(x) sim_audio_play(x)
40 #endif
42 #define AUDIO_STATUS_PLAY 0x0001
43 #define AUDIO_STATUS_PAUSE 0x0002
44 #define AUDIO_STATUS_RECORD 0x0004
45 #define AUDIO_STATUS_PRERECORD 0x0008
46 #define AUDIO_STATUS_ERROR 0x0010
47 #define AUDIO_STATUS_WARNING 0x0020
49 #define AUDIOERR_DISK_FULL 1
51 #define AUDIO_GAIN_LINEIN 0
52 #define AUDIO_GAIN_MIC 1
55 struct audio_debug
57 int audiobuflen;
58 int audiobuf_write;
59 int audiobuf_swapwrite;
60 int audiobuf_read;
62 int last_dma_chunk_size;
64 bool dma_on;
65 bool playing;
66 bool play_pending;
67 bool is_playing;
68 bool filling;
69 bool dma_underrun;
71 int unplayed_space;
72 int playable_space;
73 int unswapped_space;
75 int low_watermark_level;
76 int lowest_watermark_level;
79 void audio_init(void);
80 void audio_wait_for_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 #if CONFIG_CODEC == SWCODEC
89 int audio_track_count(void); /* SWCODEC only */
90 long audio_filebufused(void); /* SWCODEC only */
91 void audio_pre_ff_rewind(void); /* SWCODEC only */
92 #endif /* CONFIG_CODEC == SWCODEC */
93 void audio_ff_rewind(long newtime);
94 void audio_flush_and_reload_tracks(void);
95 #ifdef HAVE_ALBUMART
96 int audio_current_aa_hid(void);
97 #endif
98 struct mp3entry* audio_current_track(void);
99 struct mp3entry* audio_next_track(void);
100 bool audio_has_changed_track(void);
101 void audio_get_debugdata(struct audio_debug *dbgdata);
102 void audio_set_crossfade(int type);
103 #ifndef HAVE_FLASH_STORAGE
104 void audio_set_buffer_margin(int seconds);
105 #endif
106 unsigned int audio_error(void);
107 void audio_error_clear(void);
108 int audio_get_file_pos(void);
109 void audio_beep(int duration);
110 void audio_init_playback(void);
111 /* Required call when audio buffer is require for some other purpose */
112 unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size);
113 /* Stops audio from serving playback */
114 void audio_hard_stop(void);
115 /* Retores the audio buffer to handle the requested playback */
116 enum
118 AUDIO_WANT_PLAYBACK = 0,
119 AUDIO_WANT_VOICE,
122 bool audio_restore_playback(int type);
124 /* channel modes */
125 enum rec_channel_modes
127 __CHN_MODE_START_INDEX = -1,
129 CHN_MODE_STEREO,
130 CHN_MODE_MONO,
132 CHN_NUM_MODES
135 #if CONFIG_CODEC == SWCODEC
136 /* channel mode capability bits */
137 #define CHN_CAP_STEREO (1 << CHN_MODE_STEREO)
138 #define CHN_CAP_MONO (1 << CHN_MODE_MONO)
139 #define CHN_CAP_ALL (CHN_CAP_STEREO | CHN_CAP_MONO)
140 #endif /* CONFIG_CODEC == SWCODEC */
142 /* the enums below must match prestr[] in recording.c */
143 enum audio_sources
145 AUDIO_SRC_PLAYBACK = -1, /* Virtual source */
146 HAVE_MIC_IN_(AUDIO_SRC_MIC,)
147 HAVE_LINE_IN_(AUDIO_SRC_LINEIN,)
148 HAVE_SPDIF_IN_(AUDIO_SRC_SPDIF,)
149 HAVE_FMRADIO_IN_(AUDIO_SRC_FMRADIO,)
150 AUDIO_NUM_SOURCES,
151 AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1,
152 AUDIO_SRC_DEFAULT = AUDIO_SRC_PLAYBACK
155 extern int audio_channels;
156 extern int audio_output_source;
158 #ifdef HAVE_RECORDING
159 /* Recordable source implies it has the input as well */
161 /* For now there's no restrictions on any targets with which inputs
162 are recordable so define them as equivalent - if they do differ,
163 special handling is needed right now. */
164 enum rec_sources
166 __REC_SRC_FIRST = -1,
167 HAVE_MIC_REC_(REC_SRC_MIC,)
168 HAVE_LINE_REC_(REC_SRC_LINEIN,)
169 HAVE_SPDIF_REC_(REC_SRC_SPDIF,)
170 HAVE_FMRADIO_REC_(REC_SRC_FMRADIO,)
171 REC_NUM_SOURCES
173 #endif /* HAVE_RECORDING */
175 #if CONFIG_CODEC == SWCODEC
176 /* selects a source to monitor for recording or playback */
177 #define SRCF_PLAYBACK 0x0000 /* default */
178 #define SRCF_RECORDING 0x1000
179 #if CONFIG_TUNER
180 /* for AUDIO_SRC_FMRADIO */
181 #define SRCF_FMRADIO_PLAYING 0x0000 /* default */
182 #define SRCF_FMRADIO_PAUSED 0x2000
183 #endif
184 #endif
186 #ifdef HAVE_RECORDING
187 /* parameters for audio_set_recording_options */
188 struct audio_recording_options
190 int rec_source;
191 int rec_frequency;
192 int rec_channels;
193 int rec_prerecord_time;
194 #if CONFIG_CODEC == SWCODEC
195 int rec_source_flags; /* for rec_set_source */
196 struct encoder_config enc_config;
197 #else
198 int rec_quality;
199 bool rec_editable;
200 #endif
203 /* audio recording functions */
204 void audio_init_recording(unsigned int buffer_offset);
205 void audio_close_recording(void);
206 void audio_record(const char *filename);
207 void audio_stop_recording(void);
208 void audio_pause_recording(void);
209 void audio_resume_recording(void);
210 void audio_new_file(const char *filename);
211 void audio_set_recording_options(struct audio_recording_options *options);
212 void audio_set_recording_gain(int left, int right, int type);
213 unsigned long audio_recorded_time(void);
214 unsigned long audio_num_recorded_bytes(void);
216 #if CONFIG_CODEC == SWCODEC
217 /* SWCODEC recoring functions */
218 /* playback.c */
219 bool audio_load_encoder(int afmt);
220 void audio_remove_encoder(void);
221 unsigned char *audio_get_recording_buffer(size_t *buffer_size);
222 #endif /* CONFIG_CODEC == SWCODEC */
224 #endif /* HAVE_RECORDING */
226 #if CONFIG_CODEC == SWCODEC
227 /* SWCODEC misc. audio functions */
228 #if INPUT_SRC_CAPS != 0
229 /* audio.c */
230 void audio_set_input_source(int source, unsigned flags);
231 /* audio_input_mux: target-specific implementation used by audio_set_source
232 to set hardware inputs and audio paths */
233 void audio_input_mux(int source, unsigned flags);
234 void audio_set_output_source(int source);
235 #endif /* INPUT_SRC_CAPS */
236 #endif /* CONFIG_CODEC == SWCODEC */
238 #ifdef HAVE_SPDIF_IN
239 /* returns index into rec_master_sampr_list */
240 int audio_get_spdif_sample_rate(void);
241 /* > 0: monitor EBUin, 0: Monitor IISrecv, <0: reset only */
242 void audio_spdif_set_monitor(int monitor_spdif);
243 #endif /* HAVE_SPDIF_IN */
245 unsigned long audio_prev_elapsed(void);
248 /***********************************************************************/
249 /* audio event handling */
251 /* subscribe to one or more audio event(s) by OR'ing together the desired */
252 /* event IDs (defined below); a handler is called with a solitary event ID */
253 /* (so switch() is okay) and possibly some useful data (depending on the */
254 /* event); a handler must return one of the return codes defined below */
256 typedef int (*AUDIO_EVENT_HANDLER)(unsigned short event, unsigned long data);
258 void audio_register_event_handler(AUDIO_EVENT_HANDLER handler, unsigned short mask);
260 /***********************************************************************/
261 /* handler return codes */
263 #define AUDIO_EVENT_RC_IGNORED 200
264 /* indicates that no action was taken or the event was not recognized */
266 #define AUDIO_EVENT_RC_HANDLED 201
267 /* indicates that the event was handled and some action was taken which renders
268 the original event invalid; USE WITH CARE!; this return code aborts all further
269 processing of the given event */
271 /***********************************************************************/
272 /* audio event IDs */
274 #define AUDIO_EVENT_POS_REPORT (1<<0)
275 /* sends a periodic song position report to handlers; a report is sent on
276 each kernal tick; the number of ticks per second is defined by HZ; on each
277 report the current song position is passed in 'data'; if a handler takes an
278 action that changes the song or the song position it must return
279 AUDIO_EVENT_RC_HANDLED which suppresses the event for any remaining handlers */
281 #define AUDIO_EVENT_END_OF_TRACK (1<<1)
282 /* generated when the end of the currently playing track is reached; no
283 data is passed; if the handler implements some alternate end-of-track
284 processing it should return AUDIO_EVENT_RC_HANDLED which suppresses the
285 event for any remaining handlers as well as the normal end-of-track
286 processing */
288 #endif