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