How to write a codec for Rockbox
Codec structure
- a minimal Codec structure looks like this:
#include "codeclib.h"
CODEC_HEADER
/* this is the codec entry point */
enum codec_status codec_main(void)
{
/* Generic codec initialisation */
ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512);
next_track:
if (codec_init()) {
DEBUGF("codec init failed\n");
return CODEC_ERROR;
}
while (!*ci->taginfo_ready && !ci->stop_codec)
ci->sleep(1);
codec_set_replaygain(ci->id3);
/* Init Codec for Track */
/* Make use of 44.1khz */
ci->configure(DSP_SET_FREQUENCY, 44100);
/* Sample depth is 16 bit little endian */
ci->configure(DSP_SET_SAMPLE_DEPTH, 16);
/* Stereo or Mono output ? */
ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
/* reset eleapsed */
ci->set_elapsed(0);
/* The main decoder loop */
while (1)
{
ci->yield();
if (ci->stop_codec || ci->new_track)
break;
if (ci->seek_time) {
/* New time is ready in ci->seek_time */
/* absolute position in ms */
/* seek to pos */
/* update elapsed */
ci->set_elapsed(ci->seek_time);
/* seek ready */
ci->seek_complete();
}
/* Generate a buffer full of Audio */
/* Insert a buffer full of samples */
ci->pcmbuf_insert(sample_buffer, NULL, numberOfSamples);
/* update elapsed in ms */
ci->set_elapsed(current_Pos);
if( EndOfFile )
break;
}
if (ci->request_next_track())
goto next_track;
return CODEC_OK;
}
Adding a decoder to Rockbox
This is of course subject to change as things move around in the source.
- Put your source in apps/codecs
- apps/codecs/Makefile
- Add a rule like ${OBJDIR}/wav.elf : $(OBJDIR)/wav.o
- firmware/export/id3.h
- Add a value to the Audio file types enum.
- firmware/id3.c
- Add an entry to audio_formats[]
- apps/metadata.c
- Add a case to the switch in get_metadata()
- apps/metadata/
- Add your metadata detection here.
- apps/filetypes.c
- Add an element to inbuilt_filetypes struct.
|