forked from len0rd/rockbox
Added tone and volume control
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@605 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a2b0490060
commit
2f54401455
1 changed files with 120 additions and 26 deletions
|
@ -16,9 +16,13 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "mas.h"
|
#include "mas.h"
|
||||||
|
#include "dac.h"
|
||||||
#include "sh7034.h"
|
#include "sh7034.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
@ -44,6 +48,46 @@
|
||||||
#define MP3_LOW_WATER 0x30000
|
#define MP3_LOW_WATER 0x30000
|
||||||
#define MP3_CHUNK_SIZE 0x20000
|
#define MP3_CHUNK_SIZE 0x20000
|
||||||
|
|
||||||
|
unsigned int bass_table[] =
|
||||||
|
{
|
||||||
|
0,
|
||||||
|
0x800, /* 1dB */
|
||||||
|
0x10000, /* 2dB */
|
||||||
|
0x17c00, /* 3dB */
|
||||||
|
0x1f800, /* 4dB */
|
||||||
|
0x27000, /* 5dB */
|
||||||
|
0x2e400, /* 6dB */
|
||||||
|
0x35800, /* 7dB */
|
||||||
|
0x3c000, /* 8dB */
|
||||||
|
0x42800, /* 9dB */
|
||||||
|
0x48800, /* 10dB */
|
||||||
|
0x4e400, /* 11dB */
|
||||||
|
0x53800, /* 12dB */
|
||||||
|
0x58800, /* 13dB */
|
||||||
|
0x5d400, /* 14dB */
|
||||||
|
0x61800 /* 15dB */
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int treble_table[] =
|
||||||
|
{
|
||||||
|
0,
|
||||||
|
0x5400, /* 1dB */
|
||||||
|
0xac00, /* 2dB */
|
||||||
|
0x10400, /* 3dB */
|
||||||
|
0x16000, /* 4dB */
|
||||||
|
0x1c000, /* 5dB */
|
||||||
|
0x22400, /* 6dB */
|
||||||
|
0x28400, /* 7dB */
|
||||||
|
0x2ec00, /* 8dB */
|
||||||
|
0x35400, /* 9dB */
|
||||||
|
0x3c000, /* 10dB */
|
||||||
|
0x42c00, /* 11dB */
|
||||||
|
0x49c00, /* 12dB */
|
||||||
|
0x51800, /* 13dB */
|
||||||
|
0x58400, /* 14dB */
|
||||||
|
0x5f800 /* 15dB */
|
||||||
|
};
|
||||||
|
|
||||||
unsigned char fliptable[] =
|
unsigned char fliptable[] =
|
||||||
{
|
{
|
||||||
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
||||||
|
@ -87,6 +131,9 @@ extern unsigned int stack[];
|
||||||
|
|
||||||
unsigned char *mp3buf = (unsigned char *)stack;
|
unsigned char *mp3buf = (unsigned char *)stack;
|
||||||
|
|
||||||
|
char *tracks[100];
|
||||||
|
int num_tracks;
|
||||||
|
|
||||||
int mp3buf_write;
|
int mp3buf_write;
|
||||||
int mp3buf_read;
|
int mp3buf_read;
|
||||||
int last_dma_chunk_size;
|
int last_dma_chunk_size;
|
||||||
|
@ -189,7 +236,7 @@ void dma_tick(void)
|
||||||
|
|
||||||
void bitswap(unsigned char *data, int length)
|
void bitswap(unsigned char *data, int length)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
int i;
|
||||||
for(i = 0;i < length;i++)
|
for(i = 0;i < length;i++)
|
||||||
{
|
{
|
||||||
data[i] = fliptable[data[i]];
|
data[i] = fliptable[data[i]];
|
||||||
|
@ -203,6 +250,9 @@ int main(void)
|
||||||
int i=0;
|
int i=0;
|
||||||
DIR *d;
|
DIR *d;
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
|
char *tmp;
|
||||||
|
int volume, bass, treble;
|
||||||
|
unsigned short frame_count;
|
||||||
|
|
||||||
/* Clear it all! */
|
/* Clear it all! */
|
||||||
SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
|
SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
|
||||||
|
@ -272,15 +322,35 @@ int main(void)
|
||||||
i = fat_mount(part[0].start);
|
i = fat_mount(part[0].start);
|
||||||
debugf("fat_mount() returned %d\n", i);
|
debugf("fat_mount() returned %d\n", i);
|
||||||
|
|
||||||
|
num_tracks = 0;
|
||||||
if((d = opendir("/")))
|
if((d = opendir("/")))
|
||||||
{
|
{
|
||||||
while((dent = readdir(d)))
|
while((dent = readdir(d)))
|
||||||
{
|
{
|
||||||
debugf("%s\n", dent->d_name);
|
debugf("%s\n", dent->d_name);
|
||||||
|
i = strlen(dent->d_name);
|
||||||
|
tmp = dent->d_name + i - 4;
|
||||||
|
debugf("%s\n", tmp);
|
||||||
|
if(!stricmp(tmp, ".mp3"))
|
||||||
|
{
|
||||||
|
tmp = malloc(i+1);
|
||||||
|
if(tmp)
|
||||||
|
{
|
||||||
|
debugf("Adding track %s\n", dent->d_name);
|
||||||
|
snprintf(tmp, i+1, "/%s", dent->d_name);
|
||||||
|
tracks[num_tracks++] = tmp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
panicf("Out of memory\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debugf("Number of tracks: %d\n");
|
||||||
|
|
||||||
queue_init(&mpeg_queue);
|
queue_init(&mpeg_queue);
|
||||||
|
|
||||||
create_thread(mpeg_thread, stack - 0x2000, 0x4000);
|
create_thread(mpeg_thread, stack - 0x2000, 0x4000);
|
||||||
|
@ -291,9 +361,24 @@ int main(void)
|
||||||
|
|
||||||
queue_post(&mpeg_queue, MPEG_PLAY, 0);
|
queue_post(&mpeg_queue, MPEG_PLAY, 0);
|
||||||
|
|
||||||
|
volume = 0x2c;
|
||||||
|
|
||||||
|
if(dac_config(0x04) < 0)
|
||||||
|
debugf("DAC write failed\n");
|
||||||
|
|
||||||
|
if(dac_volume(volume) < 0)
|
||||||
|
debugf("DAC write failed\n");
|
||||||
|
|
||||||
|
bass = 12;
|
||||||
|
treble = 8;
|
||||||
|
|
||||||
|
mas_writereg(MAS_REG_KPRESCALE, 0xe9400);
|
||||||
|
mas_writereg(MAS_REG_KBASS, bass_table[bass]);
|
||||||
|
mas_writereg(MAS_REG_KTREBLE, treble_table[treble]);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
sleep(HZ*1000);
|
sleep(HZ*4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,21 +467,24 @@ void IMIA1(void)
|
||||||
TSR1 &= ~0x01;
|
TSR1 &= ~0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tracks[] =
|
int track_index = 0;
|
||||||
{
|
|
||||||
"/machinae_supremacy_-_arcade.mp3"
|
|
||||||
};
|
|
||||||
|
|
||||||
char *peek_next_track(int index)
|
char *peek_next_track(int index)
|
||||||
{
|
{
|
||||||
return tracks[index];
|
if(track_index < num_tracks)
|
||||||
|
return tracks[track_index+index];
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void next_track(void)
|
||||||
|
{
|
||||||
|
track_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mpeg_file = -1;
|
int mpeg_file = -1;
|
||||||
|
|
||||||
int new_file(void)
|
int new_file(void)
|
||||||
{
|
{
|
||||||
int len;
|
|
||||||
char *trackname;
|
char *trackname;
|
||||||
|
|
||||||
trackname = peek_next_track(0);
|
trackname = peek_next_track(0);
|
||||||
|
@ -408,16 +496,6 @@ int new_file(void)
|
||||||
debugf("Couldn't open file\n");
|
debugf("Couldn't open file\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First read in a few seconds worth of MP3 data */
|
|
||||||
len = read(mpeg_file, mp3buf + mp3buf_write, MP3_CHUNK_SIZE);
|
|
||||||
|
|
||||||
ata_spindown(-1);
|
|
||||||
|
|
||||||
bitswap(mp3buf + mp3buf_write, len);
|
|
||||||
|
|
||||||
mp3buf_write = len;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +505,9 @@ void mpeg_thread(void)
|
||||||
int len;
|
int len;
|
||||||
int free_space_left;
|
int free_space_left;
|
||||||
int amount_to_read;
|
int amount_to_read;
|
||||||
|
bool play_pending;
|
||||||
|
|
||||||
|
play_pending = false;
|
||||||
playing = false;
|
playing = false;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
|
@ -438,6 +518,7 @@ void mpeg_thread(void)
|
||||||
{
|
{
|
||||||
case MPEG_PLAY:
|
case MPEG_PLAY:
|
||||||
/* Stop the current stream */
|
/* Stop the current stream */
|
||||||
|
play_pending = false;
|
||||||
playing = false;
|
playing = false;
|
||||||
stop_dma();
|
stop_dma();
|
||||||
|
|
||||||
|
@ -449,10 +530,9 @@ void mpeg_thread(void)
|
||||||
filling = true;
|
filling = true;
|
||||||
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
|
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
|
||||||
|
|
||||||
playing = true;
|
/* Tell the file loading code that we want to start playing
|
||||||
|
as soon as we have some data */
|
||||||
init_dma();
|
play_pending = true;
|
||||||
start_dma();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MPEG_STOP:
|
case MPEG_STOP:
|
||||||
|
@ -475,7 +555,9 @@ void mpeg_thread(void)
|
||||||
|
|
||||||
case MPEG_NEED_DATA:
|
case MPEG_NEED_DATA:
|
||||||
free_space_left = mp3buf_read - mp3buf_write;
|
free_space_left = mp3buf_read - mp3buf_write;
|
||||||
if(free_space_left < 0)
|
|
||||||
|
/* We interpret 0 as "empty buffer" */
|
||||||
|
if(free_space_left <= 0)
|
||||||
free_space_left = MP3BUF_LEN + free_space_left;
|
free_space_left = MP3BUF_LEN + free_space_left;
|
||||||
|
|
||||||
if(free_space_left <= MP3_CHUNK_SIZE)
|
if(free_space_left <= MP3_CHUNK_SIZE)
|
||||||
|
@ -509,6 +591,17 @@ void mpeg_thread(void)
|
||||||
|
|
||||||
/* Tell ourselves that we want more data */
|
/* Tell ourselves that we want more data */
|
||||||
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
|
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
|
||||||
|
|
||||||
|
/* And while we're at it, see if we have startet playing
|
||||||
|
yet. If not, do it. */
|
||||||
|
if(play_pending)
|
||||||
|
{
|
||||||
|
play_pending = false;
|
||||||
|
playing = true;
|
||||||
|
|
||||||
|
init_dma();
|
||||||
|
start_dma();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -518,6 +611,7 @@ void mpeg_thread(void)
|
||||||
boundary */
|
boundary */
|
||||||
mp3buf_write &= 0xfffffffe;
|
mp3buf_write &= 0xfffffffe;
|
||||||
|
|
||||||
|
next_track();
|
||||||
if(new_file() < 0)
|
if(new_file() < 0)
|
||||||
{
|
{
|
||||||
/* No more data to play */
|
/* No more data to play */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue