Reload the current playlist after reboot even if it has ended. (FS#11644)
[kugel-rb.git] / firmware / export / pcm.h
blob22c5ef350ef5eee627e3193edb679cd30288806a
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 PCM_PLAYBACK_H
22 #define PCM_PLAYBACK_H
24 #include <string.h> /* size_t */
26 #define DMA_REC_ERROR_DMA (-1)
27 #ifdef HAVE_SPDIF_REC
28 #define DMA_REC_ERROR_SPDIF (-2)
29 #endif
31 /** Warnings **/
32 /* pcm (dma) buffer has overflowed */
33 #define PCMREC_W_PCM_BUFFER_OVF 0x00000001
34 /* encoder output buffer has overflowed */
35 #define PCMREC_W_ENC_BUFFER_OVF 0x00000002
36 /** Errors **/
37 /* failed to load encoder */
38 #define PCMREC_E_LOAD_ENCODER 0x80001000
39 /* error originating in encoder */
40 #define PCMREC_E_ENCODER 0x80002000
41 /* filename queue has desynced from stream markers */
42 #define PCMREC_E_FNQ_DESYNC 0x80004000
43 /* I/O error has occurred */
44 #define PCMREC_E_IO 0x80008000
45 #ifdef DEBUG
46 /* encoder has written past end of allocated space */
47 #define PCMREC_E_CHUNK_OVF 0x80010000
48 #endif /* DEBUG */
50 /** RAW PCM routines used with playback and recording **/
52 /* Typedef for registered callbacks */
53 typedef void (*pcm_play_callback_type)(unsigned char **start,
54 size_t *size);
55 typedef void (*pcm_rec_callback_type)(int status, void **start, size_t *size);
57 /* set the pcm frequency - use values in hw_sampr_list
58 * when CONFIG_SAMPR_TYPES is #defined, or-in SAMPR_TYPE_* fields with
59 * frequency value. SAMPR_TYPE_PLAY is 0 and the default if none is
60 * specified. */
61 #ifdef CONFIG_SAMPR_TYPES
62 #ifdef SAMPR_TYPE_REC
63 unsigned int pcm_sampr_type_rec_to_play(unsigned int samplerate);
64 #endif
65 #endif /* CONFIG_SAMPR_TYPES */
67 void pcm_set_frequency(unsigned int samplerate);
68 /* apply settings to hardware immediately */
69 void pcm_apply_settings(void);
71 /** RAW PCM playback routines **/
73 /* Reenterable locks for locking and unlocking the playback interrupt */
74 void pcm_play_lock(void);
75 void pcm_play_unlock(void);
77 void pcm_init(void) INIT_ATTR;
78 void pcm_postinit(void);
80 /* This is for playing "raw" PCM data */
81 void pcm_play_data(pcm_play_callback_type get_more,
82 unsigned char* start, size_t size);
84 void pcm_calculate_peaks(int *left, int *right);
85 const void* pcm_get_peak_buffer(int* count);
86 size_t pcm_get_bytes_waiting(void);
88 void pcm_play_stop(void);
89 void pcm_play_pause(bool play);
90 bool pcm_is_paused(void);
91 bool pcm_is_playing(void);
93 void pcm_play_set_dma_started_callback(void (* callback)(void));
95 #ifdef HAVE_RECORDING
97 /** RAW PCM recording routines **/
99 /* Reenterable locks for locking and unlocking the recording interrupt */
100 void pcm_rec_lock(void);
101 void pcm_rec_unlock(void);
103 /* Initialize pcm recording interface */
104 void pcm_init_recording(void);
105 /* Uninitialize pcm recording interface */
106 void pcm_close_recording(void);
108 /* Start recording "raw" PCM data */
109 void pcm_record_data(pcm_rec_callback_type more_ready,
110 void *start, size_t size);
112 /* Stop tranferring data into supplied buffer */
113 void pcm_stop_recording(void);
115 /* Is pcm currently recording? */
116 bool pcm_is_recording(void);
118 /* Called by bottom layer ISR when transfer is complete. Returns non-zero
119 * size if successful. Setting start to NULL forces stop. */
120 void pcm_rec_more_ready_callback(int status, void **start, size_t *size);
122 void pcm_calculate_rec_peaks(int *left, int *right);
124 #endif /* HAVE_RECORDING */
126 #endif /* PCM_PLAYBACK_H */