summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-05-16 21:11:21 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-05-16 21:11:21 +0000
commit2f54401455ab5b27e134d6739e1ef4e5edcc4dbc (patch)
tree1966bdc5d8b3e6e6072f939d81a5f8fd6b0f8c38 /firmware
parenta2b049006067e47880fae51ff637d5c8021d1683 (diff)
downloadrockbox-2f54401455ab5b27e134d6739e1ef4e5edcc4dbc.tar.gz
rockbox-2f54401455ab5b27e134d6739e1ef4e5edcc4dbc.zip
Added tone and volume control
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@605 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/test/i2c/main.c144
1 files changed, 119 insertions, 25 deletions
diff --git a/firmware/test/i2c/main.c b/firmware/test/i2c/main.c
index 43d3ef31d3..34d3dc68e2 100644
--- a/firmware/test/i2c/main.c
+++ b/firmware/test/i2c/main.c
@@ -16,9 +16,13 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19#include <stdio.h>
20#include <stdlib.h>
19#include <stdbool.h> 21#include <stdbool.h>
22#include <string.h>
20#include "i2c.h" 23#include "i2c.h"
21#include "mas.h" 24#include "mas.h"
25#include "dac.h"
22#include "sh7034.h" 26#include "sh7034.h"
23#include "system.h" 27#include "system.h"
24#include "debug.h" 28#include "debug.h"
@@ -44,6 +48,46 @@
44#define MP3_LOW_WATER 0x30000 48#define MP3_LOW_WATER 0x30000
45#define MP3_CHUNK_SIZE 0x20000 49#define MP3_CHUNK_SIZE 0x20000
46 50
51unsigned int bass_table[] =
52{
53 0,
54 0x800, /* 1dB */
55 0x10000, /* 2dB */
56 0x17c00, /* 3dB */
57 0x1f800, /* 4dB */
58 0x27000, /* 5dB */
59 0x2e400, /* 6dB */
60 0x35800, /* 7dB */
61 0x3c000, /* 8dB */
62 0x42800, /* 9dB */
63 0x48800, /* 10dB */
64 0x4e400, /* 11dB */
65 0x53800, /* 12dB */
66 0x58800, /* 13dB */
67 0x5d400, /* 14dB */
68 0x61800 /* 15dB */
69};
70
71unsigned int treble_table[] =
72{
73 0,
74 0x5400, /* 1dB */
75 0xac00, /* 2dB */
76 0x10400, /* 3dB */
77 0x16000, /* 4dB */
78 0x1c000, /* 5dB */
79 0x22400, /* 6dB */
80 0x28400, /* 7dB */
81 0x2ec00, /* 8dB */
82 0x35400, /* 9dB */
83 0x3c000, /* 10dB */
84 0x42c00, /* 11dB */
85 0x49c00, /* 12dB */
86 0x51800, /* 13dB */
87 0x58400, /* 14dB */
88 0x5f800 /* 15dB */
89};
90
47unsigned char fliptable[] = 91unsigned char fliptable[] =
48{ 92{
49 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 93 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
@@ -87,6 +131,9 @@ extern unsigned int stack[];
87 131
88unsigned char *mp3buf = (unsigned char *)stack; 132unsigned char *mp3buf = (unsigned char *)stack;
89 133
134char *tracks[100];
135int num_tracks;
136
90int mp3buf_write; 137int mp3buf_write;
91int mp3buf_read; 138int mp3buf_read;
92int last_dma_chunk_size; 139int last_dma_chunk_size;
@@ -189,7 +236,7 @@ void dma_tick(void)
189 236
190void bitswap(unsigned char *data, int length) 237void bitswap(unsigned char *data, int length)
191{ 238{
192 unsigned int i; 239 int i;
193 for(i = 0;i < length;i++) 240 for(i = 0;i < length;i++)
194 { 241 {
195 data[i] = fliptable[data[i]]; 242 data[i] = fliptable[data[i]];
@@ -203,6 +250,9 @@ int main(void)
203 int i=0; 250 int i=0;
204 DIR *d; 251 DIR *d;
205 struct dirent *dent; 252 struct dirent *dent;
253 char *tmp;
254 int volume, bass, treble;
255 unsigned short frame_count;
206 256
207 /* Clear it all! */ 257 /* Clear it all! */
208 SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER); 258 SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
@@ -271,16 +321,36 @@ int main(void)
271 321
272 i = fat_mount(part[0].start); 322 i = fat_mount(part[0].start);
273 debugf("fat_mount() returned %d\n", i); 323 debugf("fat_mount() returned %d\n", i);
274 324
325 num_tracks = 0;
275 if((d = opendir("/"))) 326 if((d = opendir("/")))
276 { 327 {
277 while((dent = readdir(d))) 328 while((dent = readdir(d)))
278 { 329 {
279 debugf("%s\n", dent->d_name); 330 debugf("%s\n", dent->d_name);
331 i = strlen(dent->d_name);
332 tmp = dent->d_name + i - 4;
333 debugf("%s\n", tmp);
334 if(!stricmp(tmp, ".mp3"))
335 {
336 tmp = malloc(i+1);
337 if(tmp)
338 {
339 debugf("Adding track %s\n", dent->d_name);
340 snprintf(tmp, i+1, "/%s", dent->d_name);
341 tracks[num_tracks++] = tmp;
342 }
343 else
344 {
345 panicf("Out of memory\n");
346 }
347 }
280 } 348 }
281 closedir(d); 349 closedir(d);
282 } 350 }
283 351
352 debugf("Number of tracks: %d\n");
353
284 queue_init(&mpeg_queue); 354 queue_init(&mpeg_queue);
285 355
286 create_thread(mpeg_thread, stack - 0x2000, 0x4000); 356 create_thread(mpeg_thread, stack - 0x2000, 0x4000);
@@ -290,10 +360,25 @@ int main(void)
290 debugf("let's play...\n"); 360 debugf("let's play...\n");
291 361
292 queue_post(&mpeg_queue, MPEG_PLAY, 0); 362 queue_post(&mpeg_queue, MPEG_PLAY, 0);
363
364 volume = 0x2c;
365
366 if(dac_config(0x04) < 0)
367 debugf("DAC write failed\n");
368
369 if(dac_volume(volume) < 0)
370 debugf("DAC write failed\n");
371
372 bass = 12;
373 treble = 8;
374
375 mas_writereg(MAS_REG_KPRESCALE, 0xe9400);
376 mas_writereg(MAS_REG_KBASS, bass_table[bass]);
377 mas_writereg(MAS_REG_KTREBLE, treble_table[treble]);
293 378
294 while(1) 379 while(1)
295 { 380 {
296 sleep(HZ*1000); 381 sleep(HZ*4);
297 } 382 }
298} 383}
299 384
@@ -382,21 +467,24 @@ void IMIA1(void)
382 TSR1 &= ~0x01; 467 TSR1 &= ~0x01;
383} 468}
384 469
385char *tracks[] = 470int track_index = 0;
471char *peek_next_track(int index)
386{ 472{
387 "/machinae_supremacy_-_arcade.mp3" 473 if(track_index < num_tracks)
388}; 474 return tracks[track_index+index];
475 else
476 return NULL;
477}
389 478
390char *peek_next_track(int index) 479void next_track(void)
391{ 480{
392 return tracks[index]; 481 track_index++;
393} 482}
394 483
395int mpeg_file = -1; 484int mpeg_file = -1;
396 485
397int new_file(void) 486int new_file(void)
398{ 487{
399 int len;
400 char *trackname; 488 char *trackname;
401 489
402 trackname = peek_next_track(0); 490 trackname = peek_next_track(0);
@@ -408,16 +496,6 @@ int new_file(void)
408 debugf("Couldn't open file\n"); 496 debugf("Couldn't open file\n");
409 return -1; 497 return -1;
410 } 498 }
411
412 /* First read in a few seconds worth of MP3 data */
413 len = read(mpeg_file, mp3buf + mp3buf_write, MP3_CHUNK_SIZE);
414
415 ata_spindown(-1);
416
417 bitswap(mp3buf + mp3buf_write, len);
418
419 mp3buf_write = len;
420
421 return 0; 499 return 0;
422} 500}
423 501
@@ -427,7 +505,9 @@ void mpeg_thread(void)
427 int len; 505 int len;
428 int free_space_left; 506 int free_space_left;
429 int amount_to_read; 507 int amount_to_read;
508 bool play_pending;
430 509
510 play_pending = false;
431 playing = false; 511 playing = false;
432 512
433 while(1) 513 while(1)
@@ -438,6 +518,7 @@ void mpeg_thread(void)
438 { 518 {
439 case MPEG_PLAY: 519 case MPEG_PLAY:
440 /* Stop the current stream */ 520 /* Stop the current stream */
521 play_pending = false;
441 playing = false; 522 playing = false;
442 stop_dma(); 523 stop_dma();
443 524
@@ -449,10 +530,9 @@ void mpeg_thread(void)
449 filling = true; 530 filling = true;
450 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); 531 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
451 532
452 playing = true; 533 /* Tell the file loading code that we want to start playing
453 534 as soon as we have some data */
454 init_dma(); 535 play_pending = true;
455 start_dma();
456 break; 536 break;
457 537
458 case MPEG_STOP: 538 case MPEG_STOP:
@@ -475,7 +555,9 @@ void mpeg_thread(void)
475 555
476 case MPEG_NEED_DATA: 556 case MPEG_NEED_DATA:
477 free_space_left = mp3buf_read - mp3buf_write; 557 free_space_left = mp3buf_read - mp3buf_write;
478 if(free_space_left < 0) 558
559 /* We interpret 0 as "empty buffer" */
560 if(free_space_left <= 0)
479 free_space_left = MP3BUF_LEN + free_space_left; 561 free_space_left = MP3BUF_LEN + free_space_left;
480 562
481 if(free_space_left <= MP3_CHUNK_SIZE) 563 if(free_space_left <= MP3_CHUNK_SIZE)
@@ -509,6 +591,17 @@ void mpeg_thread(void)
509 591
510 /* Tell ourselves that we want more data */ 592 /* Tell ourselves that we want more data */
511 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); 593 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
594
595 /* And while we're at it, see if we have startet playing
596 yet. If not, do it. */
597 if(play_pending)
598 {
599 play_pending = false;
600 playing = true;
601
602 init_dma();
603 start_dma();
604 }
512 } 605 }
513 else 606 else
514 { 607 {
@@ -517,7 +610,8 @@ void mpeg_thread(void)
517 /* Make sure that the write pointer is at a word 610 /* Make sure that the write pointer is at a word
518 boundary */ 611 boundary */
519 mp3buf_write &= 0xfffffffe; 612 mp3buf_write &= 0xfffffffe;
520 613
614 next_track();
521 if(new_file() < 0) 615 if(new_file() < 0)
522 { 616 {
523 /* No more data to play */ 617 /* No more data to play */