1 /***************************************************************************
2 * Copyright (C) 2007 PCSX-df Team *
3 * Copyright (C) 2009 Wei Mingzhi *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. *
19 ***************************************************************************/
21 #include "psxcommon.h"
35 static FILE *cdHandle = NULL;
36 static FILE *cddaHandle = NULL;
37 static FILE *subHandle = NULL;
39 static boolean subChanMixed = FALSE;
40 static boolean subChanRaw = FALSE;
41 static boolean subChanMissing = FALSE;
43 static unsigned char cdbuffer[DATA_SIZE];
44 static unsigned char subbuffer[SUB_FRAMESIZE];
46 static unsigned char sndbuffer[CD_FRAMESIZE_RAW * 10];
48 #define CDDA_FRAMETIME (1000 * (sizeof(sndbuffer) / CD_FRAMESIZE_RAW) / 75)
51 static HANDLE threadid;
53 static pthread_t threadid;
55 static unsigned int initial_offset = 0;
56 static boolean playing = FALSE;
57 static boolean cddaBigEndian = FALSE;
58 static unsigned int cddaCurOffset = 0;
59 static unsigned int cddaStartOffset;
60 /* Frame offset into CD image where pregap data would be found if it was there.
61 * If a game seeks there we must *not* return subchannel data since it's
62 * not in the CD image, so that cdrom code can fake subchannel data instead.
63 * XXX: there could be multiple pregaps but PSX dumps only have one? */
64 static unsigned int pregapOffset;
66 char* CALLBACK CDR__getDriveLetter(void);
67 long CALLBACK CDR__configure(void);
68 long CALLBACK CDR__test(void);
69 void CALLBACK CDR__about(void);
70 long CALLBACK CDR__setfilename(char *filename);
71 long CALLBACK CDR__getStatus(struct CdrStat *stat);
73 static void DecodeRawSubData(void);
75 extern void *hCDRDriver;
78 enum {DATA, CDDA} type;
79 char start[3]; // MSF-format
80 char length[3]; // MSF-format
81 FILE *handle; // for multi-track images CDDA
82 int start_offset; // sector offset from start of above file
85 #define MAXTRACKS 100 /* How many tracks can a CD hold? */
87 static int numtracks = 0;
88 static struct trackinfo ti[MAXTRACKS];
90 // get a sector from a msf-array
91 static unsigned int msf2sec(char *msf) {
92 return ((msf[0] * 60 + msf[1]) * 75) + msf[2];
95 static void sec2msf(unsigned int s, char *msf) {
97 s = s - msf[0] * 75 * 60;
103 // divide a string of xx:yy:zz into m, s, f
104 static void tok2msf(char *time, char *msf) {
107 token = strtok(time, ":");
109 msf[0] = atoi(token);
115 token = strtok(NULL, ":");
117 msf[1] = atoi(token);
123 token = strtok(NULL, ":");
125 msf[2] = atoi(token);
133 static long GetTickCount(void) {
134 static time_t initial_time = 0;
137 gettimeofday(&now, NULL);
139 if (initial_time == 0) {
140 initial_time = now.tv_sec;
143 return (now.tv_sec - initial_time) * 1000L + now.tv_usec / 1000L;
147 // this thread plays audio data
149 static void playthread(void *param)
151 static void *playthread(void *param)
160 d = t - (long)GetTickCount();
164 else if (d > CDDA_FRAMETIME) {
172 // HACK: stop feeding data while emu is paused
179 t = GetTickCount() + CDDA_FRAMETIME;
184 for (i = 0; i < sizeof(sndbuffer) / CD_FRAMESIZE_RAW; i++) {
186 d = fread(sndbuffer + CD_FRAMESIZE_RAW * i, 1, CD_FRAMESIZE_RAW, cddaHandle);
187 if (d < CD_FRAMESIZE_RAW) {
193 fread(subbuffer, 1, SUB_FRAMESIZE, cddaHandle);
194 if (subChanRaw) DecodeRawSubData();
198 s = fread(sndbuffer, 1, sizeof(sndbuffer), cddaHandle);
200 if (subHandle != NULL) {
201 fread(subbuffer, 1, SUB_FRAMESIZE, subHandle);
202 if (subChanRaw) DecodeRawSubData();
204 // a bit crude but ohwell
205 fseek(subHandle, (sizeof(sndbuffer) / CD_FRAMESIZE_RAW - 1) * SUB_FRAMESIZE, SEEK_CUR);
215 if (!cdr.Muted && playing) {
217 for (i = 0; i < s / 2; i++) {
218 tmp = sndbuffer[i * 2];
219 sndbuffer[i * 2] = sndbuffer[i * 2 + 1];
220 sndbuffer[i * 2 + 1] = tmp;
224 SPU_playCDDAchannel((short *)sndbuffer, s);
238 // stop the CDDA playback
239 static void stopCDDA() {
246 WaitForSingleObject(threadid, INFINITE);
248 pthread_join(threadid, NULL);
254 // start the CDDA playback
255 static void startCDDA(unsigned int offset) {
257 if (initial_offset == offset) {
263 initial_offset = offset;
264 cddaCurOffset = initial_offset;
265 fseek(cddaHandle, initial_offset, SEEK_SET);
270 threadid = (HANDLE)_beginthread(playthread, 0, NULL);
272 pthread_create(&threadid, NULL, playthread, NULL);
276 // this function tries to get the .toc file of the given .bin
277 // the necessary data is put into the ti (trackinformation)-array
278 static int parsetoc(const char *isofile) {
279 char tocname[MAXPATHLEN];
281 char linebuf[256], dummy[256], name[256];
283 char time[20], time2[20];
284 unsigned int t, sector_offs;
288 // copy name of the iso and change extension from .bin to .toc
289 strncpy(tocname, isofile, sizeof(tocname));
290 tocname[MAXPATHLEN - 1] = '\0';
291 if (strlen(tocname) >= 4) {
292 strcpy(tocname + strlen(tocname) - 4, ".toc");
298 if ((fi = fopen(tocname, "r")) == NULL) {
299 // try changing extension to .cue (to satisfy some stupid tutorials)
300 strcpy(tocname + strlen(tocname) - 4, ".cue");
301 if ((fi = fopen(tocname, "r")) == NULL) {
302 // if filename is image.toc.bin, try removing .bin (for Brasero)
303 strcpy(tocname, isofile);
305 if (t >= 8 && strcmp(tocname + t - 8, ".toc.bin") == 0) {
306 tocname[t - 4] = '\0';
307 if ((fi = fopen(tocname, "r")) == NULL) {
317 memset(&ti, 0, sizeof(ti));
318 cddaBigEndian = TRUE; // cdrdao uses big-endian for CD Audio
320 sector_offs = 2 * 75;
322 // parse the .toc file
323 while (fgets(linebuf, sizeof(linebuf), fi) != NULL) {
325 strncpy(dummy, linebuf, sizeof(linebuf));
326 token = strtok(dummy, " ");
328 if (token == NULL) continue;
330 if (!strcmp(token, "TRACK")) {
332 token = strtok(NULL, " ");
335 if (!strncmp(token, "MODE2_RAW", 9)) {
336 ti[numtracks].type = DATA;
337 sec2msf(2 * 75, ti[numtracks].start); // assume data track on 0:2:0
339 // check if this image contains mixed subchannel data
340 token = strtok(NULL, " ");
341 if (token != NULL && !strncmp(token, "RW_RAW", 6)) {
346 else if (!strncmp(token, "AUDIO", 5)) {
347 ti[numtracks].type = CDDA;
350 else if (!strcmp(token, "DATAFILE")) {
351 if (ti[numtracks].type == CDDA) {
352 sscanf(linebuf, "DATAFILE \"%[^\"]\" #%d %8s", name, &t, time2);
353 t /= CD_FRAMESIZE_RAW + (subChanMixed ? SUB_FRAMESIZE : 0);
354 ti[numtracks].start_offset = t;
356 sec2msf(t, (char *)&ti[numtracks].start);
357 tok2msf((char *)&time2, (char *)&ti[numtracks].length);
360 sscanf(linebuf, "DATAFILE \"%[^\"]\" %8s", name, time);
361 tok2msf((char *)&time, (char *)&ti[numtracks].length);
364 else if (!strcmp(token, "FILE")) {
365 sscanf(linebuf, "FILE \"%[^\"]\" #%d %8s %8s", name, &t, time, time2);
366 tok2msf((char *)&time, (char *)&ti[numtracks].start);
367 t /= CD_FRAMESIZE_RAW + (subChanMixed ? SUB_FRAMESIZE : 0);
368 ti[numtracks].start_offset = t;
369 t += msf2sec(ti[numtracks].start) + sector_offs;
370 sec2msf(t, (char *)&ti[numtracks].start);
371 tok2msf((char *)&time2, (char *)&ti[numtracks].length);
373 else if (!strcmp(token, "ZERO")) {
374 sscanf(linebuf, "ZERO AUDIO RW_RAW %8s", time);
375 tok2msf((char *)&time, dummy);
376 sector_offs += msf2sec(dummy);
378 t = ti[numtracks - 1].start_offset;
379 pregapOffset = t + msf2sec(ti[numtracks - 1].length);
389 // this function tries to get the .cue file of the given .bin
390 // the necessary data is put into the ti (trackinformation)-array
391 static int parsecue(const char *isofile) {
392 char cuename[MAXPATHLEN];
393 char filepath[MAXPATHLEN];
399 char linebuf[256], tmpb[256], dummy[256];
400 unsigned int incue_max_len;
401 unsigned int t, file_len, sector_offs;
405 // copy name of the iso and change extension from .bin to .cue
406 strncpy(cuename, isofile, sizeof(cuename));
407 cuename[MAXPATHLEN - 1] = '\0';
408 if (strlen(cuename) >= 4) {
409 strcpy(cuename + strlen(cuename) - 4, ".cue");
415 if ((fi = fopen(cuename, "r")) == NULL) {
419 // Some stupid tutorials wrongly tell users to use cdrdao to rip a
420 // "bin/cue" image, which is in fact a "bin/toc" image. So let's check
422 if (fgets(linebuf, sizeof(linebuf), fi) != NULL) {
423 if (!strncmp(linebuf, "CD_ROM_XA", 9)) {
424 // Don't proceed further, as this is actually a .toc file rather
427 return parsetoc(isofile);
429 fseek(fi, 0, SEEK_SET);
432 // build a path for files referenced in .cue
433 strncpy(filepath, cuename, sizeof(filepath));
434 tmp = strrchr(filepath, '/') + 1;
436 tmp = strrchr(filepath, '\\') + 1;
440 filepath[sizeof(filepath) - 1] = 0;
442 incue_max_len = sizeof(filepath) - (tmp - filepath) - 1;
444 memset(&ti, 0, sizeof(ti));
447 sector_offs = 2 * 75;
449 while (fgets(linebuf, sizeof(linebuf), fi) != NULL) {
450 strncpy(dummy, linebuf, sizeof(linebuf));
451 token = strtok(dummy, " ");
457 if (!strcmp(token, "TRACK")) {
460 if (strstr(linebuf, "AUDIO") != NULL) {
461 ti[numtracks].type = CDDA;
463 else if (strstr(linebuf, "MODE1/2352") != NULL || strstr(linebuf, "MODE2/2352") != NULL) {
464 ti[numtracks].type = DATA;
467 else if (!strcmp(token, "INDEX")) {
468 sscanf(linebuf, " INDEX %02d %8s", &t, time);
469 tok2msf(time, (char *)&ti[numtracks].start);
471 t = msf2sec(ti[numtracks].start);
472 ti[numtracks].start_offset = t;
474 sec2msf(t, ti[numtracks].start);
476 // default track length to file length
477 t = file_len - ti[numtracks].start_offset;
478 sec2msf(t, ti[numtracks].length);
480 if (numtracks > 1 && ti[numtracks].handle == NULL) {
481 // this track uses the same file as the last,
482 // start of this track is last track's end
483 t = msf2sec(ti[numtracks].start) - msf2sec(ti[numtracks - 1].start);
484 sec2msf(t, ti[numtracks - 1].length);
486 if (numtracks > 1 && pregapOffset == -1)
487 pregapOffset = ti[numtracks].start_offset;
489 else if (!strcmp(token, "PREGAP")) {
490 if (sscanf(linebuf, " PREGAP %8s", time) == 1) {
491 tok2msf(time, dummy);
492 sector_offs += msf2sec(dummy);
494 pregapOffset = -1; // mark to fill track start_offset
496 else if (!strcmp(token, "FILE")) {
497 sscanf(linebuf, " FILE \"%[^\"]\"", tmpb);
500 ti[numtracks + 1].handle = fopen(tmpb, "rb");
501 if (ti[numtracks + 1].handle == NULL) {
503 tmp = strrchr(tmpb, '\\');
505 tmp = strrchr(tmpb, '/');
510 strncpy(incue_fname, tmp, incue_max_len);
511 ti[numtracks + 1].handle = fopen(filepath, "rb");
514 // update global offset if this is not first file in this .cue
515 if (numtracks + 1 > 1)
516 sector_offs += file_len;
519 if (ti[numtracks + 1].handle == NULL) {
520 SysPrintf(_("\ncould not open: %s\n"), filepath);
523 fseek(ti[numtracks + 1].handle, 0, SEEK_END);
524 file_len = ftell(ti[numtracks + 1].handle) / 2352;
526 if (numtracks == 0 && strlen(isofile) >= 4 &&
527 strcmp(isofile + strlen(isofile) - 4, ".cue") == 0)
529 // user selected .cue as image file, use it's data track instead
531 cdHandle = fopen(filepath, "rb");
541 // this function tries to get the .ccd file of the given .img
542 // the necessary data is put into the ti (trackinformation)-array
543 static int parseccd(const char *isofile) {
544 char ccdname[MAXPATHLEN];
551 // copy name of the iso and change extension from .img to .ccd
552 strncpy(ccdname, isofile, sizeof(ccdname));
553 ccdname[MAXPATHLEN - 1] = '\0';
554 if (strlen(ccdname) >= 4) {
555 strcpy(ccdname + strlen(ccdname) - 4, ".ccd");
561 if ((fi = fopen(ccdname, "r")) == NULL) {
565 memset(&ti, 0, sizeof(ti));
567 while (fgets(linebuf, sizeof(linebuf), fi) != NULL) {
568 if (!strncmp(linebuf, "[TRACK", 6)){
571 else if (!strncmp(linebuf, "MODE=", 5)) {
572 sscanf(linebuf, "MODE=%d", &t);
573 ti[numtracks].type = ((t == 0) ? CDDA : DATA);
575 else if (!strncmp(linebuf, "INDEX 1=", 8)) {
576 sscanf(linebuf, "INDEX 1=%d", &t);
577 sec2msf(t + 2 * 75, ti[numtracks].start);
578 ti[numtracks].start_offset = t;
580 // If we've already seen another track, this is its end
582 t = msf2sec(ti[numtracks].start) - msf2sec(ti[numtracks - 1].start);
583 sec2msf(t, ti[numtracks - 1].length);
590 // Fill out the last track's end based on size
591 if (numtracks >= 1) {
592 fseek(cdHandle, 0, SEEK_END);
593 t = ftell(cdHandle) / 2352 - msf2sec(ti[numtracks].start) + 2 * 75;
594 sec2msf(t, ti[numtracks].length);
600 // this function tries to get the .mds file of the given .mdf
601 // the necessary data is put into the ti (trackinformation)-array
602 static int parsemds(const char *isofile) {
603 char mdsname[MAXPATHLEN];
605 unsigned int offset, extra_offset, l, i;
610 // copy name of the iso and change extension from .mdf to .mds
611 strncpy(mdsname, isofile, sizeof(mdsname));
612 mdsname[MAXPATHLEN - 1] = '\0';
613 if (strlen(mdsname) >= 4) {
614 strcpy(mdsname + strlen(mdsname) - 4, ".mds");
620 if ((fi = fopen(mdsname, "rb")) == NULL) {
624 memset(&ti, 0, sizeof(ti));
626 // check if it's a valid mds file
627 fread(&i, 1, sizeof(unsigned int), fi);
629 if (i != 0x4944454D) {
630 // not an valid mds file
635 // get offset to session block
636 fseek(fi, 0x50, SEEK_SET);
637 fread(&offset, 1, sizeof(unsigned int), fi);
638 offset = SWAP32(offset);
640 // get total number of tracks
642 fseek(fi, offset, SEEK_SET);
643 fread(&s, 1, sizeof(unsigned short), fi);
647 // get offset to track blocks
648 fseek(fi, 4, SEEK_CUR);
649 fread(&offset, 1, sizeof(unsigned int), fi);
650 offset = SWAP32(offset);
654 fseek(fi, offset + 4, SEEK_SET);
655 if (fgetc(fi) < 0xA0) {
661 // check if the image contains mixed subchannel data
662 fseek(fi, offset + 1, SEEK_SET);
663 subChanMixed = (fgetc(fi) ? TRUE : FALSE);
666 for (i = 1; i <= numtracks; i++) {
667 fseek(fi, offset, SEEK_SET);
669 // get the track type
670 ti[i].type = ((fgetc(fi) == 0xA9) ? CDDA : DATA);
671 fseek(fi, 8, SEEK_CUR);
673 // get the track starting point
674 ti[i].start[0] = fgetc(fi);
675 ti[i].start[1] = fgetc(fi);
676 ti[i].start[2] = fgetc(fi);
678 fread(&extra_offset, 1, sizeof(unsigned int), fi);
679 extra_offset = SWAP32(extra_offset);
681 // get track start offset (in .mdf)
682 fseek(fi, offset + 0x28, SEEK_SET);
683 fread(&l, 1, sizeof(unsigned int), fi);
685 ti[i].start_offset = l / CD_FRAMESIZE_RAW;
688 fseek(fi, extra_offset, SEEK_SET);
689 fread(&l, 1, sizeof(unsigned int), fi);
692 pregapOffset = ti[i].start_offset;
694 // get the track length
695 fread(&l, 1, sizeof(unsigned int), fi);
697 sec2msf(l, ti[i].length);
706 // this function tries to get the .sub file of the given .img
707 static int opensubfile(const char *isoname) {
708 char subname[MAXPATHLEN];
710 // copy name of the iso and change extension from .img to .sub
711 strncpy(subname, isoname, sizeof(subname));
712 subname[MAXPATHLEN - 1] = '\0';
713 if (strlen(subname) >= 4) {
714 strcpy(subname + strlen(subname) - 4, ".sub");
720 subHandle = fopen(subname, "rb");
721 if (subHandle == NULL) {
728 static int opensbifile(const char *isoname) {
729 char sbiname[MAXPATHLEN];
732 strncpy(sbiname, isoname, sizeof(sbiname));
733 sbiname[MAXPATHLEN - 1] = '\0';
734 if (strlen(sbiname) >= 4) {
735 strcpy(sbiname + strlen(sbiname) - 4, ".sbi");
741 fseek(cdHandle, 0, SEEK_END);
742 s = ftell(cdHandle) / 2352;
744 return LoadSBI(sbiname, s);
747 static void PrintTracks(void) {
750 for (i = 1; i <= numtracks; i++) {
751 SysPrintf(_("Track %.2d (%s) - Start %.2d:%.2d:%.2d, Length %.2d:%.2d:%.2d\n"),
752 i, (ti[i].type == DATA ? "DATA" : "AUDIO"),
753 ti[i].start[0], ti[i].start[1], ti[i].start[2],
754 ti[i].length[0], ti[i].length[1], ti[i].length[2]);
758 // This function is invoked by the front-end when opening an ISO
760 static long CALLBACK ISOopen(void) {
761 if (cdHandle != NULL) {
762 return 0; // it's already open
765 cdHandle = fopen(GetIsoFile(), "rb");
766 if (cdHandle == NULL) {
770 SysPrintf(_("Loaded CD Image: %s"), GetIsoFile());
772 cddaBigEndian = FALSE;
773 subChanMixed = FALSE;
775 subChanMixed = FALSE;
778 if (parsecue(GetIsoFile()) == 0) {
781 else if (parsetoc(GetIsoFile()) == 0) {
784 else if (parseccd(GetIsoFile()) == 0) {
787 else if (parsemds(GetIsoFile()) == 0) {
791 if (!subChanMixed && opensubfile(GetIsoFile()) == 0) {
794 if (opensbifile(GetIsoFile()) == 0) {
802 // make sure we have another handle open for cdda
803 if (numtracks > 1 && ti[1].handle == NULL) {
804 ti[1].handle = fopen(GetIsoFile(), "rb");
806 cddaCurOffset = cddaStartOffset = 0;
811 static long CALLBACK ISOclose(void) {
814 if (cdHandle != NULL) {
818 if (subHandle != NULL) {
825 for (i = 1; i <= numtracks; i++) {
826 if (ti[i].handle != NULL) {
827 fclose(ti[i].handle);
837 static long CALLBACK ISOinit(void) {
838 assert(cdHandle == NULL);
839 assert(subHandle == NULL);
841 return 0; // do nothing
844 static long CALLBACK ISOshutdown(void) {
849 // return Starting and Ending Track
851 // byte 0 - start track
852 // byte 1 - end track
853 static long CALLBACK ISOgetTN(unsigned char *buffer) {
857 buffer[1] = numtracks;
871 static long CALLBACK ISOgetTD(unsigned char track, unsigned char *buffer) {
873 // CD length according pcsxr-svn (done a bit different here)
875 unsigned char time[3];
876 sect = msf2sec(ti[numtracks].start) + msf2sec(ti[numtracks].length);
877 sec2msf(sect, (char *)time);
882 else if (numtracks > 0 && track <= numtracks) {
883 buffer[2] = ti[track].start[0];
884 buffer[1] = ti[track].start[1];
885 buffer[0] = ti[track].start[2];
896 // decode 'raw' subchannel data ripped by cdrdao
897 static void DecodeRawSubData(void) {
898 unsigned char subQData[12];
901 memset(subQData, 0, sizeof(subQData));
903 for (i = 0; i < 8 * 12; i++) {
904 if (subbuffer[i] & (1 << 6)) { // only subchannel Q is needed
905 subQData[i >> 3] |= (1 << (7 - (i & 7)));
909 memcpy(&subbuffer[12], subQData, 12);
913 // time: byte 0 - minute; byte 1 - second; byte 2 - frame
915 static long CALLBACK ISOreadTrack(unsigned char *time) {
916 int sector = MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2]));
918 if (cdHandle == NULL) {
923 subChanMissing = FALSE;
924 if (sector >= pregapOffset) {
926 if (sector < pregapOffset)
927 subChanMissing = TRUE;
932 fseek(cdHandle, sector * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE) + 12, SEEK_SET);
933 fread(cdbuffer, 1, DATA_SIZE, cdHandle);
934 fread(subbuffer, 1, SUB_FRAMESIZE, cdHandle);
936 if (subChanRaw) DecodeRawSubData();
939 fseek(cdHandle, sector * CD_FRAMESIZE_RAW + 12, SEEK_SET);
940 fread(cdbuffer, 1, DATA_SIZE, cdHandle);
942 if (subHandle != NULL) {
943 fseek(subHandle, sector * SUB_FRAMESIZE, SEEK_SET);
944 fread(subbuffer, 1, SUB_FRAMESIZE, subHandle);
946 if (subChanRaw) DecodeRawSubData();
953 // return readed track
954 static unsigned char * CALLBACK ISOgetBuffer(void) {
959 // sector: byte 0 - minute; byte 1 - second; byte 2 - frame
960 // does NOT uses bcd format
961 static long CALLBACK ISOplay(unsigned char *time) {
962 unsigned int i, abs_sect;
969 abs_sect = msf2sec((char *)time);
970 for (i = numtracks; i > 1; i--)
971 if (msf2sec(ti[i].start) <= abs_sect + 2 * 75)
974 file_sect = ti[i].start_offset + (abs_sect - msf2sec(ti[i].start));
978 // find the file that contains this track
980 if (ti[i].handle != NULL)
983 cddaStartOffset = abs_sect - file_sect;
984 cddaHandle = ti[i].handle;
986 if (pregapOffset && (unsigned int)(pregapOffset - file_sect) < 2 * 75) {
987 // get out of the missing pregap to avoid noise
988 file_sect = pregapOffset;
991 if (SPU_playCDDAchannel != NULL) {
993 startCDDA(file_sect * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE));
996 startCDDA(file_sect * CD_FRAMESIZE_RAW);
997 if (subHandle != NULL)
998 fseek(subHandle, file_sect * SUB_FRAMESIZE, SEEK_SET);
1005 static long CALLBACK ISOstop(void) {
1010 // gets subchannel data
1011 static unsigned char* CALLBACK ISOgetBufferSub(void) {
1012 if ((subHandle != NULL || subChanMixed) && !subChanMissing) {
1019 static long CALLBACK ISOgetStatus(struct CdrStat *stat) {
1022 CDR__getStatus(stat);
1026 stat->Status |= 0x80;
1032 sec = (cddaStartOffset + cddaCurOffset) / CD_FRAMESIZE_RAW;
1033 sec2msf(sec, (char *)stat->Time);
1038 void cdrIsoInit(void) {
1040 CDR_shutdown = ISOshutdown;
1042 CDR_close = ISOclose;
1043 CDR_getTN = ISOgetTN;
1044 CDR_getTD = ISOgetTD;
1045 CDR_readTrack = ISOreadTrack;
1046 CDR_getBuffer = ISOgetBuffer;
1049 CDR_getBufferSub = ISOgetBufferSub;
1050 CDR_getStatus = ISOgetStatus;
1052 CDR_getDriveLetter = CDR__getDriveLetter;
1053 CDR_configure = CDR__configure;
1054 CDR_test = CDR__test;
1055 CDR_about = CDR__about;
1056 CDR_setfilename = CDR__setfilename;
1061 int cdrIsoActive(void) {
1062 return (cdHandle != NULL);