2005-03-02 23:49:38 +00:00
|
|
|
#include "rockmacros.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "pcm.h"
|
|
|
|
#include "rc.h"
|
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
//#define ONEBUF // Note: I think the single buffer implementation is more responsive with sound(less lag)
|
|
|
|
// but it creates more choppyness overall to the sound. 2 buffer's don't seem to make
|
|
|
|
// a difference, but 4 buffers is definately noticable
|
|
|
|
|
|
|
|
struct pcm pcm IBSS_ATTR;
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2006-01-10 21:55:56 +00:00
|
|
|
bool sound = 1;
|
2006-01-20 13:05:52 +00:00
|
|
|
#ifdef ONEBUF
|
|
|
|
#define N_BUFS 1
|
|
|
|
#else
|
2006-01-10 21:55:56 +00:00
|
|
|
#define N_BUFS 4
|
2006-01-20 13:05:52 +00:00
|
|
|
#endif
|
2006-01-10 21:55:56 +00:00
|
|
|
#define BUF_SIZE 1024
|
2005-03-28 00:27:49 +00:00
|
|
|
|
|
|
|
rcvar_t pcm_exports[] =
|
|
|
|
{
|
|
|
|
RCV_END
|
|
|
|
};
|
|
|
|
|
2006-01-10 21:55:56 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR)
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
#ifndef ONEBUF
|
|
|
|
static short curbuf,gmcurbuf;
|
|
|
|
#else
|
|
|
|
bool doneplay=0;
|
|
|
|
#endif
|
2005-03-28 00:00:24 +00:00
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
static unsigned char *buf=0;
|
|
|
|
static unsigned short *gmbuf;
|
2005-03-28 00:00:24 +00:00
|
|
|
|
|
|
|
static bool newly_started;
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2006-02-07 20:38:55 +00:00
|
|
|
void get_more(unsigned char** start, size_t* size)
|
2006-01-20 13:05:52 +00:00
|
|
|
{
|
|
|
|
#ifdef ONEBUF
|
|
|
|
doneplay=1;
|
|
|
|
*start = (unsigned char*)(gmbuf);
|
|
|
|
#else
|
|
|
|
*start = (unsigned char*)(&gmbuf[pcm.len*curbuf]);
|
|
|
|
#endif
|
|
|
|
*size = BUF_SIZE*sizeof(short);
|
|
|
|
}
|
|
|
|
|
2005-03-02 23:49:38 +00:00
|
|
|
void pcm_init(void)
|
|
|
|
{
|
2006-01-10 21:55:56 +00:00
|
|
|
if(!sound) return;
|
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
newly_started = true;
|
2005-03-28 00:00:24 +00:00
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
pcm.hz = 11025;
|
|
|
|
pcm.stereo = 1;
|
2005-03-28 00:00:24 +00:00
|
|
|
|
2006-01-10 21:55:56 +00:00
|
|
|
pcm.len = BUF_SIZE;
|
|
|
|
if(!buf){
|
2006-01-20 13:05:52 +00:00
|
|
|
buf = my_malloc(pcm.len * N_BUFS);
|
|
|
|
gmbuf = my_malloc(pcm.len * N_BUFS*sizeof (short));
|
|
|
|
pcm.buf = buf;
|
|
|
|
pcm.pos = 0;
|
|
|
|
#ifndef ONEBUF
|
|
|
|
curbuf = gmcurbuf= 0;
|
|
|
|
#endif
|
|
|
|
memset(gmbuf, 0, pcm.len * N_BUFS *sizeof(short));
|
|
|
|
memset(buf, 0, pcm.len * N_BUFS);
|
2006-01-10 21:55:56 +00:00
|
|
|
}
|
2006-01-20 13:05:52 +00:00
|
|
|
|
|
|
|
rb->pcm_play_stop();
|
|
|
|
|
|
|
|
rb->pcm_set_frequency(11025); // 44100 22050 11025
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_close(void)
|
|
|
|
{
|
2006-01-20 13:05:52 +00:00
|
|
|
memset(&pcm, 0, sizeof pcm);
|
|
|
|
newly_started = true;
|
|
|
|
rb->pcm_play_stop();
|
2006-01-10 21:55:56 +00:00
|
|
|
rb->pcm_set_frequency(44100);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
2005-03-28 00:00:24 +00:00
|
|
|
|
2005-03-02 23:49:38 +00:00
|
|
|
int pcm_submit(void)
|
|
|
|
{
|
2006-01-10 21:55:56 +00:00
|
|
|
register int i;
|
|
|
|
|
|
|
|
if (!sound) {
|
|
|
|
pcm.pos = 0;
|
|
|
|
return 0;
|
2006-01-20 13:05:52 +00:00
|
|
|
}
|
2006-01-10 21:55:56 +00:00
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
if (pcm.pos < pcm.len) return 1;
|
2006-01-10 21:55:56 +00:00
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
#ifndef ONEBUF
|
|
|
|
curbuf = (curbuf + 1) % N_BUFS;
|
|
|
|
pcm.buf = buf + pcm.len * curbuf;
|
|
|
|
#endif
|
|
|
|
pcm.pos = 0;
|
|
|
|
|
|
|
|
// gotta convert the 8 bit buffer to 16
|
|
|
|
for(i=0; i<pcm.len;i++)
|
|
|
|
#ifdef ONEBUF
|
|
|
|
gmbuf[i] = (pcm.buf[i]<<8)-0x8000;
|
|
|
|
#else
|
|
|
|
gmbuf[i+pcm.len*curbuf] = (pcm.buf[i]<<8)-0x8000;
|
|
|
|
#endif
|
2005-03-28 00:00:24 +00:00
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
if(newly_started)
|
|
|
|
{
|
2006-02-07 20:38:55 +00:00
|
|
|
rb->pcm_play_data(&get_more,NULL,0);
|
2006-01-20 13:05:52 +00:00
|
|
|
newly_started = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this while loop and done play are in place to make sure the sound timing is correct(although it's not)
|
|
|
|
#ifdef ONEBUF
|
|
|
|
while(doneplay==0) rb->yield();
|
|
|
|
doneplay=0;
|
|
|
|
#endif
|
|
|
|
return 1;
|
2005-03-28 00:27:49 +00:00
|
|
|
}
|
2005-03-20 23:06:47 +00:00
|
|
|
#else
|
2006-01-10 21:55:56 +00:00
|
|
|
static byte buf1_unal[(BUF_SIZE / sizeof(short)) + 2]; // to make sure 4 byte aligned
|
2005-03-28 00:27:49 +00:00
|
|
|
void pcm_init(void)
|
|
|
|
{
|
|
|
|
pcm.hz = 11025;
|
|
|
|
pcm.stereo = 1;
|
|
|
|
pcm.buf = buf1_unal;
|
|
|
|
pcm.len = (BUF_SIZE / sizeof(short));
|
2005-03-28 00:00:24 +00:00
|
|
|
pcm.pos = 0;
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
2005-03-28 00:27:49 +00:00
|
|
|
void pcm_close(void)
|
|
|
|
{
|
|
|
|
memset(&pcm, 0, sizeof pcm);
|
|
|
|
}
|
|
|
|
int pcm_submit(void)
|
|
|
|
{
|
|
|
|
pcm.pos =0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2005-03-02 23:49:38 +00:00
|
|
|
|