summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-03-28 00:00:24 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-03-28 00:00:24 +0000
commit451dd48adc2ef29fd2f900693393cc9b9b4a849b (patch)
treee15d20e602261866617210bde007966ce9b19293 /apps/plugins
parent853bc3dcf85aa1284a0e5b550277c40beb7697a9 (diff)
downloadrockbox-451dd48adc2ef29fd2f900693393cc9b9b4a849b.zip
rockbox-451dd48adc2ef29fd2f900693393cc9b9b4a849b.tar.gz
rockbox-451dd48adc2ef29fd2f900693393cc9b9b4a849b.tar.bz2
rockbox-451dd48adc2ef29fd2f900693393cc9b9b4a849b.tar.xz
Sound api improvements, rockboy sound, contributed by xshock.
Playback of sound currently only works in boost mode, needs fixing. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6226 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/rockboy/pcm.h2
-rw-r--r--apps/plugins/rockboy/rbsound.c111
-rw-r--r--apps/plugins/rockboy/rockboy.c4
-rw-r--r--apps/plugins/rockboy/sound.c12
4 files changed, 102 insertions, 27 deletions
diff --git a/apps/plugins/rockboy/pcm.h b/apps/plugins/rockboy/pcm.h
index 3719933..742f0e5 100644
--- a/apps/plugins/rockboy/pcm.h
+++ b/apps/plugins/rockboy/pcm.h
@@ -9,7 +9,7 @@ struct pcm
{
int hz, len;
int stereo;
- byte *buf;
+ short *buf;
int pos;
};
diff --git a/apps/plugins/rockboy/rbsound.c b/apps/plugins/rockboy/rbsound.c
index 6d1b24f..92f824a 100644
--- a/apps/plugins/rockboy/rbsound.c
+++ b/apps/plugins/rockboy/rbsound.c
@@ -1,47 +1,120 @@
-
-
-
#include "rockmacros.h"
#include "defs.h"
#include "pcm.h"
#include "rc.h"
+#define RBSOUND
struct pcm pcm;
-static byte buf[4096];
+#define BUF_SIZE (8192)
+#define DMA_PORTION (1024)
+
+static short buf1_unal[(BUF_SIZE / sizeof(short)) + 2]; // to make sure 4 byte aligned
+static short* buf1;
+static short front_buf[512];
+
+static short* last_back_pos;
+
+static bool newly_started;
+static int turns;
rcvar_t pcm_exports[] =
{
- RCV_END
+ RCV_END
};
-
void pcm_init(void)
{
- pcm.hz = 44100;
- pcm.stereo = 1;
- pcm.buf = buf;
- pcm.len = sizeof buf;
- pcm.pos = 0;
+ buf1 = (signed short*)((((unsigned int)buf1_unal) >> 2) << 2); /* here i just make sure that buffer is aligned to 4 bytes*/
+ newly_started = true;
+ last_back_pos = buf1;
+ turns = 0;
+
+ pcm.hz = 11025;
+ pcm.stereo = 1;
+ pcm.buf = front_buf;
+ pcm.len = (sizeof(front_buf)) / sizeof(short); /* length in shorts, not bytes */
+ pcm.pos = 0;
+
+
+ rb->pcm_play_stop();
+ rb->pcm_set_frequency(11025);
+ rb->pcm_set_volume(200);
}
void pcm_close(void)
{
- memset(&pcm, 0, sizeof pcm);
+ memset(&pcm, 0, sizeof pcm);
+ newly_started = true;
+ last_back_pos = buf1;
+ rb->pcm_play_stop();
}
+void get_more(unsigned char** start, long* size)
+{
+ int length;
+ unsigned int sar = (unsigned int)SAR0;
+ length = ((unsigned int)buf1) + BUF_SIZE - sar;
+
+ if(turns > 0)
+ {
+ newly_started = true;
+ last_back_pos = buf1;
+ turns = 0;
+ return;
+ } /* sound will stop if no one feeds data*/
+
+ if(length <= 0)
+ {
+ *start = (unsigned char*)buf1;
+ *size = DMA_PORTION;
+ turns++;
+ }
+ else
+ {
+ *start = (unsigned char*)sar;
+ if(length > DMA_PORTION)
+ *size = DMA_PORTION;
+ else
+ *size = length;
+ }
+
+}
+
int pcm_submit(void)
{
-#ifdef RBSOUND
- rb->pcm_play_data(pcm.buf,pcm.pos,NULL);
- while(rb->pcm_is_playing()); /* spinlock */
- pcm.pos = 0;
- return 1;
+#ifdef RBSOUND
+ while( (turns < 0) && ((((unsigned int)last_back_pos) + pcm.pos * sizeof(short)) > ((unsigned int)SAR0)) && !newly_started) rb->yield(); /* wait until data is passed through DAC or until exit*/
+ int shorts_left = ((((unsigned int)buf1) + BUF_SIZE) - ((unsigned int)last_back_pos)) / sizeof(short);
+ if( shorts_left >= pcm.pos )
+ {
+ memcpy(last_back_pos,pcm.buf,pcm.pos * sizeof(short));
+ last_back_pos = &last_back_pos[pcm.pos];
+ }
+ else
+ {
+ int last_pos = shorts_left;
+ memcpy(last_back_pos,pcm.buf,shorts_left * sizeof(short));
+ last_back_pos = buf1;
+ shorts_left = pcm.pos - shorts_left;
+ memcpy(last_back_pos,&pcm.buf[last_pos],shorts_left * sizeof(short));
+ last_back_pos = &buf1[shorts_left];
+ turns--;
+ }
+
+ if(newly_started)
+ {
+ rb->pcm_play_data((unsigned char*)buf1,pcm.pos * sizeof(short),&get_more);
+ newly_started = false;
+ }
+
+ pcm.pos = 0;
+ return 1;
#else
- pcm.pos = 0;
- return 0;
+ pcm.pos = 0;
+ return 0;
#endif
}
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c
index a34fd7b..c6d006a 100644
--- a/apps/plugins/rockboy/rockboy.c
+++ b/apps/plugins/rockboy/rockboy.c
@@ -51,6 +51,7 @@ struct plugin_api* rb;
int shut,cleanshut;
char *errormsg;
int gnuboy_main(char *rom);
+void pcm_close(void);
void die(char *message, ...)
{
@@ -124,10 +125,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
rb->splash(HZ*2, true, errormsg);
return PLUGIN_ERROR;
}
-
+ pcm_close();
rb->splash(HZ*2, true, "Shutting down.. byebye ^^");
cleanup();
+
return PLUGIN_OK;
}
diff --git a/apps/plugins/rockboy/sound.c b/apps/plugins/rockboy/sound.c
index edf31d8..10fc504 100644
--- a/apps/plugins/rockboy/sound.c
+++ b/apps/plugins/rockboy/sound.c
@@ -60,9 +60,9 @@ int pcm_submit(void);
#define S4 (snd.ch[3])
rcvar_t sound_exports[] =
- {
- RCV_END
- };
+{
+ RCV_END
+};
static void s1_freq_d(int d)
@@ -275,10 +275,10 @@ void sound_mix(void)
pcm_submit();
if (pcm.stereo)
{
- pcm.buf[pcm.pos++] = l+128;
- pcm.buf[pcm.pos++] = r+128;
+ pcm.buf[pcm.pos++] = (signed short)(l * 256);
+ pcm.buf[pcm.pos++] = (signed short)(r * 256);
}
- else pcm.buf[pcm.pos++] = ((l+r)>>1)+128;
+ else pcm.buf[pcm.pos++] = (signed short)((r+l) * 128);
}
}
R_NR52 = (R_NR52&0xf0) | S1.on | (S2.on<<1) | (S3.on<<2) | (S4.on<<3);