Previous 15994 Revisions Next

r6098 Thursday 15th October, 2009 at 21:31:46 UTC by Harmony
[CDI] Added rudimentary ADPCM decoding based on pSX XA implementation, sending the results to a file. No intelligible audio yet, but the hookup is there. [pSXAuthor, Harmony]
[src/mess/drivers]cdi.c

src/mess/drivers/cdi.c
r6097r6098
447447         return scc68070_regs.timers.timer0;
448448      case 0x2026/2:
449449         verboselog(space->machine, 2, "scc68070_periphs_r: Timer 1: %04x & %04x\n", scc68070_regs.timers.timer1, mem_mask);
450         printf( "Timer 1 read\n" );
450451         return scc68070_regs.timers.timer1;
451452      case 0x2028/2:
452453         verboselog(space->machine, 2, "scc68070_periphs_r: Timer 2: %04x & %04x\n", scc68070_regs.timers.timer2, mem_mask);
454         printf( "Timer 2 read\n" );
453455         return scc68070_regs.timers.timer2;
454456
455457      // PICR1: 80002045
r6097r6098
717719      case 0x2026/2:
718720         verboselog(space->machine, 2, "scc68070_periphs_w: Timer 1: %04x & %04x\n", data, mem_mask);
719721         COMBINE_DATA(&scc68070_regs.timers.timer1);
722         printf( "Timer 1 write: %04x\n", data );
720723         break;
721724      case 0x2028/2:
722725         verboselog(space->machine, 2, "scc68070_periphs_w: Timer 2: %04x & %04x\n", data, mem_mask);
723726         COMBINE_DATA(&scc68070_regs.timers.timer2);
727         printf( "Timer 2 write: %04x\n", data );
724728         break;
725729
726730      // PICR1: 80002045
r6097r6098
942946
943947static cdic_regs_t cdic_regs;
944948
949const INT32 cdic_adpcm_filter_coef[5][2] =
950{
951   { 0,0 },
952   { 60,0 },
953   { 115,-52 },
954   { 98,-55 },
955   { 122,-60 },
956};
957
958int cdic_xa_last[4] = { 0, 0, 0, 0 };
959
960INLINE INT16 clamp(INT16 in)
961{
962   return in;
963}
964
965static void cdic_decode_xa_mono(const unsigned char *xa, unsigned char *ptr)
966{
967   signed short *dp=(signed short *)ptr;
968
969   int l0=cdic_xa_last[0],
970         l1=cdic_xa_last[1];
971   int b=0;
972   int s=0;
973
974   for (b=0; b<18; b++)
975   {
976      for (s=0; s<4; s++)
977      {
978         unsigned char flags=xa[(4+(s<<1))^1],
979                              shift=flags&0xf,
980                              filter=flags>>4;
981         int f0=cdic_adpcm_filter_coef[filter][0],
982               f1=cdic_adpcm_filter_coef[filter][1];
983         int i=0;
984
985         for (i=0; i<28; i++)
986         {
987            short d=(xa[(16+(i<<2)+s)^1]&0xf)<<12;
988            d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6));
989            *dp++=d;
990            l1=l0;
991            l0=d;
992         }
993
994         flags=xa[(5+(s<<1))^1];
995         shift=flags&0xf;
996         filter=flags>>4;
997         f0=cdic_adpcm_filter_coef[filter][0];
998         f1=cdic_adpcm_filter_coef[filter][1];
999
1000         for (i=0; i<28; i++)
1001         {
1002            short d=(xa[(16+(i<<2)+s)^1]>>4)<<12;
1003            d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6));
1004            *dp++=d;
1005            l1=l0;
1006            l0=d;
1007         }
1008      }
1009
1010      xa+=128;
1011   }
1012
1013   cdic_xa_last[0]=l0;
1014   cdic_xa_last[1]=l1;
1015}
1016
1017//
1018//
1019//
1020
1021static void cdic_decode_xa_stereo(const unsigned char *xa, unsigned char *ptr)
1022{
1023   signed short *dp=(signed short *)ptr;
1024
1025   int l0=cdic_xa_last[0],
1026         l1=cdic_xa_last[1],
1027         l2=cdic_xa_last[2],
1028         l3=cdic_xa_last[3];
1029   int b=0;
1030   int s=0;
1031
1032   for (b=0; b<18; b++)
1033   {
1034      for (s=0; s<4; s++)
1035      {
1036         unsigned char flags0=xa[(4+(s<<1))^1],
1037                              shift0=flags0&0xf,
1038                              filter0=flags0>>4,
1039                              flags1=xa[(5+(s<<1))^1],
1040                              shift1=flags1&0xf,
1041                              filter1=flags1>>4;
1042
1043         int f0=cdic_adpcm_filter_coef[filter0][0],
1044               f1=cdic_adpcm_filter_coef[filter0][1],
1045               f2=cdic_adpcm_filter_coef[filter1][0],
1046               f3=cdic_adpcm_filter_coef[filter1][1];
1047         int i=0;
1048
1049         for (i=0; i<28; i++)
1050         {
1051            short d=xa[(16+(i<<2)+s)^1],
1052                      d0=(d&0xf)<<12,
1053                      d1=(d>>4)<<12;
1054            d0=clamp((int)(d0>>shift0)+(((l0*f0)+(l1*f1)+32)>>6));
1055            *dp++=d0;
1056            l1=l0;
1057            l0=d0;
1058
1059            d1=clamp((int)(d1>>shift1)+(((l2*f2)+(l3*f3)+32)>>6));
1060            *dp++=d1;
1061            l3=l2;
1062            l2=d1;
1063         }
1064      }
1065
1066      xa+=128;
1067   }
1068
1069   cdic_xa_last[0]=l0;
1070   cdic_xa_last[1]=l1;
1071   cdic_xa_last[2]=l2;
1072   cdic_xa_last[3]=l3;
1073}
1074
1075static void cdic_decode_audio_sector(const unsigned char *xa)
1076{
1077   // Get XA format from sector header
1078
1079   const unsigned char *hdr = xa + 4;
1080   float freq;
1081   int channels;
1082   UINT8 samples[18*28*8*2];
1083   //FILE* temp_adpcm = fopen("temp_adpcm.bin","ab");
1084
1085   //fseek(temp_adpcm, 0, SEEK_END);
1086   switch(hdr[2] & 0x3f)   // ignore emphasis and reserved bits
1087   {
1088      case 0:
1089         channels=1;
1090         freq=37800.0f;   //18900.0f;
1091         break;
1092
1093      case 1:
1094         channels=2;
1095         freq=37800.0f;
1096         break;
1097
1098      case 4:
1099         channels=1;
1100         freq=18900.0f;   ///2.0f;
1101         break;
1102
1103      case 5:
1104         channels=2;
1105         freq=18900.0f;   //37800.0f/2.0f;
1106         break;
1107
1108      default:
1109         printf("play_xa: unhandled xa mode %08x\n",hdr[2]);
1110         return;
1111   }
1112
1113   switch(channels)
1114   {
1115      case 1:
1116         cdic_decode_xa_mono(xa, samples);
1117         break;
1118      case 2:
1119         cdic_decode_xa_stereo(xa, samples);
1120         break;
1121   }
1122
1123   //fwrite(samples, 18*28*8*2, 1, temp_adpcm);
1124   //fclose(temp_adpcm);
1125}
1126
9451127static TIMER_CALLBACK( cdic_trigger_readback_int )
9461128{
9471129   switch(cdic_regs.command)
r6097r6098
10331215         {
10341216            //if(!(buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_TRIG))
10351217            //{
1036            //   verboselog(machine, 0, "Audio sector, ignored\n" );
1218               verboselog(machine, 0, "Audio sector\n" );
10371219            //}
10381220            //else
10391221            //{
1222               cdic_decode_audio_sector((UINT8*)cdram + ((cdic_regs.data_buffer & 5) * 0xa00 + 4));
10401223               // Ignore the audio sector for now.
10411224               cdic_regs.x_buffer |= 0x8000;
10421225
r6097r6098
12251408                  break;
12261409               case 0x29: // Read Mode 1
12271410               case 0x2a: // Read Mode 2
1411                  cdic_xa_last[0] = cdic_xa_last[1] = cdic_xa_last[2] = cdic_xa_last[3] = 0;
12281412                  timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed
12291413                  cdic_regs.data_buffer &= 0xfffe;
12301414                  break;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team