Hi, i'm working on a new rockbox plugin based on vgmstream (
http://sourceforge.net/projects/vgmstream/),
the plugin is based on the mikmod and midi plugins, and uses the pcm_play_data api.
Some videogame streams has has some weird sampling rates, like 37800 Hz. I am calling pcm_set_frequency, but it seems it only supports some sampling rates. So i was wondering if i can use the dsp resampler to get the closest sampling rate possible. But i'm not sure if i can use the dsp in combination with the pcm api, and how to setup the required dsp buffers for dsp_process. Anyone can help, please?
Post Merge: May 14, 2012, 09:43:27 PM
Ok, made some progress, the code is very dirty, i'm only doing some tests with the dsp. This is the get_more callbak used by pcm_play_data:
unsigned char dspbuffer[BUF_SIZE * 2 * 2];
static int dspbuffer_count = BUF_SIZE ;
static void get_more(const void** start, size_t* size)
{
#ifndef SYNC
if (lastswap != swap)
{
//DEBUGF("Buffer miss!");
}
#else
synthbuf();
#endif
/* process dsp */
src.remcount = BUF_SIZE;
src.pin[0] = gmbuf;
src.pin[1] = gmbuf;
src.proc_mask = 0;
struct dsp_buffer dst;
dst.remcount = 0;
dst.p16out = (int16_t *)dspbuffer;
dst.bufcount = dspbuffer_count;
while (1)
{
int old_remcount = dst.remcount;
rb->dsp_process(dsp, &src, &dst);
if (dst.bufcount <= 0 ||
(src.remcount <= 0 && dst.remcount <= old_remcount))
{
/* Dest is full or no input left and DSP purged */
break;
}
}
//*size = BUF_SIZE;
*size = dst.remcount >> 1;
#ifndef SYNC
*start = swap ? gmbuf : gmbuf + BUF_SIZE;
swap = !swap;
#else
//*start = gmbuf;
*start = dspbuffer;
#endif
}
The dsp is configured like this:
/* configure dsp */
dsp = rb->dsp_get_config(CODEC_IDX_AUDIO);
rb->dsp_configure(dsp, DSP_RESET, 0);
rb->dsp_configure(dsp, DSP_FLUSH, 0);
rb->dsp_configure(dsp, DSP_SWITCH_FREQUENCY, streamfile->sample_rate);
rb->dsp_configure(dsp, DSP_SET_STEREO_MODE,
streamfile->channels == 1 ? STEREO_MONO : STEREO_NONINTERLEAVED);
streamfile is an VGMSTREAM object from the vgmstream api, and the samples are rendered here:
static inline void synthbuf(void)
{
char *outptr;
#ifndef SYNC
if (lastswap == swap) return;
lastswap = swap;
outptr = (swap ? gmbuf : gmbuf + BUF_SIZE);
#else
outptr = gmbuf;
#endif
/* have we finished decoding? */
current_sample += BUF_SIZE / (channels << 1);
if( current_sample >= total_samples ) {
exit_flag = 1;
return;
}
render_vgmstream((sample *)gmbuf, BUF_SIZE / (channels << 1), streamfile);
// playingtime += (BUF_SIZE / (channels << 1)) / 44.1;
}
The results, i can hear the music, but is sounds very noise and laggy. Whithout the dsp code, the plugin works fine, except that the sampling frequency is set to 44100, and the song plays too fast. My first question is, how do i setup the src buffer correctly?, i need to pass a pointer to each channel, but i only have an stereo samples buffer.
Well hope someone can take a look at the code and point me into the right direction.