diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-07-03 22:16:11 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-07-03 22:16:11 +0000 |
commit | 0d4560cb0305029fa5f0739670286176ab47cb65 (patch) | |
tree | 9899f4324664a77e6a5884fdd1541818a28a2172 /apps/plugins/pdbox/PDa/src/s_audio_rockbox.c | |
parent | eabeb928ddfdbe5fc6379efb87d9522803310649 (diff) | |
download | rockbox-0d4560cb0305029fa5f0739670286176ab47cb65.tar.gz rockbox-0d4560cb0305029fa5f0739670286176ab47cb65.zip |
Accept FS #10244 by Wincent Balin: more pdbox work done for GSoC; also some keyword and line-ending fixes by me
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21626 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/s_audio_rockbox.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/s_audio_rockbox.c | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c new file mode 100644 index 0000000000..7f9b0e03e1 --- /dev/null +++ b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c | |||
@@ -0,0 +1,144 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 Wincent Balin | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "plugin.h" | ||
23 | #include "pdbox.h" | ||
24 | |||
25 | #include "m_pd.h" | ||
26 | #include "s_stuff.h" | ||
27 | |||
28 | /* Sound output buffer. */ | ||
29 | #define AUDIO_OUTPUT_BLOCKS 3 | ||
30 | static struct pdbox_audio_block audio_output[AUDIO_OUTPUT_BLOCKS]; | ||
31 | static unsigned int output_head; | ||
32 | static unsigned int output_tail; | ||
33 | static unsigned int output_fill; | ||
34 | |||
35 | /* Open audio. */ | ||
36 | void rockbox_open_audio(int rate) | ||
37 | { | ||
38 | unsigned int i; | ||
39 | |||
40 | /* Initialize output buffer. */ | ||
41 | for(i = 0; i < AUDIO_OUTPUT_BLOCKS; i++) | ||
42 | audio_output[i].fill = 0; | ||
43 | |||
44 | output_head = 0; | ||
45 | output_tail = 0; | ||
46 | output_fill = 0; | ||
47 | |||
48 | #if INPUT_SRC_CAPS != 0 | ||
49 | /* Select playback */ | ||
50 | rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); | ||
51 | rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); | ||
52 | #endif | ||
53 | |||
54 | /* Set sample rate of the audio buffer. */ | ||
55 | rb->pcm_set_frequency(rate); | ||
56 | } | ||
57 | |||
58 | /* Close audio. */ | ||
59 | void rockbox_close_audio(void) | ||
60 | { | ||
61 | /* Stop playback. */ | ||
62 | rb->pcm_play_stop(); | ||
63 | |||
64 | /* Restore default sampling rate. */ | ||
65 | rb->pcm_set_frequency(HW_SAMPR_DEFAULT); | ||
66 | } | ||
67 | |||
68 | /* Rockbox audio callback. */ | ||
69 | void pdbox_get_more(unsigned char** start, size_t* size) | ||
70 | { | ||
71 | if(output_fill > 0) | ||
72 | { | ||
73 | /* Store output data address and size. */ | ||
74 | *start = (unsigned char*) audio_output[output_tail].data; | ||
75 | *size = audio_output[output_tail].fill; | ||
76 | |||
77 | /* Advance tail index. */ | ||
78 | audio_output[output_tail].fill = 0; | ||
79 | output_fill--; | ||
80 | if(output_tail == AUDIO_OUTPUT_BLOCKS-1) | ||
81 | output_tail = 0; | ||
82 | else | ||
83 | output_tail++; | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | /* Nothing to play. */ | ||
88 | *start = NULL; | ||
89 | *size = 0; | ||
90 | return; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | /* Audio I/O. */ | ||
95 | int rockbox_send_dacs(void) | ||
96 | { | ||
97 | |||
98 | |||
99 | /* Start playback if needed and possible. */ | ||
100 | if(output_fill > 1 && | ||
101 | audio_output[output_tail].fill == PD_AUDIO_BLOCK_SIZE) | ||
102 | { | ||
103 | /* Start playback. */ | ||
104 | rb->pcm_play_data(pdbox_get_more, | ||
105 | (unsigned char*) audio_output[output_tail].data, | ||
106 | PD_AUDIO_BLOCK_SIZE); | ||
107 | |||
108 | /* Advance tail index. */ | ||
109 | audio_output[output_tail].fill = PD_AUDIO_BLOCK_SIZE; | ||
110 | output_fill--; | ||
111 | if(output_tail == AUDIO_OUTPUT_BLOCKS-1) | ||
112 | output_tail = 0; | ||
113 | else | ||
114 | output_tail++; | ||
115 | } | ||
116 | |||
117 | |||
118 | |||
119 | |||
120 | #if 0 | ||
121 | if (sys_getrealtime() > timebefore + 0.002) | ||
122 | { | ||
123 | /* post("slept"); */ | ||
124 | return (SENDDACS_SLEPT); | ||
125 | } | ||
126 | else | ||
127 | #endif | ||
128 | return (SENDDACS_YES); | ||
129 | } | ||
130 | |||
131 | /* Placeholder. */ | ||
132 | void rockbox_listdevs(void) | ||
133 | { | ||
134 | } | ||
135 | |||
136 | #if 0 | ||
137 | /* Scanning for devices */ | ||
138 | void rockbox_getdevs(char *indevlist, int *nindevs, | ||
139 | char *outdevlist, int *noutdevs, int *canmulti, | ||
140 | int maxndev, int devdescsize) | ||
141 | { | ||
142 | } | ||
143 | #endif | ||
144 | |||