1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Peter D'Hoye 2009-07-03 22:16:11 +00:00
parent eabeb928dd
commit 0d4560cb03
113 changed files with 10637 additions and 4420 deletions

View file

@ -22,31 +22,76 @@
#include "plugin.h"
#include "pdbox.h"
#include "m_pd.h"
#include "s_stuff.h"
/* Welcome to the PDBox plugin */
PLUGIN_HEADER
PLUGIN_IRAM_DECLARE
/* Name of the file to open. */
char* filename;
/* Running time. */
uint64_t runningtime = 0;
/* Variables for Pure Data. */
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];
/* 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 */
/* Core thread, scheduler. */
void core_thread(void)
{
struct datagram ping;
/* 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();
@ -56,8 +101,13 @@ void core_thread(void)
SEND_FROM_CORE("Pong!");
break;
}
#endif
rb->yield();
/* 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();
@ -66,11 +116,12 @@ void core_thread(void)
/* GUI thread */
void gui_thread(void)
{
struct datagram pong;
/* struct datagram pong; */
/* GUI loop */
while(!quit)
{
#if 0
/* Send ping to the core. */
SEND_TO_CORE("Ping!");
rb->splash(HZ, "Sent ping.");
@ -86,8 +137,22 @@ void gui_thread(void)
quit = true;
break;
}
#endif
rb->yield();
rb->sleep(1);
}
rb->thread_exit();
}
/* Running time thread. */
void time_thread(void)
{
while(!quit)
{
/* Add time slice in milliseconds. */
runningtime += (1000 / HZ);
rb->sleep(1);
}
rb->thread_exit();
@ -99,11 +164,12 @@ enum plugin_status plugin_start(const void* parameter)
{
PLUGIN_IRAM_INIT(rb)
/* Memory pool variables. */
size_t mem_size;
void* mem_pool;
/* Get the file name. */
const char* filename = (const char*) parameter;
filename = (char*) parameter;
/* Allocate memory; check it's size; add to the pool. */
mem_pool = rb->plugin_get_audio_buffer(&mem_size);
@ -117,7 +183,35 @@ enum plugin_status plugin_start(const void* parameter)
/* Initialize net. */
net_init();
/* Initialize Pure Data, as does sys_main in s_main.c */
pd_init();
/* 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,
time_stack,
sizeof(time_stack),
0, /* FIXME Which flags? */
"PD running time"
IF_PRIO(, PRIORITY_REALTIME)
IF_COP(, COP));
core_thread_id =
rb->create_thread(&core_thread,
core_stack,
@ -142,11 +236,12 @@ enum plugin_status plugin_start(const void* parameter)
/* Wait for quit flag. */
while(!quit)
rb->yield();
yield();
/* Wait for threads to complete. */
rb->thread_wait(gui_thread_id);
rb->thread_wait(core_thread_id);
rb->thread_wait(time_thread_id);
/* Destroy net. */
net_destroy();