public async Task EventBasedReconstruction(byte[] aedatFile, CameraParameters cam, int eventsPerFrame, int maxFrames, StorageFolder folder, string fileName) { int frameCount = 0; int eventCount = 0; int endOfHeaderIndex = AedatUtilities.GetEndOfHeaderIndex(ref aedatFile); // find end of aedat header string fileConent = ""; // Read through AEDAT file for (int i = endOfHeaderIndex, length = aedatFile.Length; i < length; i += AedatUtilities.dataEntrySize) // iterate through file, 8 bytes at a time. { AEDATEvent currentEvent = new AEDATEvent(aedatFile, i, cam); fileConent += $"{currentEvent.onOff},{currentEvent.x},{currentEvent.y},{currentEvent.time}\n"; eventCount++; if (eventCount >= eventsPerFrame) // Collected events within specified timeframe, add frame to video { eventCount = 0; StorageFile file = await folder.CreateFileAsync(fileName + frameCount + ".csv", CreationCollisionOption.GenerateUniqueName); await FileIO.WriteTextAsync(file, "On/Off,X,Y,Timestamp\n" + fileConent); fileConent = ""; frameCount++; // Stop adding frames to video if max frames has been reached if (frameCount >= maxFrames) { return; } } } }
public async Task TimeBasedReconstruction(byte[] aedatFile, CameraParameters cam, int frameTime, int maxFrames, StorageFolder folder, string fileName) { int lastTime = -999999; int timeStamp; int frameCount = 0; int endOfHeaderIndex = AedatUtilities.GetEndOfHeaderIndex(ref aedatFile); // find end of aedat header string fileConent = ""; // Read through AEDAT file for (int i = endOfHeaderIndex, length = aedatFile.Length; i < length; i += AedatUtilities.dataEntrySize) // iterate through file, 8 bytes at a time. { AEDATEvent currentEvent = new AEDATEvent(aedatFile, i, cam); fileConent += currentEvent.onOff + "," + currentEvent.x + "," + currentEvent.y + "," + currentEvent.time + "\n"; timeStamp = currentEvent.time; if (lastTime == -999999) { lastTime = timeStamp; } else { if (lastTime + frameTime <= timeStamp) // Collected events within specified timeframe, add frame to video { try { StorageFile file = await folder.CreateFileAsync(fileName + frameCount + ".csv", CreationCollisionOption.GenerateUniqueName); await FileIO.WriteTextAsync(file, "On/Off,X,Y,Timestamp\n" + fileConent); } catch { } fileConent = ""; frameCount++; // Stop adding frames to video if max frames has been reached if (frameCount >= maxFrames) { break; } lastTime = timeStamp; } } } }
/// <summary> /// Gets the first timestamp and the last timestamp /// </summary> /// <param name="file"></param> private async void getData(StorageFile file) { byte[] currentDataEntry = new byte[AedatUtilities.dataEntrySize]; int timeStamp = 0; Queue <byte> dataEntryQ = new Queue <byte>(); byte[] result; // All of the bytes in the AEDAT file loaded into an array using (Stream stream = await file.OpenStreamForReadAsync()) { using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); result = memoryStream.ToArray(); } } int endOfHeaderIndex = AedatUtilities.GetEndOfHeaderIndex(ref result); foreach (byte byteIn in result.Skip(endOfHeaderIndex)) //get the first timestamp; { if (dataEntryQ.Count < AedatUtilities.dataEntrySize) { dataEntryQ.Enqueue(byteIn); } else { dataEntryQ.CopyTo(currentDataEntry, 0); Array.Reverse(currentDataEntry); timeStamp = BitConverter.ToInt32(currentDataEntry, 0); // Timestamp is found in the first four bytes break; } } // Get final data entry int endingTime = 0; byte[] finalDataEntry = new byte[AedatUtilities.dataEntrySize]; int i = 0; for (int j = result.Count() - 1; j > result.Count() - 9; j--) { finalDataEntry[i] = result[j]; i++; } endingTime = BitConverter.ToInt32(finalDataEntry, 0); // Timestamp is found in the first four bytes // Convert to seconds double startingTime = (double)timeStamp / 1000000.000f; double endingTime2 = (double)endingTime / 1000000.000f; // Total number of events in the file double eventCount = (result.Count() - endOfHeaderIndex) / 8; // Add data to GUI tableData.Add(new AEDATData { name = file.Name.Replace(".aedat", "").Replace(".AEDAT", ""), startingTime = startingTime, eventCount = eventCount, endingTime = endingTime2, avgEventsPerSecond = eventCount / Math.Abs(endingTime2 - startingTime), duration = endingTime2 - startingTime }); }