mcd, make audio/binary track type handling more locally
authorkub <derkub@gmail.com>
Tue, 4 Feb 2025 20:45:54 +0000 (21:45 +0100)
committerkub <derkub@gmail.com>
Tue, 4 Feb 2025 20:45:54 +0000 (21:45 +0100)
pico/cd/cd_image.c
pico/cd/cdd.c

index afe9dff..d2210a6 100644 (file)
@@ -49,7 +49,7 @@ static int handle_mp3(const char *fname, int index)
     return -1;
   }
 
-  track->type = CT_AUDIO;
+  track->type = CT_MP3;
   track->fd = tmp_file;
   track->offset = 0;
 
@@ -93,8 +93,6 @@ int load_cd_image(const char *cd_img_name, int *type)
   if (PicoCDLoadProgressCB != NULL)
     PicoCDLoadProgressCB(cd_img_name, 1);
 
-  Pico_mcd->cdda_type = CT_UNKNOWN;
-
   /* is this a .cue? */
   cue_data = cue_parse(cd_img_name);
   if (cue_data != NULL) {
@@ -115,7 +113,7 @@ int load_cd_image(const char *cd_img_name, int *type)
   }
   tracks[0].fd = pmf;
   tracks[0].fname = strdup(cd_img_name);
-  tracks[0].type = *type & CT_AUDIO;
+  tracks[0].type = *type;
 
   if (*type == CT_ISO)
        cd_img_sectors = pmf->size >> 11;  // size in sectors
@@ -186,8 +184,7 @@ int load_cd_image(const char *cd_img_name, int *type)
         // overriden by custom cue command
         length = cue_data->tracks[n].sector_xlength;
 
-      Pico_mcd->cdda_type = cue_data->tracks[n].type;
-      tracks[index].type = cue_data->tracks[n].type & CT_AUDIO;
+      tracks[index].type = cue_data->tracks[n].type;
 
       tracks[index].start = lba;
       lba += length;
@@ -253,8 +250,7 @@ int load_cd_image(const char *cd_img_name, int *type)
         lba += length;
         tracks[index].end = lba;
 
-        Pico_mcd->cdda_type = CT_MP3;
-        tracks[index].type = CT_AUDIO;
+        tracks[index].type = CT_MP3;
 
         sprintf_lba(tmp_ext, sizeof(tmp_ext), tracks[index].start);
         elprintf(EL_STATUS, "Track %2i: %s %9i AUDIO - %s",
index 2e95a89..0030b16 100644 (file)
@@ -188,9 +188,12 @@ void cdd_play_audio(int index, int lba)
   for (i = index; i >= 0; i--)
     if (cdd.toc.tracks[i].fd != NULL)
       break;
+  // TODO: this doesn't cover all tracks being in a single bin file properly:
+  // in that case, fd should be duplicated to work properly with this MD+ shit.
   if (! is_audio(i)) return;
 
   Pico_mcd->cdda_stream = cdd.toc.tracks[i].fd;
+  Pico_mcd->cdda_type = cdd.toc.tracks[i].type;
   base = cdd.toc.tracks[index].offset;
   lba_offset = lba - cdd.toc.tracks[index].start;
   lb_len = cdd.toc.tracks[index].end - cdd.toc.tracks[index].start;
@@ -467,7 +470,7 @@ int cdd_unload(void)
     int i;
 
     /* stop audio streaming */
-    Pico_mcd->cdda_stream = NULL;
+    if (Pico_mcd) Pico_mcd->cdda_stream = NULL;
 
     /* close CD tracks */
     if (cdd.toc.tracks[0].fd)
@@ -492,7 +495,7 @@ int cdd_unload(void)
       if (cdd.toc.tracks[i].fd)
       {
         /* close file */
-        if (Pico_mcd->cdda_type == CT_MP3)
+        if (cdd.toc.tracks[i].type == CT_MP3)
           fclose(cdd.toc.tracks[i].fd);
         else
           pm_close(cdd.toc.tracks[i].fd);