Parcourir la source

cmDspKr.c : Updates to use amicro instead of dtick in MIDI mesg.

master
kevin il y a 9 ans
Parent
révision
c9eaf40705
1 fichiers modifiés avec 20 ajouts et 6 suppressions
  1. 20
    6
      dsp/cmDspKr.c

+ 20
- 6
dsp/cmDspKr.c Voir le fichier

@@ -756,7 +756,7 @@ unsigned _cmDspMidiFilePlaySeekMsgIdx( cmDspCtx_t* ctx, cmDspInst_t* inst, unsig
756 756
   const cmMidiTrackMsg_t** a     = cmMidiFileMsgArray(p->mfH);
757 757
 
758 758
   for(i=0; i<n; ++i)
759
-    if( a[i]->dtick > smpIdx )
759
+    if( (a[i]->amicro * cmDspSampleRate(ctx) / 1000000.0) >= smpIdx )
760 760
       break;
761 761
 
762 762
   return i==n ? cmInvalidIdx : i;
@@ -786,7 +786,7 @@ cmDspRC_t _cmDspMidiFilePlayOpen(cmDspCtx_t* ctx, cmDspInst_t* inst )
786 786
     cmMidiFileSetDelay(p->mfH, cmMidiFileTicksPerQN(p->mfH) );
787 787
 
788 788
     // convert midi msg times to absolute time in samples
789
-    cmMidiFileTickToSamples(p->mfH,cmDspSampleRate(ctx),true);
789
+    //cmMidiFileTickToSamples(p->mfH,cmDspSampleRate(ctx),true);
790 790
 
791 791
   }
792 792
   return rc;
@@ -820,23 +820,37 @@ cmDspRC_t _cmDspMidiFilePlayExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp
820 820
 
821 821
     const cmMidiTrackMsg_t** mpp   = cmMidiFileMsgArray(p->mfH);
822 822
     unsigned                 msgN  = cmMidiFileMsgCount(p->mfH);
823
-  
824
-    for(; p->curMsgIdx < msgN && p->csi <= mpp[p->curMsgIdx]->dtick  &&  mpp[p->curMsgIdx]->dtick < (p->csi + sPc); ++p->curMsgIdx )
823
+    
824
+    do
825 825
     {
826
+      if( p->curMsgIdx >= msgN )
827
+        break;
828
+
826 829
       const cmMidiTrackMsg_t* mp = mpp[p->curMsgIdx];
830
+
831
+      // convert the absolute time in microseconds to samples
832
+      unsigned  curMsgTimeSmp = round(mp->amicro * cmDspSampleRate(ctx) / 1000000.0);
833
+
834
+      // if this midi event falls inside this execution window
835
+      if( p->csi > curMsgTimeSmp  ||  curMsgTimeSmp >= (p->csi + sPc))
836
+        break;
837
+        
827 838
       switch( mp->status )
828 839
       {
829 840
         case kNoteOffMdId:
830 841
         case kNoteOnMdId:
831 842
         case kCtlMdId:
832
-          cmDspSetUInt(ctx,inst, kSmpIdxMfId, mp->dtick);
843
+          cmDspSetUInt(ctx,inst, kSmpIdxMfId, curMsgTimeSmp);
833 844
           cmDspSetUInt(ctx,inst, kD1MfId,     mp->u.chMsgPtr->d1);
834 845
           cmDspSetUInt(ctx,inst, kD0MfId,     mp->u.chMsgPtr->d0);
835 846
           cmDspSetUInt(ctx,inst, kStatusMfId, mp->status);
836 847
           cmDspSetUInt(ctx,inst, kIdMfId,     mp->uid);
837 848
           break;
838 849
       }
839
-    }
850
+
851
+      p->curMsgIdx += 1;
852
+      
853
+    }while(1);
840 854
   }
841 855
 
842 856
   p->csi += sPc;

Chargement…
Annuler
Enregistrer