Mercurial > repos > blastem
comparison cdimage.c @ 2288:efc75ea79164
Support WAVE files in CUE sheets
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 18 Jan 2023 23:31:44 -0800 |
parents | 9ead0fe69d9b |
children | 9d68799f945b |
comparison
equal
deleted
inserted
replaced
2287:8a918eb95ba8 | 2288:efc75ea79164 |
---|---|
2 #include <string.h> | 2 #include <string.h> |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "system.h" | 5 #include "system.h" |
6 #include "util.h" | 6 #include "util.h" |
7 #include "wave.h" | |
7 | 8 |
8 static char* cmd_start(char *cur) | 9 static char* cmd_start(char *cur) |
9 { | 10 { |
10 while (*cur && isblank(*cur)) | 11 while (*cur && isblank(*cur)) |
11 { | 12 { |
197 int track = -1; | 198 int track = -1; |
198 uint8_t audio_byte_swap = 0; | 199 uint8_t audio_byte_swap = 0; |
199 FILE *f = NULL; | 200 FILE *f = NULL; |
200 int track_of_file = -1; | 201 int track_of_file = -1; |
201 uint8_t has_index_0 = 0; | 202 uint8_t has_index_0 = 0; |
203 uint32_t extra_offset = 0; | |
202 do { | 204 do { |
203 char *cmd = cmd_start(line); | 205 char *cmd = cmd_start(line); |
204 if (*cmd) { | 206 if (*cmd) { |
205 if (startswith(cmd, "TRACK ")) { | 207 if (startswith(cmd, "TRACK ")) { |
206 track++; | 208 track++; |
264 free(fname); | 266 free(fname); |
265 track_of_file = -1; | 267 track_of_file = -1; |
266 for (end++; *end && *end != '\n' && *end != '\r'; end++) | 268 for (end++; *end && *end != '\n' && *end != '\r'; end++) |
267 { | 269 { |
268 if (!isspace(*end)) { | 270 if (!isspace(*end)) { |
271 extra_offset = 0; | |
269 if (startswith(end, "BINARY")) { | 272 if (startswith(end, "BINARY")) { |
270 audio_byte_swap = 0; | 273 audio_byte_swap = 0; |
271 } else if (startswith(end, "MOTOROLA")) { | 274 } else if (startswith(end, "MOTOROLA")) { |
272 audio_byte_swap = 1; | 275 audio_byte_swap = 1; |
276 } else if (startswith(end, "WAVE")) { | |
277 audio_byte_swap = 0; | |
278 wave_header wave; | |
279 if (!wave_read_header(f, &wave)) { | |
280 fatal_error("Wave file %s specified by cute sheet %s.%s is not valid\n", fname, media->name, media->extension); | |
281 } | |
282 if (wave.audio_format != 1 || wave.num_channels != 2 || wave.sample_rate != 44100 || wave.bits_per_sample != 16) { | |
283 warning("BlastEm only suports WAVE tracks in 16-bit stereo PCM format at 44100 hz, file %s does not match\n", fname); | |
284 } | |
285 extra_offset = wave.format_header.size + sizeof(wave.data_header) + sizeof(wave.chunk); | |
273 } else { | 286 } else { |
274 warning("Unsupported FILE type in CUE sheet. Only BINARY and MOTOROLA are supported\n"); | 287 warning("Unsupported FILE type in CUE sheet. Only BINARY and MOTOROLA are supported\n"); |
275 } | 288 } |
276 break; | 289 break; |
277 } | 290 } |
308 tracks[track].file_offset = tracks[track-1].file_offset + tracks[track-1].end_lba * tracks[track-1].sector_bytes; | 321 tracks[track].file_offset = tracks[track-1].file_offset + tracks[track-1].end_lba * tracks[track-1].sector_bytes; |
309 if (track_of_file > 1) { | 322 if (track_of_file > 1) { |
310 tracks[track].file_offset -= tracks[track-2].end_lba * tracks[track-1].sector_bytes; | 323 tracks[track].file_offset -= tracks[track-2].end_lba * tracks[track-1].sector_bytes; |
311 } | 324 } |
312 } else { | 325 } else { |
313 tracks[track].file_offset = 0; | 326 tracks[track].file_offset = extra_offset; |
314 } | 327 } |
315 } | 328 } |
316 } | 329 } |
317 } | 330 } |
318 if (cmd && *cmd) { | 331 if (cmd && *cmd) { |