diff options
Diffstat (limited to 'apps/codecs/sid.c')
-rw-r--r-- | apps/codecs/sid.c | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/apps/codecs/sid.c b/apps/codecs/sid.c index 52c1289fff..0edbabe0b6 100644 --- a/apps/codecs/sid.c +++ b/apps/codecs/sid.c | |||
@@ -1203,34 +1203,47 @@ unsigned short LoadSIDFromMemory(void *pSidData, unsigned short *load_addr, | |||
1203 | return *load_addr; | 1203 | return *load_addr; |
1204 | } | 1204 | } |
1205 | 1205 | ||
1206 | static int nSamplesRendered = 0; | ||
1207 | static int nSamplesPerCall = 882; /* This is PAL SID single speed (44100/50Hz) */ | ||
1208 | static int nSamplesToRender = 0; | ||
1206 | 1209 | ||
1207 | enum codec_status codec_main(void) | 1210 | /* this is the codec entry point */ |
1211 | enum codec_status codec_main(enum codec_entry_call_reason reason) | ||
1208 | { | 1212 | { |
1209 | unsigned int filesize; | 1213 | if (reason == CODEC_LOAD) { |
1214 | /* Make use of 44.1khz */ | ||
1215 | ci->configure(DSP_SWITCH_FREQUENCY, 44100); | ||
1216 | /* Sample depth is 28 bit host endian */ | ||
1217 | ci->configure(DSP_SET_SAMPLE_DEPTH, 28); | ||
1218 | /* Mono output */ | ||
1219 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); | ||
1220 | } | ||
1221 | |||
1222 | return CODEC_OK; | ||
1223 | } | ||
1210 | 1224 | ||
1225 | /* this is called for each file to process */ | ||
1226 | enum codec_status codec_run(void) | ||
1227 | { | ||
1228 | unsigned int filesize; | ||
1211 | unsigned short load_addr, init_addr, play_addr; | 1229 | unsigned short load_addr, init_addr, play_addr; |
1212 | unsigned char subSongsMax, subSong, song_speed; | 1230 | unsigned char subSongsMax, subSong, song_speed; |
1231 | intptr_t param; | ||
1213 | 1232 | ||
1214 | int nSamplesRendered = 0; | ||
1215 | int nSamplesPerCall = 882; /* This is PAL SID single speed (44100/50Hz) */ | ||
1216 | int nSamplesToRender = 0; | ||
1217 | |||
1218 | next_track: | ||
1219 | if (codec_init()) { | 1233 | if (codec_init()) { |
1220 | return CODEC_ERROR; | 1234 | return CODEC_ERROR; |
1221 | } | 1235 | } |
1222 | 1236 | ||
1223 | if (codec_wait_taginfo() != 0) | ||
1224 | goto request_next_track; | ||
1225 | |||
1226 | codec_set_replaygain(ci->id3); | 1237 | codec_set_replaygain(ci->id3); |
1227 | 1238 | ||
1228 | /* Load SID file the read_filebuf callback will return the full requested | 1239 | /* Load SID file the read_filebuf callback will return the full requested |
1229 | * size if at all possible, so there is no need to loop */ | 1240 | * size if at all possible, so there is no need to loop */ |
1241 | ci->seek_buffer(0); | ||
1230 | filesize = ci->read_filebuf(sidfile, sizeof(sidfile)); | 1242 | filesize = ci->read_filebuf(sidfile, sizeof(sidfile)); |
1231 | 1243 | ||
1232 | if (filesize == 0) | 1244 | if (filesize == 0) { |
1233 | return CODEC_ERROR; | 1245 | return CODEC_ERROR; |
1246 | } | ||
1234 | 1247 | ||
1235 | c64Init(44100); | 1248 | c64Init(44100); |
1236 | LoadSIDFromMemory(sidfile, &load_addr, &init_addr, &play_addr, | 1249 | LoadSIDFromMemory(sidfile, &load_addr, &init_addr, &play_addr, |
@@ -1239,37 +1252,30 @@ next_track: | |||
1239 | cpuJSR(init_addr, subSong); /* Start the song initialize */ | 1252 | cpuJSR(init_addr, subSong); /* Start the song initialize */ |
1240 | 1253 | ||
1241 | 1254 | ||
1242 | /* Make use of 44.1khz */ | ||
1243 | ci->configure(DSP_SWITCH_FREQUENCY, 44100); | ||
1244 | /* Sample depth is 28 bit host endian */ | ||
1245 | ci->configure(DSP_SET_SAMPLE_DEPTH, 28); | ||
1246 | /* Mono output */ | ||
1247 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); | ||
1248 | |||
1249 | |||
1250 | /* Set the elapsed time to the current subsong (in seconds) */ | 1255 | /* Set the elapsed time to the current subsong (in seconds) */ |
1251 | ci->set_elapsed(subSong*1000); | 1256 | ci->set_elapsed(subSong*1000); |
1252 | 1257 | ||
1253 | /* The main decoder loop */ | 1258 | /* The main decoder loop */ |
1254 | while (1) { | 1259 | while (1) { |
1255 | ci->yield(); | 1260 | enum codec_command_action action = ci->get_command(¶m); |
1256 | if (ci->stop_codec || ci->new_track) | 1261 | |
1262 | if (action == CODEC_ACTION_HALT) | ||
1257 | break; | 1263 | break; |
1258 | 1264 | ||
1259 | if (ci->seek_time) { | 1265 | if (action == CODEC_ACTION_SEEK_TIME) { |
1260 | /* New time is ready in ci->seek_time */ | 1266 | /* New time is ready in param */ |
1261 | 1267 | ||
1262 | /* Start playing from scratch */ | 1268 | /* Start playing from scratch */ |
1263 | c64Init(44100); | 1269 | c64Init(44100); |
1264 | LoadSIDFromMemory(sidfile, &load_addr, &init_addr, &play_addr, &subSongsMax, &subSong, &song_speed, filesize); | 1270 | LoadSIDFromMemory(sidfile, &load_addr, &init_addr, &play_addr, |
1265 | sidPoke(24, 15); /* Turn on full volume */ | 1271 | &subSongsMax, &subSong, &song_speed, filesize); |
1266 | subSong = ci->seek_time / 1000; /* Now use the current seek time in seconds as subsong */ | 1272 | sidPoke(24, 15); /* Turn on full volume */ |
1267 | cpuJSR(init_addr, subSong); /* Start the song initialize */ | 1273 | subSong = param / 1000; /* Now use the current seek time in seconds as subsong */ |
1268 | nSamplesToRender = 0; /* Start the rendering from scratch */ | 1274 | cpuJSR(init_addr, subSong); /* Start the song initialize */ |
1269 | 1275 | nSamplesToRender = 0; /* Start the rendering from scratch */ | |
1270 | ci->seek_complete(); | ||
1271 | 1276 | ||
1272 | /* Set the elapsed time to the current subsong (in seconds) */ | 1277 | /* Set the elapsed time to the current subsong (in seconds) */ |
1278 | ci->seek_complete(); | ||
1273 | ci->set_elapsed(subSong*1000); | 1279 | ci->set_elapsed(subSong*1000); |
1274 | } | 1280 | } |
1275 | 1281 | ||
@@ -1306,9 +1312,5 @@ next_track: | |||
1306 | ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE); | 1312 | ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE); |
1307 | } | 1313 | } |
1308 | 1314 | ||
1309 | request_next_track: | ||
1310 | if (ci->request_next_track()) | ||
1311 | goto next_track; | ||
1312 | |||
1313 | return CODEC_OK; | 1315 | return CODEC_OK; |
1314 | } | 1316 | } |