diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /apps/codecs/nsf.c | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'apps/codecs/nsf.c')
-rw-r--r-- | apps/codecs/nsf.c | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/apps/codecs/nsf.c b/apps/codecs/nsf.c deleted file mode 100644 index 4c5b37c3fa..0000000000 --- a/apps/codecs/nsf.c +++ /dev/null @@ -1,135 +0,0 @@ - -/* Ripped off from Game_Music_Emu 0.5.2. http://www.slack.net/~ant/ */ - -#define GME_NSF_TYPE - -#include <codecs/lib/codeclib.h> -#include "libgme/nsf_emu.h" - -CODEC_HEADER - -/* Maximum number of bytes to process in one iteration */ -#define CHUNK_SIZE (1024*2) - -static int16_t samples[CHUNK_SIZE] IBSS_ATTR; -static struct Nsf_Emu nsf_emu; - -/****************** rockbox interface ******************/ - -static void set_codec_track(int t, int multitrack) { - Nsf_start_track(&nsf_emu, t); - - /* for REPEAT_ONE we disable track limits */ - if (!ci->loop_track()) { - Track_set_fade(&nsf_emu, Track_length( &nsf_emu, t ) - 4000, 4000); - } - if (multitrack) ci->set_elapsed(t*1000); /* t is track no to display */ - else ci->set_elapsed(0); -} - -/* this is the codec entry point */ -enum codec_status codec_main(enum codec_entry_call_reason reason) -{ - if (reason == CODEC_LOAD) { - /* we only render 16 bits */ - ci->configure(DSP_SET_SAMPLE_DEPTH, 16); - - /* 44 Khz, Interleaved stereo */ - ci->configure(DSP_SET_FREQUENCY, 44100); - ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); - - Nsf_init(&nsf_emu); - Nsf_set_sample_rate(&nsf_emu, 44100); - } - - return CODEC_OK; -} - -/* this is called for each file to process */ -enum codec_status codec_run(void) -{ - blargg_err_t err; - uint8_t *buf; - size_t n; - int track, is_multitrack; - uint32_t elapsed_time; - intptr_t param; - - track = is_multitrack = 0; - elapsed_time = 0; - - DEBUGF("NSF: next_track\n"); - if (codec_init()) { - return CODEC_ERROR; - } - - codec_set_replaygain(ci->id3); - - /* Read the entire file */ - DEBUGF("NSF: request file\n"); - ci->seek_buffer(0); - buf = ci->request_buffer(&n, ci->filesize); - if (!buf || n < (size_t)ci->filesize) { - DEBUGF("NSF: file load failed\n"); - return CODEC_ERROR; - } - - if ((err = Nsf_load_mem(&nsf_emu, buf, ci->filesize))) { - DEBUGF("NSF: Nsf_load_mem failed (%s)\n", err); - return CODEC_ERROR; - } - - /* Update internal track count */ - if (nsf_emu.m3u.size > 0) - nsf_emu.track_count = nsf_emu.m3u.size; - - if (nsf_emu.track_count > 1) is_multitrack = 1; - -next_track: - set_codec_track(track, is_multitrack); - - /* The main decoder loop */ - while (1) { - enum codec_command_action action = ci->get_command(¶m); - - if (action == CODEC_ACTION_HALT) - break; - - if (action == CODEC_ACTION_SEEK_TIME) { - if (is_multitrack) { - track = param/1000; - ci->seek_complete(); - if (track >= nsf_emu.track_count) break; - goto next_track; - } - - ci->set_elapsed(param); - elapsed_time = param; - Track_seek(&nsf_emu, param); - ci->seek_complete(); - - /* Set fade again */ - if (!ci->loop_track()) { - Track_set_fade(&nsf_emu, Track_length( &nsf_emu, track ), 4000); - } - } - - /* Generate audio buffer */ - err = Nsf_play(&nsf_emu, CHUNK_SIZE, samples); - if (err || Track_ended(&nsf_emu)) { - track++; - if (track >= nsf_emu.track_count) break; - goto next_track; - } - - ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE >> 1); - - /* Set elapsed time for one track files */ - if (is_multitrack == 0) { - elapsed_time += (CHUNK_SIZE / 2) * 10 / 441; - ci->set_elapsed(elapsed_time); - } - } - - return CODEC_OK; -} |