123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package QuickVerifyCrap;
- import java.io.FileNotFoundException;
- import java.io.RandomAccessFile;
- import java.math.BigInteger;
- import java.nio.ByteBuffer;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.List;
- 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
- public static void main(String[] args) throws Exception
- {
- long[] edges_ch1 = null;
- long[] edges_ch2 = null;
- String basepath = "/home/tgoerner/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
- ch1.readInt();
- ch1.readInt();
- boolean initialHigh1 = (ch1.readInt()!=0);
- ch1.readDouble();
- ch1.readDouble();
- int countEdges1 = (int) Long.reverseBytes(ch1.readLong());
- if(initialHigh1)
- {
- countEdges1++;
- }
- int writeptr = 0;
- edges_ch1 = new long[countEdges1+1];
- if(initialHigh1)
- {
- edges_ch1[0]=-1;
- writeptr++;
- }
- 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);
- writeptr++;
- }
- edges_ch1[writeptr] = edges_ch1[writeptr-1]+REFRATE;
-
-
- ch2.readLong(); //magic LMAA
- ch2.readInt();
- ch2.readInt();
- boolean initialHigh2 = (ch2.readInt()!=0);
- ch2.readDouble();
- ch2.readDouble();
- int countEdges2 = (int) Long.reverseBytes(ch2.readLong());
- if(initialHigh2)
- {
- countEdges2++;
- }
- writeptr = 0;
- edges_ch2 = new long[countEdges2+1];
- if(initialHigh2)
- {
- edges_ch1[0]=-1;
- writeptr++;
- }
-
- 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);
- writeptr++;
- }
- 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)
- {
- 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))
- {
- 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
- {
- 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;
- }
- 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
- {
- long samplesize = edges_ch2[c2]+edges_ch2[c2+1];
- if(edges_ch2[c2+1]>SAMPLELENGTH_BUFFERED)
- {
- samplesize=SAMPLELENGTH;
- }
- short sample = (short)(((edges_ch2[c2]*32768)/samplesize)*-1);
- samples.add(sample);
- c2+=2;
- }
- else
- {
- System.out.println("ZÖINKS");
- c1=edges_ch1.length;
- c2=edges_ch2.length;
- }
-
-
- if(cutoff)
- {
- lst.add(samples);
- samples = new LinkedList<>();
- }
- }
-
- 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.close();
- }
-
- }
- }
|