diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-07 20:01:04 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-07 20:01:04 +0000 |
commit | acb0917556fc33681c1df5a530cf754193e67705 (patch) | |
tree | 052a47097009a210e4aed9c207bd6aa4828cc000 /apps/codecs/sgc.c | |
parent | 93c6f1329a5691a8be158cefe15641bd1daf9ef8 (diff) | |
download | rockbox-acb0917556fc33681c1df5a530cf754193e67705.tar.gz rockbox-acb0917556fc33681c1df5a530cf754193e67705.zip |
Submit initial patch from FS#12176. Adds support for several new game music formats (AY, GBS, HES, KSS, SGC, VGM and VGZ) and replaces the current NSF and NSFE with a new implementation based on a port of the Game Music Emu library 'GME'. This first submit does not cover the full functionality provided by the author's original patch: Coleco-SGV is not supported, some GME-specific m3u-support has been removed and IRAM is not used yet. Further changes are very likely to follow this submit. Thanks to Mauricio Garrido.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30264 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/sgc.c')
-rw-r--r-- | apps/codecs/sgc.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/apps/codecs/sgc.c b/apps/codecs/sgc.c new file mode 100644 index 0000000000..e5f0299980 --- /dev/null +++ b/apps/codecs/sgc.c | |||
@@ -0,0 +1,123 @@ | |||
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/sgc_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 Sgc_Emu sgc_emu IDATA_ATTR CACHEALIGN_ATTR; | ||
14 | |||
15 | /* Coleco Bios */ | ||
16 | /* Colecovision not supported yet | ||
17 | static char coleco_bios[0x2000]; | ||
18 | */ | ||
19 | |||
20 | /****************** rockbox interface ******************/ | ||
21 | |||
22 | static void set_codec_track(int t) { | ||
23 | Sgc_start_track(&sgc_emu, t); | ||
24 | |||
25 | /* for REPEAT_ONE we disable track limits */ | ||
26 | if (ci->global_settings->repeat_mode != REPEAT_ONE) { | ||
27 | Track_set_fade(&sgc_emu, Track_get_length( &sgc_emu, t ), 4000); | ||
28 | } | ||
29 | ci->set_elapsed(t*1000); /* t is track no to display */ | ||
30 | } | ||
31 | |||
32 | /* this is the codec entry point */ | ||
33 | enum codec_status codec_main(enum codec_entry_call_reason reason) | ||
34 | { | ||
35 | if (reason == CODEC_LOAD) { | ||
36 | /* we only render 16 bits */ | ||
37 | ci->configure(DSP_SET_SAMPLE_DEPTH, 16); | ||
38 | |||
39 | /* 44 Khz, Interleaved stereo */ | ||
40 | ci->configure(DSP_SET_FREQUENCY, 44100); | ||
41 | ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); | ||
42 | |||
43 | Sgc_init(&sgc_emu); | ||
44 | Sgc_set_sample_rate(&sgc_emu, 44100); | ||
45 | |||
46 | /* set coleco bios, should be named coleco_bios.rom */ | ||
47 | /* Colecovision not supported yet | ||
48 | int fd = ci->open("/coleco_bios.rom", O_RDONLY); | ||
49 | if ( fd >= 0 ) { | ||
50 | ci->read(fd, coleco_bios, 0x2000); | ||
51 | ci->close(fd); | ||
52 | set_coleco_bios( &sgc_emu, coleco_bios ); | ||
53 | } | ||
54 | */ | ||
55 | } | ||
56 | |||
57 | return CODEC_OK; | ||
58 | } | ||
59 | |||
60 | /* this is called for each file to process */ | ||
61 | enum codec_status codec_run(void) | ||
62 | { | ||
63 | blargg_err_t err; | ||
64 | uint8_t *buf; | ||
65 | size_t n; | ||
66 | intptr_t param; | ||
67 | int track = 0; | ||
68 | |||
69 | DEBUGF("SGC: next_track\n"); | ||
70 | if (codec_init()) { | ||
71 | return CODEC_ERROR; | ||
72 | } | ||
73 | |||
74 | codec_set_replaygain(ci->id3); | ||
75 | |||
76 | /* Read the entire file */ | ||
77 | DEBUGF("SGC: request file\n"); | ||
78 | ci->seek_buffer(0); | ||
79 | buf = ci->request_buffer(&n, ci->filesize); | ||
80 | if (!buf || n < (size_t)ci->filesize) { | ||
81 | DEBUGF("SGC: file load failed\n"); | ||
82 | return CODEC_ERROR; | ||
83 | } | ||
84 | |||
85 | if ((err = Sgc_load_mem(&sgc_emu, buf, ci->filesize))) { | ||
86 | DEBUGF("SGC: Sgc_load failed (%s)\n", err); | ||
87 | return CODEC_ERROR; | ||
88 | } | ||
89 | |||
90 | /* Update internal track count */ | ||
91 | if (sgc_emu.m3u.size > 0) | ||
92 | sgc_emu.track_count = sgc_emu.m3u.size; | ||
93 | |||
94 | next_track: | ||
95 | set_codec_track(track); | ||
96 | |||
97 | /* The main decoder loop */ | ||
98 | while (1) { | ||
99 | enum codec_command_action action = ci->get_command(¶m); | ||
100 | |||
101 | if (action == CODEC_ACTION_HALT) | ||
102 | break; | ||
103 | |||
104 | if (action == CODEC_ACTION_SEEK_TIME) { | ||
105 | track = param/1000; | ||
106 | ci->seek_complete(); | ||
107 | if (track >= sgc_emu.track_count) break; | ||
108 | goto next_track; | ||
109 | } | ||
110 | |||
111 | /* Generate audio buffer */ | ||
112 | err = Sgc_play(&sgc_emu, CHUNK_SIZE, samples); | ||
113 | if (err || sgc_emu.track_ended) { | ||
114 | track++; | ||
115 | if (track >= sgc_emu.track_count) break; | ||
116 | goto next_track; | ||
117 | } | ||
118 | |||
119 | ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE >> 1); | ||
120 | } | ||
121 | |||
122 | return CODEC_OK; | ||
123 | } | ||