diff options
Diffstat (limited to 'apps/plugins/rockboy/rbsound.c')
-rw-r--r-- | apps/plugins/rockboy/rbsound.c | 64 |
1 files changed, 16 insertions, 48 deletions
diff --git a/apps/plugins/rockboy/rbsound.c b/apps/plugins/rockboy/rbsound.c index e671554e25..163c39aa66 100644 --- a/apps/plugins/rockboy/rbsound.c +++ b/apps/plugins/rockboy/rbsound.c | |||
@@ -5,21 +5,20 @@ | |||
5 | struct pcm pcm IBSS_ATTR; | 5 | struct pcm pcm IBSS_ATTR; |
6 | 6 | ||
7 | #define N_BUFS 2 | 7 | #define N_BUFS 2 |
8 | #define BUF_SIZE 1024 | 8 | #define BUF_SIZE 2048 |
9 | |||
10 | #if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) | ||
11 | 9 | ||
12 | bool doneplay=1; | 10 | bool doneplay=1; |
11 | bool bufnum=0; | ||
13 | 12 | ||
14 | static unsigned char *buf=0; | 13 | static unsigned short *buf=0; |
15 | static unsigned short *gmbuf; | ||
16 | 14 | ||
17 | static bool newly_started; | 15 | static bool newly_started; |
18 | 16 | ||
19 | void get_more(unsigned char** start, size_t* size) | 17 | void get_more(unsigned char** start, size_t* size) |
20 | { | 18 | { |
21 | *start = (unsigned char*)(&gmbuf[pcm.len*doneplay]); | 19 | *start = (unsigned char*)(&buf[pcm.len*doneplay]); |
22 | *size = BUF_SIZE*sizeof(short); | 20 | *size = BUF_SIZE*sizeof(short); |
21 | doneplay=1; | ||
23 | } | 22 | } |
24 | 23 | ||
25 | void pcm_init(void) | 24 | void pcm_init(void) |
@@ -29,19 +28,17 @@ void pcm_init(void) | |||
29 | 28 | ||
30 | newly_started = true; | 29 | newly_started = true; |
31 | 30 | ||
32 | pcm.hz = 11025; | 31 | pcm.hz = SAMPR_44; |
33 | pcm.stereo = 1; | 32 | pcm.stereo = 1; |
34 | 33 | ||
35 | pcm.len = BUF_SIZE; | 34 | pcm.len = BUF_SIZE; |
36 | if(!buf) | 35 | if(!buf) |
37 | { | 36 | { |
38 | buf = my_malloc(pcm.len * N_BUFS); | 37 | buf = my_malloc(pcm.len * N_BUFS *sizeof(short)); |
39 | gmbuf = my_malloc(pcm.len * N_BUFS*sizeof (short)); | ||
40 | 38 | ||
41 | pcm.buf = buf; | 39 | pcm.buf = buf; |
42 | pcm.pos = 0; | 40 | pcm.pos = 0; |
43 | memset(gmbuf, 0, pcm.len * N_BUFS *sizeof(short)); | 41 | memset(buf, 0, pcm.len * N_BUFS*sizeof(short)); |
44 | memset(buf, 0, pcm.len * N_BUFS); | ||
45 | } | 42 | } |
46 | 43 | ||
47 | rb->pcm_play_stop(); | 44 | rb->pcm_play_stop(); |
@@ -52,7 +49,7 @@ void pcm_init(void) | |||
52 | rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); | 49 | rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); |
53 | #endif | 50 | #endif |
54 | 51 | ||
55 | rb->pcm_set_frequency(SAMPR_11); /* 44100 22050 11025 */ | 52 | rb->pcm_set_frequency(pcm.hz); /* 44100 22050 11025 */ |
56 | } | 53 | } |
57 | 54 | ||
58 | void pcm_close(void) | 55 | void pcm_close(void) |
@@ -65,50 +62,21 @@ void pcm_close(void) | |||
65 | 62 | ||
66 | int pcm_submit(void) | 63 | int pcm_submit(void) |
67 | { | 64 | { |
68 | register int i; | 65 | if (!pcm.buf) return 0; |
69 | |||
70 | if (pcm.pos < pcm.len) return 1; | 66 | if (pcm.pos < pcm.len) return 1; |
71 | 67 | ||
72 | doneplay=!doneplay; | ||
73 | |||
74 | if(doneplay) | ||
75 | pcm.buf = buf + pcm.len; | ||
76 | else | ||
77 | pcm.buf = buf; | ||
78 | |||
79 | pcm.pos = 0; | ||
80 | |||
81 | /* gotta convert the 8 bit buffer to 16 */ | ||
82 | for(i=0; i<pcm.len;i++) | ||
83 | gmbuf[i+pcm.len*doneplay] = (pcm.buf[i]<<8)-0x8000; | ||
84 | |||
85 | if(newly_started) | 68 | if(newly_started) |
86 | { | 69 | { |
87 | rb->pcm_play_data(&get_more,NULL,0); | 70 | rb->pcm_play_data(&get_more,NULL,0); |
88 | newly_started = false; | 71 | newly_started = false; |
89 | } | 72 | } |
90 | 73 | ||
91 | return 1; | 74 | while (!doneplay) |
92 | } | 75 | {rb->yield();} |
93 | #else | ||
94 | static byte buf1_unal[(BUF_SIZE / sizeof(short)) + 2]; /* 4 byte aligned */ | ||
95 | void pcm_init(void) | ||
96 | { | ||
97 | pcm.hz = 11025; | ||
98 | pcm.stereo = 1; | ||
99 | pcm.buf = buf1_unal; | ||
100 | pcm.len = (BUF_SIZE / sizeof(short)); | ||
101 | pcm.pos = 0; | ||
102 | } | ||
103 | 76 | ||
104 | void pcm_close(void) | 77 | doneplay=0; |
105 | { | 78 | |
106 | memset(&pcm, 0, sizeof pcm); | 79 | pcm.pos = 0; |
107 | } | 80 | return 1; |
108 | int pcm_submit(void) | ||
109 | { | ||
110 | pcm.pos =0; | ||
111 | return 0; | ||
112 | } | 81 | } |
113 | #endif | ||
114 | 82 | ||