diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2006-01-10 21:55:56 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2006-01-10 21:55:56 +0000 |
commit | cf218e33eca3abcc1067b9e78f1c82510bfe7c69 (patch) | |
tree | 5f60203774b1080ddfb62092681005d163d4cbb9 /apps/plugins/rockboy/rbsound.c | |
parent | 640eeabfe113695a22bf60ba327210a5526b187d (diff) | |
download | rockbox-cf218e33eca3abcc1067b9e78f1c82510bfe7c69.tar.gz rockbox-cf218e33eca3abcc1067b9e78f1c82510bfe7c69.zip |
Patch #1401999 by Karl Kurbjun - Rockboy color, sound support, and speedups
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8324 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/rockboy/rbsound.c')
-rw-r--r-- | apps/plugins/rockboy/rbsound.c | 102 |
1 files changed, 37 insertions, 65 deletions
diff --git a/apps/plugins/rockboy/rbsound.c b/apps/plugins/rockboy/rbsound.c index 139c33d037..b68a053f77 100644 --- a/apps/plugins/rockboy/rbsound.c +++ b/apps/plugins/rockboy/rbsound.c | |||
@@ -5,117 +5,89 @@ | |||
5 | 5 | ||
6 | struct pcm pcm; | 6 | struct pcm pcm; |
7 | 7 | ||
8 | #define BUF_SIZE (8192) | 8 | bool sound = 1; |
9 | #define DMA_PORTION (1024) | 9 | #define N_BUFS 4 |
10 | 10 | #define BUF_SIZE 1024 | |
11 | static short buf1_unal[(BUF_SIZE / sizeof(short)) + 2]; // to make sure 4 byte aligned | ||
12 | 11 | ||
13 | rcvar_t pcm_exports[] = | 12 | rcvar_t pcm_exports[] = |
14 | { | 13 | { |
15 | RCV_END | 14 | RCV_END |
16 | }; | 15 | }; |
17 | 16 | ||
18 | /*#if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) | 17 | #if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) |
19 | * disabled cause it crashes with current audio implementation.. no sound. | ||
20 | */ | ||
21 | #if 0 | ||
22 | static short* buf1; | ||
23 | 18 | ||
24 | static short front_buf[512]; | 19 | static int curbuf,gmcurbuf; |
25 | 20 | ||
26 | static short* last_back_pos; | 21 | static byte *buf=0; |
22 | static short *gmbuf; | ||
27 | 23 | ||
28 | static bool newly_started; | 24 | static bool newly_started; |
29 | static int turns; | ||
30 | 25 | ||
31 | void pcm_init(void) | 26 | void pcm_init(void) |
32 | { | 27 | { |
33 | buf1 = (signed short*)((((unsigned int)buf1_unal) >> 2) << 2); /* here i just make sure that buffer is aligned to 4 bytes*/ | 28 | if(!sound) return; |
29 | |||
34 | newly_started = true; | 30 | newly_started = true; |
35 | last_back_pos = buf1; | ||
36 | turns = 0; | ||
37 | 31 | ||
38 | pcm.hz = 11025; | 32 | pcm.hz = 11025; |
39 | pcm.stereo = 1; | 33 | pcm.stereo = 1; |
40 | pcm.buf = front_buf; | ||
41 | pcm.len = (sizeof(front_buf)) / sizeof(short); /* length in shorts, not bytes */ | ||
42 | pcm.pos = 0; | ||
43 | 34 | ||
35 | pcm.len = BUF_SIZE; | ||
36 | if(!buf){ | ||
37 | buf = my_malloc(pcm.len * N_BUFS); | ||
38 | gmbuf = my_malloc(pcm.len * N_BUFS*sizeof (short)); | ||
39 | pcm.buf = buf; | ||
40 | pcm.pos = 0; | ||
41 | curbuf = gmcurbuf= 0; | ||
42 | } | ||
44 | 43 | ||
45 | rb->pcm_play_stop(); | 44 | rb->pcm_play_stop(); |
46 | rb->pcm_set_frequency(11025); | 45 | rb->pcm_set_frequency(11025); // 44100 22050 11025 |
47 | rb->pcm_set_volume(200); | ||
48 | } | 46 | } |
49 | 47 | ||
50 | void pcm_close(void) | 48 | void pcm_close(void) |
51 | { | 49 | { |
52 | memset(&pcm, 0, sizeof pcm); | 50 | memset(&pcm, 0, sizeof pcm); |
53 | newly_started = true; | 51 | newly_started = true; |
54 | last_back_pos = buf1; | ||
55 | rb->pcm_play_stop(); | 52 | rb->pcm_play_stop(); |
53 | rb->pcm_set_frequency(44100); | ||
56 | } | 54 | } |
57 | 55 | ||
58 | void get_more(unsigned char** start, long* size) | 56 | void get_more(unsigned char** start, long* size) |
59 | { | 57 | { |
60 | int length; | 58 | *start = (unsigned char*)(&gmbuf[pcm.len*curbuf]); |
61 | unsigned int sar = (unsigned int)SAR0; | 59 | *size = BUF_SIZE*sizeof(short); |
62 | length = ((unsigned int)buf1) + BUF_SIZE - sar; | ||
63 | |||
64 | if(turns > 0) | ||
65 | { | ||
66 | newly_started = true; | ||
67 | last_back_pos = buf1; | ||
68 | turns = 0; | ||
69 | return; | ||
70 | } /* sound will stop if no one feeds data*/ | ||
71 | |||
72 | if(length <= 0) | ||
73 | { | ||
74 | *start = (unsigned char*)buf1; | ||
75 | *size = DMA_PORTION; | ||
76 | turns++; | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | *start = (unsigned char*)sar; | ||
81 | if(length > DMA_PORTION) | ||
82 | *size = DMA_PORTION; | ||
83 | else | ||
84 | *size = length; | ||
85 | } | ||
86 | |||
87 | } | 60 | } |
88 | 61 | ||
89 | int pcm_submit(void) | 62 | int pcm_submit(void) |
90 | { | 63 | { |
91 | 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*/ | 64 | register int i; |
92 | int shorts_left = ((((unsigned int)buf1) + BUF_SIZE) - ((unsigned int)last_back_pos)) / sizeof(short); | 65 | |
93 | if( shorts_left >= pcm.pos ) | 66 | if (!sound) { |
94 | { | 67 | pcm.pos = 0; |
95 | memcpy(last_back_pos,pcm.buf,pcm.pos * sizeof(short)); | 68 | return 0; |
96 | last_back_pos = &last_back_pos[pcm.pos]; | ||
97 | } | 69 | } |
98 | else | 70 | |
99 | { | 71 | if (pcm.pos >= pcm.len) { |
100 | int last_pos = shorts_left; | 72 | curbuf = (curbuf + 1) % N_BUFS; |
101 | memcpy(last_back_pos,pcm.buf,shorts_left * sizeof(short)); | 73 | pcm.buf = buf + pcm.len * curbuf; |
102 | last_back_pos = buf1; | 74 | pcm.pos = 0; |
103 | shorts_left = pcm.pos - shorts_left; | 75 | |
104 | memcpy(last_back_pos,&pcm.buf[last_pos],shorts_left * sizeof(short)); | 76 | // gotta convert the 8 bit buffer to 16 |
105 | last_back_pos = &buf1[shorts_left]; | 77 | for(i=0; i<pcm.len;i++) |
106 | turns--; | 78 | gmbuf[i+pcm.len*curbuf] = (pcm.buf[i]<<8)-0x8000; |
107 | } | 79 | } |
108 | 80 | ||
109 | if(newly_started) | 81 | if(newly_started) |
110 | { | 82 | { |
111 | rb->pcm_play_data((unsigned char*)buf1,pcm.pos * sizeof(short),&get_more); | 83 | rb->pcm_play_data(&get_more); |
112 | newly_started = false; | 84 | newly_started = false; |
113 | } | 85 | } |
114 | 86 | ||
115 | pcm.pos = 0; | ||
116 | return 1; | 87 | return 1; |
117 | } | 88 | } |
118 | #else | 89 | #else |
90 | static byte buf1_unal[(BUF_SIZE / sizeof(short)) + 2]; // to make sure 4 byte aligned | ||
119 | void pcm_init(void) | 91 | void pcm_init(void) |
120 | { | 92 | { |
121 | pcm.hz = 11025; | 93 | pcm.hz = 11025; |