diff options
Diffstat (limited to 'apps/plugins/rockboy/rbsound.c')
-rw-r--r-- | apps/plugins/rockboy/rbsound.c | 103 |
1 files changed, 35 insertions, 68 deletions
diff --git a/apps/plugins/rockboy/rbsound.c b/apps/plugins/rockboy/rbsound.c index 41d00c1b73..4e61d5590c 100644 --- a/apps/plugins/rockboy/rbsound.c +++ b/apps/plugins/rockboy/rbsound.c | |||
@@ -2,30 +2,14 @@ | |||
2 | #include "defs.h" | 2 | #include "defs.h" |
3 | #include "pcm.h" | 3 | #include "pcm.h" |
4 | 4 | ||
5 | /*#define ONEBUF*/ | ||
6 | /* Note: I think the single buffer implementation is more | ||
7 | * responsive with sound(less lag) but it creates more | ||
8 | * choppyness overall to the sound. 2 buffer's don't seem to | ||
9 | * make a difference, but 4 buffers is definately noticable | ||
10 | */ | ||
11 | |||
12 | struct pcm pcm IBSS_ATTR; | 5 | struct pcm pcm IBSS_ATTR; |
13 | 6 | ||
14 | bool sound = 1; | 7 | #define N_BUFS 2 |
15 | #ifdef ONEBUF | ||
16 | #define N_BUFS 1 | ||
17 | #else | ||
18 | #define N_BUFS 4 | ||
19 | #endif | ||
20 | #define BUF_SIZE 1024 | 8 | #define BUF_SIZE 1024 |
21 | 9 | ||
22 | #if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) | 10 | #if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) |
23 | 11 | ||
24 | #ifndef ONEBUF | 12 | bool doneplay=1; |
25 | static short curbuf,gmcurbuf; | ||
26 | #else | ||
27 | bool doneplay=0; | ||
28 | #endif | ||
29 | 13 | ||
30 | static unsigned char *buf=0; | 14 | static unsigned char *buf=0; |
31 | static unsigned short *gmbuf; | 15 | static unsigned short *gmbuf; |
@@ -34,33 +18,30 @@ static bool newly_started; | |||
34 | 18 | ||
35 | void get_more(unsigned char** start, size_t* size) | 19 | void get_more(unsigned char** start, size_t* size) |
36 | { | 20 | { |
37 | #ifdef ONEBUF | 21 | *start = (unsigned char*)(&gmbuf[pcm.len*doneplay]); |
38 | doneplay=1; | 22 | *size = BUF_SIZE*sizeof(short); |
39 | *start = (unsigned char*)(gmbuf); | ||
40 | #else | ||
41 | *start = (unsigned char*)(&gmbuf[pcm.len*curbuf]); | ||
42 | #endif | ||
43 | *size = BUF_SIZE*sizeof(short); | ||
44 | } | 23 | } |
45 | 24 | ||
46 | void pcm_init(void) | 25 | void pcm_init(void) |
47 | { | 26 | { |
27 | if(plugbuf) | ||
28 | return; | ||
29 | |||
48 | newly_started = true; | 30 | newly_started = true; |
49 | 31 | ||
50 | pcm.hz = 11025; | 32 | pcm.hz = 11025; |
51 | pcm.stereo = 1; | 33 | pcm.stereo = 1; |
52 | 34 | ||
53 | pcm.len = BUF_SIZE; | 35 | pcm.len = BUF_SIZE; |
54 | if(!buf){ | 36 | if(!buf) |
55 | buf = my_malloc(pcm.len * N_BUFS); | 37 | { |
56 | gmbuf = my_malloc(pcm.len * N_BUFS*sizeof (short)); | 38 | buf = my_malloc(pcm.len * N_BUFS); |
57 | pcm.buf = buf; | 39 | gmbuf = my_malloc(pcm.len * N_BUFS*sizeof (short)); |
58 | pcm.pos = 0; | 40 | |
59 | #ifndef ONEBUF | 41 | pcm.buf = buf; |
60 | curbuf = gmcurbuf= 0; | 42 | pcm.pos = 0; |
61 | #endif | 43 | memset(gmbuf, 0, pcm.len * N_BUFS *sizeof(short)); |
62 | memset(gmbuf, 0, pcm.len * N_BUFS *sizeof(short)); | 44 | memset(buf, 0, pcm.len * N_BUFS); |
63 | memset(buf, 0, pcm.len * N_BUFS); | ||
64 | } | 45 | } |
65 | 46 | ||
66 | rb->pcm_play_stop(); | 47 | rb->pcm_play_stop(); |
@@ -75,46 +56,32 @@ void pcm_close(void) | |||
75 | rb->pcm_play_stop(); | 56 | rb->pcm_play_stop(); |
76 | rb->pcm_set_frequency(44100); | 57 | rb->pcm_set_frequency(44100); |
77 | } | 58 | } |
78 | 59 | ||
79 | int pcm_submit(void) | 60 | int pcm_submit(void) |
80 | { | 61 | { |
81 | if (!options.sound) return 1; | ||
82 | register int i; | 62 | register int i; |
83 | 63 | ||
84 | if (!sound) { | 64 | if (pcm.pos < pcm.len) return 1; |
85 | pcm.pos = 0; | ||
86 | return 0; | ||
87 | } | ||
88 | 65 | ||
89 | if (pcm.pos < pcm.len) return 1; | 66 | doneplay=!doneplay; |
90 | 67 | ||
91 | #ifndef ONEBUF | 68 | if(doneplay) |
92 | curbuf = (curbuf + 1) % N_BUFS; | 69 | pcm.buf = buf + pcm.len; |
93 | pcm.buf = buf + pcm.len * curbuf; | 70 | else |
94 | #endif | 71 | pcm.buf = buf; |
95 | pcm.pos = 0; | 72 | |
73 | pcm.pos = 0; | ||
74 | |||
75 | /* gotta convert the 8 bit buffer to 16 */ | ||
76 | for(i=0; i<pcm.len;i++) | ||
77 | gmbuf[i+pcm.len*doneplay] = (pcm.buf[i]<<8)-0x8000; | ||
78 | |||
79 | if(newly_started) | ||
80 | { | ||
81 | rb->pcm_play_data(&get_more,NULL,0); | ||
82 | newly_started = false; | ||
83 | } | ||
96 | 84 | ||
97 | /* gotta convert the 8 bit buffer to 16 */ | ||
98 | for(i=0; i<pcm.len;i++) | ||
99 | #ifdef ONEBUF | ||
100 | gmbuf[i] = (pcm.buf[i]<<8)-0x8000; | ||
101 | #else | ||
102 | gmbuf[i+pcm.len*curbuf] = (pcm.buf[i]<<8)-0x8000; | ||
103 | #endif | ||
104 | |||
105 | if(newly_started) | ||
106 | { | ||
107 | rb->pcm_play_data(&get_more,NULL,0); | ||
108 | newly_started = false; | ||
109 | } | ||
110 | |||
111 | /* this while loop and done play are in place to make sure the sound timing | ||
112 | * is correct(although it's not) | ||
113 | */ | ||
114 | #ifdef ONEBUF | ||
115 | while(doneplay==0) rb->yield(); | ||
116 | doneplay=0; | ||
117 | #endif | ||
118 | return 1; | 85 | return 1; |
119 | } | 86 | } |
120 | #else | 87 | #else |