summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/pdbox.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-07-03 22:16:11 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-07-03 22:16:11 +0000
commit0d4560cb0305029fa5f0739670286176ab47cb65 (patch)
tree9899f4324664a77e6a5884fdd1541818a28a2172 /apps/plugins/pdbox/pdbox.c
parenteabeb928ddfdbe5fc6379efb87d9522803310649 (diff)
downloadrockbox-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/pdbox.c')
-rw-r--r--apps/plugins/pdbox/pdbox.c109
1 files changed, 102 insertions, 7 deletions
diff --git a/apps/plugins/pdbox/pdbox.c b/apps/plugins/pdbox/pdbox.c
index d6e25ca3fa..0f3728e586 100644
--- a/apps/plugins/pdbox/pdbox.c
+++ b/apps/plugins/pdbox/pdbox.c
@@ -22,31 +22,76 @@
22#include "plugin.h" 22#include "plugin.h"
23#include "pdbox.h" 23#include "pdbox.h"
24 24
25#include "m_pd.h"
26#include "s_stuff.h"
27
25/* Welcome to the PDBox plugin */ 28/* Welcome to the PDBox plugin */
26PLUGIN_HEADER 29PLUGIN_HEADER
27PLUGIN_IRAM_DECLARE 30PLUGIN_IRAM_DECLARE
28 31
32/* Name of the file to open. */
33char* filename;
34
35/* Running time. */
36uint64_t runningtime = 0;
37
38/* Variables for Pure Data. */
39int sys_verbose;
40int sys_noloadbang;
41t_symbol *sys_libdir;
42t_namelist *sys_openlist;
43int sys_nsoundin = 0;
44int sys_soundindevlist[MAXAUDIOINDEV];
45int sys_nchin = 0;
46int sys_chinlist[MAXAUDIOINDEV];
47int sys_nsoundout = 1;
48int sys_soundoutdevlist[MAXAUDIOOUTDEV];
49int sys_nchout = 2;
50int sys_choutlist[MAXAUDIOOUTDEV];
51static int sys_main_srate = PD_SAMPLERATE;
52static int sys_main_advance = PD_SAMPLES_PER_HZ;
53
54/* References for scheduler variables and functions. */
55extern t_time sys_time;
56extern t_time sys_time_per_dsp_tick;
57extern void sched_tick(t_time next_sys_time);
58
59#define SAMPLES_SIZE 1000
60t_sample samples[SAMPLES_SIZE];
61
29/* Quit flag. */ 62/* Quit flag. */
30bool quit = false; 63bool quit = false;
31 64
32/* Thread IDs. */ 65/* Thread IDs. */
33unsigned int core_thread_id; 66unsigned int core_thread_id;
34unsigned int gui_thread_id; 67unsigned int gui_thread_id;
68unsigned int time_thread_id;
35 69
36/* Stacks for threads. */ 70/* Stacks for threads. */
37#define STACK_SIZE 16384 71#define STACK_SIZE 16384
38uint32_t core_stack[STACK_SIZE / sizeof(uint32_t)]; 72uint32_t core_stack[STACK_SIZE / sizeof(uint32_t)];
39uint32_t gui_stack[STACK_SIZE / sizeof(uint32_t)]; 73uint32_t gui_stack[STACK_SIZE / sizeof(uint32_t)];
74uint32_t time_stack[256 / sizeof(uint32_t)];
40 75
41 76
42/* Core thread */ 77/* Core thread, scheduler. */
43void core_thread(void) 78void core_thread(void)
44{ 79{
45 struct datagram ping; 80/* struct datagram ping; */
81
82 /* LATER consider making this variable. It's now the LCM of all sample
83 rates we expect to see: 32000, 44100, 48000, 88200, 96000. */
84 #define TIMEUNITPERSEC (32.*441000.)
85
86 sys_time = 0;
87 sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
88 ((double)sys_schedblocksize) / sys_dacsr;
89
46 90
47 /* Main loop */ 91 /* Main loop */
48 while(!quit) 92 while(!quit)
49 { 93 {
94#if 0
50 /* Wait for request. */ 95 /* Wait for request. */
51 while(!RECEIVE_TO_CORE(&ping)) 96 while(!RECEIVE_TO_CORE(&ping))
52 rb->yield(); 97 rb->yield();
@@ -56,8 +101,13 @@ void core_thread(void)
56 SEND_FROM_CORE("Pong!"); 101 SEND_FROM_CORE("Pong!");
57 break; 102 break;
58 } 103 }
104#endif
105
106 /* Use sys_send_dacs() function as timer. */
107 if(sys_send_dacs() != SENDDACS_NO)
108 sched_tick(sys_time + sys_time_per_dsp_tick);
59 109
60 rb->yield(); 110 rb->sleep(1);
61 } 111 }
62 112
63 rb->thread_exit(); 113 rb->thread_exit();
@@ -66,11 +116,12 @@ void core_thread(void)
66/* GUI thread */ 116/* GUI thread */
67void gui_thread(void) 117void gui_thread(void)
68{ 118{
69 struct datagram pong; 119/* struct datagram pong; */
70 120
71 /* GUI loop */ 121 /* GUI loop */
72 while(!quit) 122 while(!quit)
73 { 123 {
124#if 0
74 /* Send ping to the core. */ 125 /* Send ping to the core. */
75 SEND_TO_CORE("Ping!"); 126 SEND_TO_CORE("Ping!");
76 rb->splash(HZ, "Sent ping."); 127 rb->splash(HZ, "Sent ping.");
@@ -86,8 +137,22 @@ void gui_thread(void)
86 quit = true; 137 quit = true;
87 break; 138 break;
88 } 139 }
140#endif
141
142 rb->sleep(1);
143 }
144
145 rb->thread_exit();
146}
89 147
90 rb->yield(); 148/* Running time thread. */
149void time_thread(void)
150{
151 while(!quit)
152 {
153 /* Add time slice in milliseconds. */
154 runningtime += (1000 / HZ);
155 rb->sleep(1);
91 } 156 }
92 157
93 rb->thread_exit(); 158 rb->thread_exit();
@@ -99,11 +164,12 @@ enum plugin_status plugin_start(const void* parameter)
99{ 164{
100 PLUGIN_IRAM_INIT(rb) 165 PLUGIN_IRAM_INIT(rb)
101 166
167 /* Memory pool variables. */
102 size_t mem_size; 168 size_t mem_size;
103 void* mem_pool; 169 void* mem_pool;
104 170
105 /* Get the file name. */ 171 /* Get the file name. */
106 const char* filename = (const char*) parameter; 172 filename = (char*) parameter;
107 173
108 /* Allocate memory; check it's size; add to the pool. */ 174 /* Allocate memory; check it's size; add to the pool. */
109 mem_pool = rb->plugin_get_audio_buffer(&mem_size); 175 mem_pool = rb->plugin_get_audio_buffer(&mem_size);
@@ -117,7 +183,35 @@ enum plugin_status plugin_start(const void* parameter)
117 /* Initialize net. */ 183 /* Initialize net. */
118 net_init(); 184 net_init();
119 185
186 /* Initialize Pure Data, as does sys_main in s_main.c */
187 pd_init();
188
189 /* Add the directory the called .pd resides in to lib directories. */
190 sys_findlibdir(filename);
191
192 /* Open the parameter file. */
193 sys_openlist = namelist_append(sys_openlist, filename);
194
195 /* Set audio API. */
196 sys_set_audio_api(API_ROCKBOX);
197
198 /* Fake a GUI start. */
199 sys_startgui(NULL);
200
201 /* Initialize audio subsystem. */
202 sys_open_audio(sys_nsoundin, sys_soundindevlist, sys_nchin, sys_chinlist,
203 sys_nsoundout, sys_soundoutdevlist, sys_nchout, sys_choutlist,
204 sys_main_srate, sys_main_advance, 1);
205
120 /* Start threads. */ 206 /* Start threads. */
207 time_thread_id =
208 rb->create_thread(&time_thread,
209 time_stack,
210 sizeof(time_stack),
211 0, /* FIXME Which flags? */
212 "PD running time"
213 IF_PRIO(, PRIORITY_REALTIME)
214 IF_COP(, COP));
121 core_thread_id = 215 core_thread_id =
122 rb->create_thread(&core_thread, 216 rb->create_thread(&core_thread,
123 core_stack, 217 core_stack,
@@ -142,11 +236,12 @@ enum plugin_status plugin_start(const void* parameter)
142 236
143 /* Wait for quit flag. */ 237 /* Wait for quit flag. */
144 while(!quit) 238 while(!quit)
145 rb->yield(); 239 yield();
146 240
147 /* Wait for threads to complete. */ 241 /* Wait for threads to complete. */
148 rb->thread_wait(gui_thread_id); 242 rb->thread_wait(gui_thread_id);
149 rb->thread_wait(core_thread_id); 243 rb->thread_wait(core_thread_id);
244 rb->thread_wait(time_thread_id);
150 245
151 /* Destroy net. */ 246 /* Destroy net. */
152 net_destroy(); 247 net_destroy();