2005-03-02 23:49:38 +00:00
|
|
|
#include "rockmacros.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "pcm.h"
|
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
struct pcm pcm IBSS_ATTR;
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2007-04-18 07:41:31 +00:00
|
|
|
#define N_BUFS 2
|
2007-06-24 16:00:55 +00:00
|
|
|
#define BUF_SIZE 2048
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2007-06-24 22:49:59 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
|
2007-04-18 07:41:31 +00:00
|
|
|
bool doneplay=1;
|
2007-06-24 16:00:55 +00:00
|
|
|
bool bufnum=0;
|
2005-03-28 00:00:24 +00:00
|
|
|
|
2007-07-21 04:00:58 +00:00
|
|
|
static unsigned short *buf=0, *hwbuf=0;
|
2005-03-28 00:00:24 +00:00
|
|
|
|
|
|
|
static bool newly_started;
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
static void get_more(const void** start, size_t* size)
|
2006-01-20 13:05:52 +00:00
|
|
|
{
|
2007-07-21 04:00:58 +00:00
|
|
|
memcpy(hwbuf, &buf[pcm.len*doneplay], BUF_SIZE*sizeof(short));
|
2012-02-23 13:14:46 +00:00
|
|
|
*start = hwbuf;
|
2007-04-18 07:41:31 +00:00
|
|
|
*size = BUF_SIZE*sizeof(short);
|
2007-06-24 16:00:55 +00:00
|
|
|
doneplay=1;
|
2006-01-20 13:05:52 +00:00
|
|
|
}
|
|
|
|
|
2010-05-27 12:00:23 +00:00
|
|
|
void rockboy_pcm_init(void)
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
2007-04-18 07:41:31 +00:00
|
|
|
if(plugbuf)
|
|
|
|
return;
|
|
|
|
|
2007-02-06 21:41:08 +00:00
|
|
|
newly_started = true;
|
2007-07-21 04:00:58 +00:00
|
|
|
|
|
|
|
#if defined(HW_HAVE_11) && !defined(TOSHIBA_GIGABEAT_F)
|
|
|
|
pcm.hz = SAMPR_11;
|
|
|
|
#else
|
2007-06-24 16:00:55 +00:00
|
|
|
pcm.hz = SAMPR_44;
|
2007-07-21 04:00:58 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-06 21:41:08 +00:00
|
|
|
pcm.stereo = 1;
|
2005-03-28 00:00:24 +00:00
|
|
|
|
2007-02-06 21:41:08 +00:00
|
|
|
pcm.len = BUF_SIZE;
|
2007-04-18 07:41:31 +00:00
|
|
|
if(!buf)
|
|
|
|
{
|
2007-06-24 16:00:55 +00:00
|
|
|
buf = my_malloc(pcm.len * N_BUFS *sizeof(short));
|
2007-07-21 04:00:58 +00:00
|
|
|
hwbuf = my_malloc(pcm.len *sizeof(short));
|
2007-04-18 07:41:31 +00:00
|
|
|
|
|
|
|
pcm.buf = buf;
|
|
|
|
pcm.pos = 0;
|
2007-06-24 16:00:55 +00:00
|
|
|
memset(buf, 0, pcm.len * N_BUFS*sizeof(short));
|
2007-02-06 21:41:08 +00:00
|
|
|
}
|
2006-01-20 13:05:52 +00:00
|
|
|
|
2007-02-06 21:41:08 +00:00
|
|
|
rb->pcm_play_stop();
|
2007-06-10 02:10:47 +00:00
|
|
|
|
|
|
|
#if INPUT_SRC_CAPS != 0
|
|
|
|
/* Select playback */
|
|
|
|
rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
|
|
|
|
rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);
|
|
|
|
#endif
|
2006-01-20 13:05:52 +00:00
|
|
|
|
2007-06-24 16:00:55 +00:00
|
|
|
rb->pcm_set_frequency(pcm.hz); /* 44100 22050 11025 */
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
2010-05-27 12:00:23 +00:00
|
|
|
void rockboy_pcm_close(void)
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
2007-02-06 21:41:08 +00:00
|
|
|
memset(&pcm, 0, sizeof pcm);
|
|
|
|
newly_started = true;
|
|
|
|
rb->pcm_play_stop();
|
2007-06-10 02:10:47 +00:00
|
|
|
rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
2007-04-18 07:41:31 +00:00
|
|
|
|
2010-05-27 12:00:23 +00:00
|
|
|
int rockboy_pcm_submit(void)
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
2007-06-24 16:00:55 +00:00
|
|
|
if (!pcm.buf) return 0;
|
2007-04-18 07:41:31 +00:00
|
|
|
if (pcm.pos < pcm.len) return 1;
|
2006-01-10 21:55:56 +00:00
|
|
|
|
2007-04-18 07:41:31 +00:00
|
|
|
if(newly_started)
|
|
|
|
{
|
2012-02-23 13:14:46 +00:00
|
|
|
rb->pcm_play_data(&get_more, NULL, NULL,0);
|
2007-04-18 07:41:31 +00:00
|
|
|
newly_started = false;
|
|
|
|
}
|
2006-01-20 13:05:52 +00:00
|
|
|
|
2007-06-24 16:00:55 +00:00
|
|
|
while (!doneplay)
|
|
|
|
{rb->yield();}
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2007-06-24 16:00:55 +00:00
|
|
|
doneplay=0;
|
|
|
|
|
|
|
|
pcm.pos = 0;
|
|
|
|
return 1;
|
2005-03-28 00:27:49 +00:00
|
|
|
}
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2007-06-24 22:49:59 +00:00
|
|
|
#else
|
|
|
|
|
2010-05-27 12:00:23 +00:00
|
|
|
void rockboy_pcm_init(void)
|
2007-06-24 22:49:59 +00:00
|
|
|
{
|
|
|
|
pcm.hz = 44100;
|
|
|
|
pcm.stereo = 1;
|
|
|
|
pcm.buf = NULL;
|
|
|
|
pcm.len = 0;
|
|
|
|
pcm.pos = 0;
|
|
|
|
}
|
|
|
|
|
2010-05-27 12:00:23 +00:00
|
|
|
void rockboy_pcm_close(void)
|
2007-06-24 22:49:59 +00:00
|
|
|
{
|
|
|
|
memset(&pcm, 0, sizeof pcm);
|
|
|
|
}
|
|
|
|
|
2010-05-27 12:00:23 +00:00
|
|
|
int rockboy_pcm_submit(void)
|
2007-06-24 22:49:59 +00:00
|
|
|
{
|
|
|
|
pcm.pos =0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|