浏览代码

ausgezilst

LH 2 月之前
父节点
当前提交
5b9dc44e7f
共有 1 个文件被更改,包括 130 次插入57 次删除
  1. 130 57
      QuickStuff/src/main/java/QuickVerifyCrap/Logic2PWMMassageliege.java

+ 130 - 57
QuickStuff/src/main/java/QuickVerifyCrap/Logic2PWMMassageliege.java

@@ -5,6 +5,7 @@ import java.io.RandomAccessFile;
 import java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -12,12 +13,13 @@ public class Logic2PWMMassageliege
 {
     static final int REFRATE = 500_000_000;
     static final int SAMPLELENGTH=REFRATE/32_000;//500MS samplerate/32KHz
-    static final int SAMPLELENGTH_BUFFERED= (int) (SAMPLELENGTH*1.1);//500MS samplerate/32KHz
+    static final int SAMPLELENGTH_BUFFERED= (int) (REFRATE/2);//1/2 second of no jiggly edges mark a "file" end
     public static void main(String[] args) throws Exception
     {
-        long[] edges_ch1 = null;
-        long[] edges_ch2 = null;
-        String basepath = "/home/tgoerner/loa/000034/export/";
+        List<Long> edges_ch1 = new ArrayList<>();
+        List<Long> edges_ch2 = new ArrayList<>();
+        //String basepath = "/home/tgoerner/loa/000034/export/";
+        String basepath = "/mnt/d/LOA/000034/export/";
         RandomAccessFile ch1 = new RandomAccessFile(basepath+"digital_0.bin","r");
         RandomAccessFile ch2 = new RandomAccessFile(basepath+"digital_1.bin","r");
         ch1.readLong(); //magic LMAA
@@ -27,27 +29,37 @@ public class Logic2PWMMassageliege
         ch1.readDouble();
         ch1.readDouble();
         int countEdges1 = (int) Long.reverseBytes(ch1.readLong());
-        if(initialHigh1)
-        {
-            countEdges1++;
-        }
+        //if(initialHigh1)
+        //{
+            //countEdges1++;
+        //}
         int writeptr = 0;
-        edges_ch1 = new long[countEdges1+1];
-        if(initialHigh1)
+        //edges_ch1 = new long[countEdges1+1];
+        System.out.println("CE1="+countEdges1);
+        /*if(initialHigh1)
         {
             edges_ch1[0]=-1;
             writeptr++;
-        }
+        }*/
+        boolean risingEdge = true;
         while(writeptr<countEdges1)
         {
             long temp = Long.reverseBytes(ch1.readLong());
             ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
             buffer.putLong(temp);
             buffer.rewind();
-            edges_ch1[writeptr]=(long)(buffer.getDouble()*REFRATE);
+            Long massaged = (long)(buffer.getDouble()*REFRATE);
+            edges_ch1.add(massaged);
             writeptr++;
+            if(risingEdge)
+            {
+                //synthetic zero-length sample for the other side
+                edges_ch2.add(massaged);
+                edges_ch2.add(massaged);
+            }
+
+            risingEdge = !risingEdge;
         }
-        edges_ch1[writeptr] = edges_ch1[writeptr-1]+REFRATE;
         
         
         ch2.readLong(); //magic LMAA
@@ -62,82 +74,143 @@ public class Logic2PWMMassageliege
             countEdges2++;
         }
         writeptr = 0;
-        edges_ch2 = new long[countEdges2+1];
-        if(initialHigh2)
-        {
-            edges_ch1[0]=-1;
-            writeptr++;
-        }
-        
+        System.out.println("CE2="+countEdges2);
+        //if(initialHigh2)
+        //{
+        //    edges_ch1[0]=-1;
+        //    writeptr++;
+        //}
+
+        risingEdge = true;
         while(writeptr<countEdges2)
         {
             long temp = Long.reverseBytes(ch2.readLong());
             ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
             buffer.putLong(temp);
             buffer.rewind();
-            
-            edges_ch2[writeptr]=(long)(buffer.getDouble()*REFRATE);
+            Long massaged = (long)(buffer.getDouble()*REFRATE);
+            edges_ch2.add(massaged);
             writeptr++;
+            if(risingEdge)
+            {
+                //synthetic zero-length sample for the other side
+                edges_ch1.add(massaged);
+                edges_ch1.add(massaged);
+            }
+            writeptr++;
+            risingEdge = !risingEdge;
         }
-        edges_ch2[writeptr] = edges_ch2[writeptr-1]+REFRATE;
-        
-        List<List<Short>> lst= new LinkedList<>();
-        List<Short> samples = new LinkedList<>();
-        int c1 = 1; //zeit zur ersten flanke weg, die ist bullshit.exe da zeit vor erster messung
-        int c2 = 1;
-        while(c1<edges_ch1.length-2||c2<edges_ch2.length-2)
+
+
+        edges_ch1.sort(Long::compareTo); //die samples an die rechte stelle rücken....
+        edges_ch2.sort(Long::compareTo);
+
+        System.out.println(edges_ch1.size());
+        System.out.println(edges_ch2.size());
+        edges_ch1.add(0L); //sentinel
+        edges_ch2.add(0L);
+
+    //edges_ch1 = Arrays.asList((Long[]) edges_ch1.toArray(new Long[]{}));
+    //edges_ch2 = Arrays.asList((Long[]) edges_ch2.toArray(new Long[]{}));
+
+        List<List<Short>> lst= new ArrayList<>();
+        List<Short> samples = new ArrayList<>();
+        boolean cutoff=false;
+        int c1 = 0; //zeit zur ersten flanke weg, die ist bullshit.exe da zeit vor erster messung
+        while(c1<edges_ch1.size()-2)
         {
-            boolean cutoff = false;
-            //triggert wenn beide signale länger als
-            if(c1<edges_ch1.length&&c2<edges_ch2.length&&(edges_ch1[c1+1]>SAMPLELENGTH_BUFFERED)&&(edges_ch2[c2+1]>SAMPLELENGTH_BUFFERED))
+            if(c1%1000==0)
+            {
+                System.out.println("c1="+c1);
+            }
+            long deltaHigh =edges_ch1.get(c1+1)-edges_ch1.get(c1);
+            long deltaLow = deltaHigh+edges_ch1.get(c1+2)-edges_ch1.get(c1+1);
+
+            short gapsample = 0;
+
+            if(deltaHigh>SAMPLELENGTH*1.1)
             {
+                gapsample=32767;
+                System.out.println("Multilength high spotted on positive");
+            }
+
+
+            if(deltaLow<0||deltaLow>SAMPLELENGTH_BUFFERED)
+            {
+                deltaLow=SAMPLELENGTH; //syntethisieren falls keine nächste steigende flanke für echten wert
                 cutoff=true;
             }
-            
-            if(c1<edges_ch1.length-2&&edges_ch1[c1]<edges_ch2[c2]&&c2<edges_ch2.length-2) //channel1 hat den nächsten höcker
+            int sample = (int)((deltaHigh*32768)/deltaLow);
+
+            deltaHigh =edges_ch2.get(c1+1)-edges_ch2.get(c1);
+            deltaLow = deltaHigh+edges_ch2.get(c1+2)-edges_ch2.get(c1+1);
+
+            if(deltaHigh>SAMPLELENGTH*1.1)
             {
-                long samplesize = edges_ch1[c1]+edges_ch1[c1+1];
-                if(edges_ch1[c1+1]>SAMPLELENGTH_BUFFERED)
-                {
-                    samplesize=SAMPLELENGTH;
-                }
-                short sample = (short)((edges_ch1[c1]*32768)/samplesize);
-                samples.add(sample);
-                c1+=2;
+                gapsample=-32768;
+                System.out.println("Multilength high spotted on negative");
             }
-            else if(c2<edges_ch2.length-2&&edges_ch2[c2]<edges_ch1[c1]&&c1<edges_ch1.length-2) //channel1 hat den nächsten höcker
+
+            if(deltaLow<0||deltaLow>SAMPLELENGTH_BUFFERED)
+            {
+                deltaLow=SAMPLELENGTH; //syntethisieren falls keine nächste steigende flanke für echten wert
+            }
+
+            int shortGap = 0;
+
+            if(deltaLow>SAMPLELENGTH*1.5)
             {
-                long samplesize = edges_ch2[c2]+edges_ch2[c2+1];
-                if(edges_ch2[c2+1]>SAMPLELENGTH_BUFFERED)
+                double gap = (double)(deltaLow)/SAMPLELENGTH;
+                if(gapsample!=0)
                 {
-                    samplesize=SAMPLELENGTH;
+                    System.out.println("multiple sus samples spotted, no edges on any side:"+gap);
                 }
-                short sample = (short)(((edges_ch2[c2]*32768)/samplesize)*-1);
-                samples.add(sample);
-                c2+=2;
+                shortGap = (int)Math.round(gap);
+            }
+
+            sample -= (int)((deltaHigh*32768)/deltaLow);
+            if(sample>32767)
+            {
+                System.out.println("CLIPPING!"+c1+"="+sample);
+                sample=32767;
             }
-            else
+            if(sample<-32768)
             {
-                System.out.println("ZÖINKS");
-                c1=edges_ch1.length;
-                c2=edges_ch2.length;
+                System.out.println("CLIPPING!"+c1+"="+sample);
+                sample=-32768;
+            }
+            samples.add((short)sample);
+
+            if(shortGap>0)
+            {
+                for(int i=1;i<shortGap;i++)
+                {
+                    samples.add(gapsample);
+                }
             }
-            
-            
+
             if(cutoff)
             {
                 lst.add(samples);
                 samples = new LinkedList<>();
+                cutoff=false;
             }
+
+
+            c1+=2;
+        }
+        if(lst.size()>10)
+        {
+            System.err.println("SUS LSTLEN>10@:"+lst.size());
+            System.exit(0);
         }
-        
         for(int i=0;i<lst.size();i++)
         {
             RandomAccessFile out = new RandomAccessFile(basepath+"track"+i+".raw","rw");
             List<Short> file = lst.get(i);
             for(int j=0;j<file.size();j++)
             {
-                out.writeShort(file.get(j));
+                out.writeShort(Short.reverseBytes(file.get(j)));
             }
             out.close();
         }