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 /lib/rbcodec/codecs/kss.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 'lib/rbcodec/codecs/kss.c')
-rw-r--r-- | lib/rbcodec/codecs/kss.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/kss.c b/lib/rbcodec/codecs/kss.c new file mode 100644 index 0000000000..92efcd4e5f --- /dev/null +++ b/lib/rbcodec/codecs/kss.c | |||
@@ -0,0 +1,111 @@ | |||
1 | |||
2 | /* Ripped off from Game_Music_Emu 0.5.2. http://www.slack.net/~ant/ */ | ||
3 | |||
4 | #include <codecs/lib/codeclib.h> | ||
5 | #include "libgme/kss_emu.h" | ||
6 | |||
7 | CODEC_HEADER | ||
8 | |||
9 | /* Maximum number of bytes to process in one iteration */ | ||
10 | #define CHUNK_SIZE (1024*2) | ||
11 | |||
12 | static int16_t samples[CHUNK_SIZE] IBSS_ATTR; | ||
13 | static struct Kss_Emu kss_emu; | ||
14 | |||
15 | /****************** rockbox interface ******************/ | ||
16 | |||
17 | static void set_codec_track(int t) { | ||
18 | Kss_start_track(&kss_emu, t); | ||
19 | |||
20 | /* for REPEAT_ONE we disable track limits */ | ||
21 | if (!ci->loop_track()) { | ||
22 | Track_set_fade(&kss_emu, Track_get_length( &kss_emu, t ), 4000); | ||
23 | } | ||
24 | ci->set_elapsed(t*1000); /* t is track no to display */ | ||
25 | } | ||
26 | |||
27 | /* this is the codec entry point */ | ||
28 | enum codec_status codec_main(enum codec_entry_call_reason reason) | ||
29 | { | ||
30 | if (reason == CODEC_LOAD) { | ||
31 | /* we only render 16 bits */ | ||
32 | ci->configure(DSP_SET_SAMPLE_DEPTH, 16); | ||
33 | |||
34 | /* 44 Khz, Interleaved stereo */ | ||
35 | ci->configure(DSP_SET_FREQUENCY, 44100); | ||
36 | ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); | ||
37 | |||
38 | Kss_init(&kss_emu); | ||
39 | Kss_set_sample_rate(&kss_emu, 44100); | ||
40 | } | ||
41 | |||
42 | return CODEC_OK; | ||
43 | } | ||
44 | |||
45 | /* this is called for each file to process */ | ||
46 | enum codec_status codec_run(void) | ||
47 | { | ||
48 | blargg_err_t err; | ||
49 | uint8_t *buf; | ||
50 | size_t n; | ||
51 | int track; | ||
52 | intptr_t param; | ||
53 | |||
54 | /* reset values */ | ||
55 | track = 0; | ||
56 | |||
57 | DEBUGF("KSS: next_track\n"); | ||
58 | if (codec_init()) { | ||
59 | return CODEC_ERROR; | ||
60 | } | ||
61 | |||
62 | codec_set_replaygain(ci->id3); | ||
63 | |||
64 | /* Read the entire file */ | ||
65 | DEBUGF("KSS: request file\n"); | ||
66 | ci->seek_buffer(0); | ||
67 | buf = ci->request_buffer(&n, ci->filesize); | ||
68 | if (!buf || n < (size_t)ci->filesize) { | ||
69 | DEBUGF("KSS: file load failed\n"); | ||
70 | return CODEC_ERROR; | ||
71 | } | ||
72 | |||
73 | if ((err = Kss_load_mem(&kss_emu, buf, ci->filesize))) { | ||
74 | DEBUGF("KSS: Kss_load failed (%s)\n", err); | ||
75 | return CODEC_ERROR; | ||
76 | } | ||
77 | |||
78 | /* Update internal track count */ | ||
79 | if (kss_emu.m3u.size > 0) | ||
80 | kss_emu.track_count = kss_emu.m3u.size; | ||
81 | |||
82 | next_track: | ||
83 | set_codec_track(track); | ||
84 | |||
85 | /* The main decoder loop */ | ||
86 | while (1) { | ||
87 | enum codec_command_action action = ci->get_command(¶m); | ||
88 | |||
89 | if (action == CODEC_ACTION_HALT) | ||
90 | break; | ||
91 | |||
92 | if (action == CODEC_ACTION_SEEK_TIME) { | ||
93 | track = param/1000; | ||
94 | ci->seek_complete(); | ||
95 | if (track >= kss_emu.track_count) break; | ||
96 | goto next_track; | ||
97 | } | ||
98 | |||
99 | /* Generate audio buffer */ | ||
100 | err = Kss_play(&kss_emu, CHUNK_SIZE, samples); | ||
101 | if (err || Track_ended(&kss_emu)) { | ||
102 | track++; | ||
103 | if (track >= kss_emu.track_count) break; | ||
104 | goto next_track; | ||
105 | } | ||
106 | |||
107 | ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE >> 1); | ||
108 | } | ||
109 | |||
110 | return CODEC_OK; | ||
111 | } | ||