summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/pdbox.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-07-12 18:44:26 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-07-12 18:44:26 +0000
commit66a0492ab7931df48689e4aa53caaafd025087c3 (patch)
tree4d17a3b7ae37ab0465abff054c106f42ded7ee04 /apps/plugins/pdbox/pdbox.c
parenta3a8708cdff7350e90b2a1224561a0f54faa41cd (diff)
downloadrockbox-66a0492ab7931df48689e4aa53caaafd025087c3.zip
rockbox-66a0492ab7931df48689e4aa53caaafd025087c3.tar.gz
rockbox-66a0492ab7931df48689e4aa53caaafd025087c3.tar.bz2
rockbox-66a0492ab7931df48689e4aa53caaafd025087c3.tar.xz
More work on PDBox by Wincent Balin. The PDBox plug-in is now working with the pdpod_test.pd file from the PureData.zip archive
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21816 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/pdbox.c')
-rw-r--r--apps/plugins/pdbox/pdbox.c119
1 files changed, 48 insertions, 71 deletions
diff --git a/apps/plugins/pdbox/pdbox.c b/apps/plugins/pdbox/pdbox.c
index 0f3728e..38c12c2 100644
--- a/apps/plugins/pdbox/pdbox.c
+++ b/apps/plugins/pdbox/pdbox.c
@@ -40,79 +40,34 @@ int sys_verbose;
int sys_noloadbang;
t_symbol *sys_libdir;
t_namelist *sys_openlist;
-int sys_nsoundin = 0;
int sys_soundindevlist[MAXAUDIOINDEV];
-int sys_nchin = 0;
int sys_chinlist[MAXAUDIOINDEV];
-int sys_nsoundout = 1;
int sys_soundoutdevlist[MAXAUDIOOUTDEV];
-int sys_nchout = 2;
int sys_choutlist[MAXAUDIOOUTDEV];
-static int sys_main_srate = PD_SAMPLERATE;
-static int sys_main_advance = PD_SAMPLES_PER_HZ;
/* References for scheduler variables and functions. */
extern t_time sys_time;
extern t_time sys_time_per_dsp_tick;
extern void sched_tick(t_time next_sys_time);
-#define SAMPLES_SIZE 1000
-t_sample samples[SAMPLES_SIZE];
+/* LATER consider making this variable. It's now the LCM of all sample
+rates we expect to see: 32000, 44100, 48000, 88200, 96000. */
+#define TIMEUNITPERSEC (32.*441000.)
+
/* Quit flag. */
bool quit = false;
/* Thread IDs. */
-unsigned int core_thread_id;
unsigned int gui_thread_id;
unsigned int time_thread_id;
/* Stacks for threads. */
#define STACK_SIZE 16384
-uint32_t core_stack[STACK_SIZE / sizeof(uint32_t)];
uint32_t gui_stack[STACK_SIZE / sizeof(uint32_t)];
uint32_t time_stack[256 / sizeof(uint32_t)];
-/* Core thread, scheduler. */
-void core_thread(void)
-{
-/* struct datagram ping; */
-
- /* LATER consider making this variable. It's now the LCM of all sample
- rates we expect to see: 32000, 44100, 48000, 88200, 96000. */
- #define TIMEUNITPERSEC (32.*441000.)
-
- sys_time = 0;
- sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
- ((double)sys_schedblocksize) / sys_dacsr;
-
-
- /* Main loop */
- while(!quit)
- {
-#if 0
- /* Wait for request. */
- while(!RECEIVE_TO_CORE(&ping))
- rb->yield();
-
- if(memcmp("Ping!", ping.data, ping.size) == 0)
- {
- SEND_FROM_CORE("Pong!");
- break;
- }
-#endif
-
- /* Use sys_send_dacs() function as timer. */
- if(sys_send_dacs() != SENDDACS_NO)
- sched_tick(sys_time + sys_time_per_dsp_tick);
-
- rb->sleep(1);
- }
-
- rb->thread_exit();
-}
-
/* GUI thread */
void gui_thread(void)
{
@@ -138,6 +93,8 @@ void gui_thread(void)
break;
}
#endif
+ if(rb->button_get(false) == BUTTON_OFF)
+ quit = true;
rb->sleep(1);
}
@@ -168,8 +125,13 @@ enum plugin_status plugin_start(const void* parameter)
size_t mem_size;
void* mem_pool;
- /* Get the file name. */
+ /* Get the file name; check whether parameter contains no file name. */
filename = (char*) parameter;
+ if(strlen(filename) == 0)
+ {
+ rb->splash(HZ, "Play a .pd file!");
+ return PLUGIN_ERROR;
+ }
/* Allocate memory; check it's size; add to the pool. */
mem_pool = rb->plugin_get_audio_buffer(&mem_size);
@@ -186,23 +148,31 @@ enum plugin_status plugin_start(const void* parameter)
/* Initialize Pure Data, as does sys_main in s_main.c */
pd_init();
+ /* Set audio API. */
+ sys_set_audio_api(API_ROCKBOX);
+
+ /* Initialize audio subsystem. */
+ sys_open_audio(0, /* No sound input yet */
+ sys_soundindevlist,
+ 0, /* No sound input yet */
+ sys_chinlist,
+ 1, /* One sound output device */
+ sys_soundoutdevlist,
+ -1, /* Use the default amount (2) of channels */
+ sys_choutlist,
+ PD_SAMPLERATE, /* Sample rate */
+ DEFAULTADVANCE, /* Scheduler advance */
+ 1 /* Enable */);
+
/* Add the directory the called .pd resides in to lib directories. */
sys_findlibdir(filename);
/* Open the parameter file. */
sys_openlist = namelist_append(sys_openlist, filename);
- /* Set audio API. */
- sys_set_audio_api(API_ROCKBOX);
-
/* Fake a GUI start. */
sys_startgui(NULL);
- /* Initialize audio subsystem. */
- sys_open_audio(sys_nsoundin, sys_soundindevlist, sys_nchin, sys_chinlist,
- sys_nsoundout, sys_soundoutdevlist, sys_nchout, sys_choutlist,
- sys_main_srate, sys_main_advance, 1);
-
/* Start threads. */
time_thread_id =
rb->create_thread(&time_thread,
@@ -212,15 +182,7 @@ enum plugin_status plugin_start(const void* parameter)
"PD running time"
IF_PRIO(, PRIORITY_REALTIME)
IF_COP(, COP));
- core_thread_id =
- rb->create_thread(&core_thread,
- core_stack,
- sizeof(core_stack),
- 0, /* FIXME Which flags? */
- "PD core"
- IF_PRIO(, MAX(PRIORITY_USER_INTERFACE / 2,
- PRIORITY_REALTIME + 1))
- IF_COP(, COP));
+
gui_thread_id =
rb->create_thread(&gui_thread,
gui_stack,
@@ -231,18 +193,33 @@ enum plugin_status plugin_start(const void* parameter)
IF_COP(, CPU));
/* If having an error creating threads, bail out. */
- if(core_thread_id == 0 || gui_thread_id == 0)
+ if(time_thread_id == 0 || gui_thread_id == 0)
return PLUGIN_ERROR;
- /* Wait for quit flag. */
+ /* Initialize scheduler time variables. */
+ sys_time = 0;
+ sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
+ ((double) sys_schedblocksize) / sys_dacsr;
+
+
+ /* Main loop. */
while(!quit)
- yield();
+ {
+ /* Use sys_send_dacs() function as timer. */
+ while(sys_send_dacs() != SENDDACS_NO)
+ sched_tick(sys_time + sys_time_per_dsp_tick);
+
+ /* Sleep to the next time slice. */
+ rb->sleep(1);
+ }
/* Wait for threads to complete. */
rb->thread_wait(gui_thread_id);
- rb->thread_wait(core_thread_id);
rb->thread_wait(time_thread_id);
+ /* Close audio subsystem. */
+ sys_close_audio();
+
/* Destroy net. */
net_destroy();