summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/pdbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/pdbox.c')
-rw-r--r--apps/plugins/pdbox/pdbox.c93
1 files changed, 60 insertions, 33 deletions
diff --git a/apps/plugins/pdbox/pdbox.c b/apps/plugins/pdbox/pdbox.c
index 38c12c279b..dd848deba2 100644
--- a/apps/plugins/pdbox/pdbox.c
+++ b/apps/plugins/pdbox/pdbox.c
@@ -58,14 +58,17 @@ rates we expect to see: 32000, 44100, 48000, 88200, 96000. */
58/* Quit flag. */ 58/* Quit flag. */
59bool quit = false; 59bool quit = false;
60 60
61/* Stack sizes for threads. */
62#define CORESTACKSIZE (8 * 1024 * 1024)
63#define GUISTACKSIZE (512 * 1024)
64
65/* Thread stacks. */
66void* core_stack;
67void* gui_stack;
68
61/* Thread IDs. */ 69/* Thread IDs. */
70unsigned int core_thread_id;
62unsigned int gui_thread_id; 71unsigned int gui_thread_id;
63unsigned int time_thread_id;
64
65/* Stacks for threads. */
66#define STACK_SIZE 16384
67uint32_t gui_stack[STACK_SIZE / sizeof(uint32_t)];
68uint32_t time_stack[256 / sizeof(uint32_t)];
69 72
70 73
71/* GUI thread */ 74/* GUI thread */
@@ -102,20 +105,33 @@ void gui_thread(void)
102 rb->thread_exit(); 105 rb->thread_exit();
103} 106}
104 107
105/* Running time thread. */ 108/* Core thread */
106void time_thread(void) 109void core_thread(void)
107{ 110{
111 /* Add the directory the called .pd resides in to lib directories. */
112 sys_findlibdir(filename);
113
114 /* Open the PD design file. */
115 sys_openlist = namelist_append(sys_openlist, filename);
116
117 /* Fake a GUI start. */
118 sys_startgui(NULL);
119
120 /* Core scheduler loop */
108 while(!quit) 121 while(!quit)
109 { 122 {
110 /* Add time slice in milliseconds. */ 123 /* Use sys_send_dacs() function as timer. */
111 runningtime += (1000 / HZ); 124 while(sys_send_dacs() != SENDDACS_NO)
112 rb->sleep(1); 125 sched_tick(sys_time + sys_time_per_dsp_tick);
126
127 yield();
113 } 128 }
114 129
115 rb->thread_exit(); 130 rb->thread_exit();
116} 131}
117 132
118 133
134
119/* Plug-in entry point */ 135/* Plug-in entry point */
120enum plugin_status plugin_start(const void* parameter) 136enum plugin_status plugin_start(const void* parameter)
121{ 137{
@@ -133,14 +149,19 @@ enum plugin_status plugin_start(const void* parameter)
133 return PLUGIN_ERROR; 149 return PLUGIN_ERROR;
134 } 150 }
135 151
136 /* Allocate memory; check it's size; add to the pool. */ 152 /* Initialize memory pool. */
137 mem_pool = rb->plugin_get_audio_buffer(&mem_size); 153 mem_pool = rb->plugin_get_audio_buffer(&mem_size);
138 if(mem_size < MIN_MEM_SIZE) 154 if(mem_size < MIN_MEM_SIZE)
139 { 155 {
140 rb->splash(HZ, "Not enough memory!"); 156 rb->splash(HZ, "Not enough memory!");
141 return PLUGIN_ERROR; 157 return PLUGIN_ERROR;
142 } 158 }
143 add_pool(mem_pool, mem_size); 159#if 1
160 init_memory_pool(mem_size, mem_pool);
161#endif
162#if 0
163 set_memory_pool(mem_pool, mem_size);
164#endif
144 165
145 /* Initialize net. */ 166 /* Initialize net. */
146 net_init(); 167 net_init();
@@ -164,36 +185,36 @@ enum plugin_status plugin_start(const void* parameter)
164 DEFAULTADVANCE, /* Scheduler advance */ 185 DEFAULTADVANCE, /* Scheduler advance */
165 1 /* Enable */); 186 1 /* Enable */);
166 187
167 /* Add the directory the called .pd resides in to lib directories. */ 188 /* Create stacks for threads. */
168 sys_findlibdir(filename); 189 core_stack = getbytes(CORESTACKSIZE);
169 190 gui_stack = getbytes(GUISTACKSIZE);
170 /* Open the parameter file. */ 191 if(core_stack == NULL || gui_stack == NULL)
171 sys_openlist = namelist_append(sys_openlist, filename); 192 {
172 193 rb->splash(HZ, "Not enough memory!");
173 /* Fake a GUI start. */ 194 return PLUGIN_ERROR;
174 sys_startgui(NULL); 195 }
175 196
176 /* Start threads. */ 197 /* Start threads. */
177 time_thread_id = 198 core_thread_id =
178 rb->create_thread(&time_thread, 199 rb->create_thread(&core_thread,
179 time_stack, 200 core_stack,
180 sizeof(time_stack), 201 CORESTACKSIZE,
181 0, /* FIXME Which flags? */ 202 0, /* FIXME Which flags? */
182 "PD running time" 203 "PD core"
183 IF_PRIO(, PRIORITY_REALTIME) 204 IF_PRIO(, PRIORITY_REALTIME)
184 IF_COP(, COP)); 205 IF_COP(, COP));
185 206
186 gui_thread_id = 207 gui_thread_id =
187 rb->create_thread(&gui_thread, 208 rb->create_thread(&gui_thread,
188 gui_stack, 209 gui_stack,
189 sizeof(gui_stack), 210 GUISTACKSIZE,
190 0, /* FIXME Which flags? */ 211 0, /* FIXME Which flags? */
191 "PD GUI" 212 "PD GUI"
192 IF_PRIO(, PRIORITY_USER_INTERFACE) 213 IF_PRIO(, PRIORITY_USER_INTERFACE)
193 IF_COP(, CPU)); 214 IF_COP(, CPU));
194 215
195 /* If having an error creating threads, bail out. */ 216 /* If having an error creating threads, bail out. */
196 if(time_thread_id == 0 || gui_thread_id == 0) 217 if(core_thread_id == 0 || gui_thread_id == 0)
197 return PLUGIN_ERROR; 218 return PLUGIN_ERROR;
198 219
199 /* Initialize scheduler time variables. */ 220 /* Initialize scheduler time variables. */
@@ -205,9 +226,8 @@ enum plugin_status plugin_start(const void* parameter)
205 /* Main loop. */ 226 /* Main loop. */
206 while(!quit) 227 while(!quit)
207 { 228 {
208 /* Use sys_send_dacs() function as timer. */ 229 /* Add time slice in milliseconds. */
209 while(sys_send_dacs() != SENDDACS_NO) 230 runningtime += (1000 / HZ);
210 sched_tick(sys_time + sys_time_per_dsp_tick);
211 231
212 /* Sleep to the next time slice. */ 232 /* Sleep to the next time slice. */
213 rb->sleep(1); 233 rb->sleep(1);
@@ -215,7 +235,7 @@ enum plugin_status plugin_start(const void* parameter)
215 235
216 /* Wait for threads to complete. */ 236 /* Wait for threads to complete. */
217 rb->thread_wait(gui_thread_id); 237 rb->thread_wait(gui_thread_id);
218 rb->thread_wait(time_thread_id); 238 rb->thread_wait(core_thread_id);
219 239
220 /* Close audio subsystem. */ 240 /* Close audio subsystem. */
221 sys_close_audio(); 241 sys_close_audio();
@@ -223,6 +243,13 @@ enum plugin_status plugin_start(const void* parameter)
223 /* Destroy net. */ 243 /* Destroy net. */
224 net_destroy(); 244 net_destroy();
225 245
246 /* Clear memory pool. */
247#if 1
248 destroy_memory_pool(mem_pool);
249#endif
250#if 0
251 clear_memory_pool();
252#endif
253
226 return PLUGIN_OK; 254 return PLUGIN_OK;
227} 255}
228