Factor out the duplicate code from bufadvance in rebuffer_handle()
[Rockbox.git] / firmware / export / pcm.h
bloba875479a2d3f26f5a18ac2199e5476fc57476216
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 PCM_PLAYBACK_H
20 #define PCM_PLAYBACK_H
22 #include <sys/types.h>
24 /** RAW PCM routines used with playback and recording **/
26 /* Typedef for registered callback */
27 typedef void (*pcm_more_callback_type)(unsigned char **start,
28 size_t *size);
29 typedef int (*pcm_more_callback_type2)(int status);
31 /* set the pcm frequency - use values in hw_sampr_list
32 * use -1 for the default frequency
34 void pcm_set_frequency(unsigned int frequency);
35 /* apply settings to hardware immediately */
36 void pcm_apply_settings(void);
38 /** RAW PCM playback routines **/
40 /* Reenterable locks for locking and unlocking the playback interrupt */
41 void pcm_play_lock(void);
42 void pcm_play_unlock(void);
44 void pcm_init(void);
45 void pcm_postinit(void);
47 /* This is for playing "raw" PCM data */
48 void pcm_play_data(pcm_more_callback_type get_more,
49 unsigned char* start, size_t size);
51 void pcm_calculate_peaks(int *left, int *right);
52 size_t pcm_get_bytes_waiting(void);
54 void pcm_play_stop(void);
55 void pcm_mute(bool mute);
56 void pcm_play_pause(bool play);
57 bool pcm_is_paused(void);
58 bool pcm_is_playing(void);
60 /** The following are for internal use between pcm.c and target-
61 specific portion **/
63 extern unsigned long pcm_curr_sampr;
65 /* the registered callback function to ask for more mp3 data */
66 extern volatile pcm_more_callback_type pcm_callback_for_more;
67 extern volatile bool pcm_playing;
68 extern volatile bool pcm_paused;
70 void pcm_play_dma_lock(void);
71 void pcm_play_dma_unlock(void);
72 void pcm_play_dma_init(void);
73 void pcm_play_dma_start(const void *addr, size_t size);
74 void pcm_play_dma_stop(void);
75 void pcm_play_dma_pause(bool pause);
76 void pcm_play_dma_stopped_callback(void);
77 const void * pcm_play_dma_get_peak_buffer(int *count);
79 #ifdef HAVE_RECORDING
81 /** RAW PCM recording routines **/
83 /* Reenterable locks for locking and unlocking the recording interrupt */
84 void pcm_rec_lock(void);
85 void pcm_rec_unlock(void);
87 /* Initialize pcm recording interface */
88 void pcm_init_recording(void);
89 /* Uninitialze pcm recording interface */
90 void pcm_close_recording(void);
92 /* Start recording "raw" PCM data */
93 void pcm_record_data(pcm_more_callback_type2 more_ready,
94 void *start, size_t size);
96 /* Stop tranferring data into supplied buffer */
97 void pcm_stop_recording(void);
99 /* Continue transferring data in - call during interrupt handler */
100 void pcm_record_more(void *start, size_t size);
102 void pcm_calculate_rec_peaks(int *left, int *right);
104 /** The following are for internal use between pcm.c and target-
105 specific portion **/
106 extern volatile const void *pcm_rec_peak_addr;
107 /* the registered callback function for when more data is available */
108 extern volatile pcm_more_callback_type2 pcm_callback_more_ready;
109 /* DMA transfer in is currently active */
110 extern volatile bool pcm_recording;
112 /* APIs implemented in the target-specific portion */
113 void pcm_rec_dma_init(void);
114 void pcm_rec_dma_close(void);
115 void pcm_rec_dma_start(void *addr, size_t size);
116 void pcm_rec_dma_stop(void);
117 void pcm_rec_dma_stopped_callback(void);
118 const void * pcm_rec_dma_get_peak_buffer(int *count);
120 #endif /* HAVE_RECORDING */
122 #endif /* PCM_PLAYBACK_H */