diff options
| author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-07-12 18:44:26 +0000 |
|---|---|---|
| committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-07-12 18:44:26 +0000 |
| commit | 66a0492ab7931df48689e4aa53caaafd025087c3 (patch) | |
| tree | 4d17a3b7ae37ab0465abff054c106f42ded7ee04 /apps/plugins/pdbox/PDa/src | |
| parent | a3a8708cdff7350e90b2a1224561a0f54faa41cd (diff) | |
| download | rockbox-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/PDa/src')
| -rw-r--r-- | apps/plugins/pdbox/PDa/src/d_ugen.c | 1 | ||||
| -rw-r--r-- | apps/plugins/pdbox/PDa/src/m_class.c | 7 | ||||
| -rw-r--r-- | apps/plugins/pdbox/PDa/src/s_audio_rockbox.c | 165 |
3 files changed, 112 insertions, 61 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_ugen.c b/apps/plugins/pdbox/PDa/src/d_ugen.c index 6cf0a5a..8454b12 100644 --- a/apps/plugins/pdbox/PDa/src/d_ugen.c +++ b/apps/plugins/pdbox/PDa/src/d_ugen.c @@ -313,7 +313,6 @@ void dsp_tick(void) t_int *ip; for (ip = dsp_chain; *ip; ) ip = (*(t_perfroutine)(*ip))(ip); dsp_phase++; -printf("%d\n", dsp_phase); } } diff --git a/apps/plugins/pdbox/PDa/src/m_class.c b/apps/plugins/pdbox/PDa/src/m_class.c index 98fe9be..95623fd 100644 --- a/apps/plugins/pdbox/PDa/src/m_class.c +++ b/apps/plugins/pdbox/PDa/src/m_class.c @@ -507,7 +507,12 @@ t_symbol *dogensym(char *s, t_symbol *oldsym) t_symbol *gensym(char *s) { -printf("gensym: %s\n", s); +// printf("gensym: %s\n", s); +#ifdef ROCKBOX + if(s == NULL) + return dogensym("/", 0); + else +#endif return(dogensym(s, 0)); } diff --git a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c index 7f9b0e0..8019289 100644 --- a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c +++ b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c @@ -25,25 +25,32 @@ #include "m_pd.h" #include "s_stuff.h" -/* Sound output buffer. */ -#define AUDIO_OUTPUT_BLOCKS 3 -static struct pdbox_audio_block audio_output[AUDIO_OUTPUT_BLOCKS]; -static unsigned int output_head; -static unsigned int output_tail; -static unsigned int output_fill; +/* Extern variables. */ +extern float sys_dacsr; +extern t_sample *sys_soundout; +extern t_sample *sys_soundin; + +/* Output buffer. */ +#define OUTBUFSIZE 3 +static struct audio_buffer outbuf[OUTBUFSIZE]; +static unsigned int outbuf_head; +static unsigned int outbuf_tail; +static unsigned int outbuf_fill; + +/* Playing status. */ +static bool playing; + /* Open audio. */ void rockbox_open_audio(int rate) { unsigned int i; - /* Initialize output buffer. */ - for(i = 0; i < AUDIO_OUTPUT_BLOCKS; i++) - audio_output[i].fill = 0; + /* No sound yet. */ + playing = false; - output_head = 0; - output_tail = 0; - output_fill = 0; + /* Stop playing to reconfigure audio settings. */ + rb->pcm_play_stop(); #if INPUT_SRC_CAPS != 0 /* Select playback */ @@ -53,6 +60,15 @@ void rockbox_open_audio(int rate) /* Set sample rate of the audio buffer. */ rb->pcm_set_frequency(rate); + rb->pcm_apply_settings(); + + /* Initialize output buffer. */ + for(i = 0; i < OUTBUFSIZE; i++) + outbuf[i].fill = 0; + + outbuf_head = 0; + outbuf_tail = 0; + outbuf_fill = 0; } /* Close audio. */ @@ -61,84 +77,115 @@ void rockbox_close_audio(void) /* Stop playback. */ rb->pcm_play_stop(); + /* Reset playing status. */ + playing = false; + /* Restore default sampling rate. */ rb->pcm_set_frequency(HW_SAMPR_DEFAULT); + rb->pcm_apply_settings(); } /* Rockbox audio callback. */ void pdbox_get_more(unsigned char** start, size_t* size) { - if(output_fill > 0) + if(outbuf_fill > 0) { /* Store output data address and size. */ - *start = (unsigned char*) audio_output[output_tail].data; - *size = audio_output[output_tail].fill; - - /* Advance tail index. */ - audio_output[output_tail].fill = 0; - output_fill--; - if(output_tail == AUDIO_OUTPUT_BLOCKS-1) - output_tail = 0; + *start = (unsigned char*) outbuf[outbuf_tail].data; + *size = sizeof(outbuf[outbuf_tail].data); + + /* Free this part of output buffer. */ + outbuf[outbuf_tail].fill = 0; + + /* Advance to the next part of output buffer. */ + if(outbuf_tail == OUTBUFSIZE-1) + outbuf_tail = 0; else - output_tail++; + outbuf_tail++; + + /* Decrease output buffer fill. */ + outbuf_fill--; } else { + /* Reset playing status. */ + playing = false; + /* Nothing to play. */ *start = NULL; *size = 0; - return; } } /* Audio I/O. */ int rockbox_send_dacs(void) { + /* Copy sys_output buffer. */ + t_sample* left = sys_soundout + DEFDACBLKSIZE*0; + t_sample* right = sys_soundout + DEFDACBLKSIZE*1; + unsigned int samples_out = 0; + int16_t* out; + int sample; + + /* Cancel if whole buffer filled. */ + if(outbuf_fill >= OUTBUFSIZE-1) + return SENDDACS_NO; + + /* Write the block of sound. */ +write_block: + for(out = outbuf[outbuf_head].data + + outbuf[outbuf_head].fill * PD_OUT_CHANNELS; + outbuf[outbuf_head].fill < (AUDIOBUFSIZE / PD_OUT_CHANNELS) && + samples_out < DEFDACBLKSIZE; + left++, right++, samples_out++, outbuf[outbuf_head].fill++) + { + /* Copy samples from both channels. */ + sample = SCALE16(*left); + if(sample > 32767) + sample = 32767; + else if(sample < -32767) + sample = -32767; + *out++ = sample; + sample = SCALE16(*right); + if(sample > 32767) + sample = 32767; + else if(sample < -32767) + sample = -32767; + *out++ = sample; + } - - /* Start playback if needed and possible. */ - if(output_fill > 1 && - audio_output[output_tail].fill == PD_AUDIO_BLOCK_SIZE) + /* If part of output buffer filled... */ + if(outbuf[outbuf_head].fill >= (AUDIOBUFSIZE / PD_OUT_CHANNELS)) { - /* Start playback. */ - rb->pcm_play_data(pdbox_get_more, - (unsigned char*) audio_output[output_tail].data, - PD_AUDIO_BLOCK_SIZE); - - /* Advance tail index. */ - audio_output[output_tail].fill = PD_AUDIO_BLOCK_SIZE; - output_fill--; - if(output_tail == AUDIO_OUTPUT_BLOCKS-1) - output_tail = 0; + /* Advance one part of output buffer. */ + if(outbuf_head == OUTBUFSIZE-1) + outbuf_head = 0; else - output_tail++; - } + outbuf_head++; + /* Increase fill counter. */ + outbuf_fill++; + } + /* If needed, fill the next frame. */ + if(samples_out < DEFDACBLKSIZE) + goto write_block; + /* Clear Pure Data output buffer. */ + memset(sys_soundout, + 0, + sizeof(t_sample) * DEFDACBLKSIZE * PD_OUT_CHANNELS); -#if 0 - if (sys_getrealtime() > timebefore + 0.002) + /* If still not playing... */ + if(!playing && outbuf_fill > 0) { - /* post("slept"); */ - return (SENDDACS_SLEPT); - } - else -#endif - return (SENDDACS_YES); -} + /* Start playing. */ + rb->pcm_play_data(pdbox_get_more, NULL, 0); -/* Placeholder. */ -void rockbox_listdevs(void) -{ -} + /* Set status flag. */ + playing = true; + } -#if 0 -/* Scanning for devices */ -void rockbox_getdevs(char *indevlist, int *nindevs, - char *outdevlist, int *noutdevs, int *canmulti, - int maxndev, int devdescsize) -{ + return SENDDACS_YES; } -#endif |