static void Main(string[] args) { Parser.Default.ParseArguments <CommandLineOptions>(args) .WithParsed <CommandLineOptions>(opts => { foreach (var file in Directory.GetFiles(opts.Path, "*.RAW", SearchOption.TopDirectoryOnly)) { string simpleFileName = Path.GetFileNameWithoutExtension(file); Console.WriteLine(simpleFileName); using (RawFileReader reader = new RawFileReader(file)) { IAverager averager = reader.GetRawAverager(); System.Collections.Generic.IEnumerable <int> scanList = Enumerable.Range(opts.StartScan, opts.EndScan); IProfileSpectrum avg = averager.AverageProfile(reader, scanList); var masses = avg.GetMz(); var intensities = avg.GetIntensity(); var csv = new StringBuilder(); for (var i = 0; i < masses.Length; i++) { var newLine = string.Format("{0},{1}", masses[i], intensities[i]); csv.AppendLine(newLine); } var filePath = Path.ChangeExtension(file, ".csv"); File.WriteAllText(filePath, csv.ToString()); } } }); }
public static RawFileReader LoadFile(IConnectionInfo info) { if (Readers.TryGetValue(info, out var file)) { return(file); } var newFile = RawFileReader.LoadFile(new ExcelFileProperties(info).FilePath); Readers[info] = newFile; return(newFile); }
private void button2_Click(object sender, EventArgs e) { bool normalized = false; Crossover crossover = Crossover.createThreeWayCrossover(Int32.Parse(txtLowerFreq.Text), Int32.Parse(txtUpperFreq.Text), Int32.Parse(txtLowerTrans.Text), Int32.Parse(txtUpperTrans.Text), 44100, normalized, false, 10.0); RawFileReader rdr = new RawFileReader(lblFileName.Text, 16, 44100, 2); ConvertBitsPerSample bps = new ConvertBitsPerSample(rdr, 24); CrossoverThreeWayFilter filter = new CrossoverThreeWayFilter(bps, crossover); measureErrorDB(filter, crossover.wooferFilterKernel.Length); }
protected override void LoadContent() { base.LoadContent(); // Create a step size based on the largest side length and create a scale factor // for the shader float maxSideLength = (float)Math.Max(width, Math.Max(height, depth)); Vector3 stepSize = new Vector3(1.0f / maxSideLength, 1.0f / maxSideLength, 1.0f / maxSideLength); effect.Parameters["StepSize"].SetValue(stepSize * stepScale); effect.Parameters["ActualSampleDist"].SetValue(stepScale); effect.Parameters["Iterations"].SetValue((int)maxSideLength * (1.0f / stepScale) * 2.0f); Vector3 sizes = new Vector3(width, height, depth); Vector3 scaleFactor = Vector3.One / ((Vector3.One * maxSideLength) / (sizes * Vector3.One)); effect.Parameters["ScaleFactor"].SetValue(new Vector4(scaleFactor, 1.0f)); // Get the scaled volume data. float[] volumeData; RawFileReader tempFileReader = new RawFileReader(); tempFileReader.Open(volumeAssetName, width, height, depth); tempFileReader.GetRawData(out volumeData); tempFileReader.Close(); // Compute the gradient at each voxel and combine them with the isovalues. HalfVector4[] textureData; CreateTextureData(volumeData, out textureData); // Set the data into our Texture3D object, for use in the shader. volumeTexture = new Texture3D(VolumetricRenderer.Game.GraphicsDevice, width, height, depth, 0, TextureUsage.None, SurfaceFormat.HalfVector4); volumeTexture.SetData <HalfVector4>(textureData); effect.Parameters["Volume"].SetValue(volumeTexture); if (transfer2DTex != null) { effect.Parameters["Transfer"].SetValue(transfer2DTex); } }
/// <summary> /// An attempt at a quick method to display the distortion introduced by running /// the input file through the digital crossover. Prints results in the debug /// console. Ideally we want any numerical errors to be less than 120dB, a /// level that will be inaudible. /// </summary> private void measureErrorDB(CrossoverThreeWayFilter filter, int kernelLength) { double[] filterData = new double[1024 * 10 * 6]; double[] fileData = new double[1024 * 10 * 2]; double[] filterSum = new double[1024 * 10 * 2]; Dictionary <Int32, Int32> dict = new Dictionary <Int32, Int32>(); RawFileReader rdr2 = new RawFileReader(lblFileName.Text, 16, 44100, 2); ConvertBitsPerSample bps2 = new ConvertBitsPerSample(rdr2, 24); filter.read(filterData, 0, (kernelLength / 2) * 6); while (true) { int nReadFilter = filter.read(filterData, 0, filterData.Length); if (nReadFilter == 0) { break; } int nReadFile = bps2.read(fileData, 0, fileData.Length); if (nReadFile * 3 != nReadFilter) { break; } //throw new Exception("" + (nReadFile * 3) + "!=" + nReadFilter); for (int i = 0; i < nReadFilter; i += 6) { filterSum[i / 3] = filterData[i] + filterData[i + 2] + filterData[i + 4]; filterSum[i / 3 + 1] = filterData[i + 1] + filterData[i + 3] + filterData[i + 5]; } for (int i = 0; i < fileData.Length; i++) { int error = (int)Math.Round(Math.Log10(Math.Abs(filterSum[i] - fileData[i]) / fileData[i]) * 20.0); if (dict.ContainsKey(error)) { dict[error]++; } else { dict.Add(error, 1); } } } Console.Out.WriteLine("Max noise: " + dict.Keys.Max() + " dB"); List <Int32> keys = new List <int>(dict.Keys); keys.Sort(); foreach (int k in keys) { Console.Out.WriteLine("" + k + " dB: " + dict[k]); } }
private void btnPlay_Click(object sender, EventArgs e) { IAudioFilter waveRdr; // For the purposes of testing we process .raw files as // containing 16-bit stereo PCM data at 44.1KHz. This is much // like a .wav file but without the header. if (lblFileName.Text.EndsWith(".raw")) { waveRdr = new RawFileReader(lblFileName.Text, 16, 44100, 2); } else { IWaveSource inputFile = CodecFactory.Instance.GetCodec(lblFileName.Text); waveRdr = new WaveSourceReader(inputFile); } // Convert to 24 bit samples (if needed) ConvertBitsPerSample bpsConvert = new ConvertBitsPerSample(waveRdr, 24); // Create a crossover and catch any errors in case the frequency parameters // are not valid Crossover crossover; try { crossover = Crossover.createThreeWayCrossover(Int32.Parse(txtLowerFreq.Text), Int32.Parse(txtUpperFreq.Text), Int32.Parse(txtLowerTrans.Text), Int32.Parse(txtUpperTrans.Text), waveRdr.SampleRate, true, false, 10.0); } catch (Exception ex) { MessageBox.Show(this, "Error building crossover: " + ex.Message); return; } // Start creating filters... CrossoverThreeWayFilter filter = new CrossoverThreeWayFilter(bpsConvert, crossover); sampleTap = new SampleTap(filter, SAMPLE_LEN); int crossoverIdx = 1; if (rdoPlayWoofer.Checked) { crossoverIdx = 0; } else if (rdoPlayMidrange.Checked) { crossoverIdx = 1; } else if (rdoPlayTweeter.Checked) { crossoverIdx = 2; } channelSelectFilter = new SelectCrossover(sampleTap, crossoverIdx); volumeControlFilter = new VolumeControl(channelSelectFilter); // Only needed for playback through Windows lastFilterStep = new ConvertBitsPerSample(volumeControlFilter, 16); // Done creating filters... tbarFilePosition.Value = 0; // Max in seconds tbarFilePosition.Maximum = (int)(lastFilterStep.Length / lastFilterStep.SampleRate / lastFilterStep.NumberOfChannels); tbarFilePosition.Enabled = true; // Playback through Windows IWaveSource finalWaveSource = new FilterToWaveSource(lastFilterStep); //_soundOut = new WasapiOut(); soundOutDevice = new WaveOut(); soundOutDevice.Initialize(finalWaveSource); soundOutDevice.Play(); tmrUpdateViz.Start(); }
protected DataContextBase(RawFileReader rawFileReader) { RawFileReader = rawFileReader; }
internal ModelImportStatus DoCollarImport(string SelectedFile, string SelectedFormatBMFile, ImportDataMap importMap, RawFileReader rawFileReader, Guid NKDProjectID, bool overwrite) { BaseImportTools bit = new BaseImportTools(); // get the current collar names in this project List <CollarInfo> existingHoles = this.GetHolesForProject(NKDProjectID); List <string> existingHoleNames = new List <string>(); foreach (CollarInfo ci in existingHoles) { existingHoleNames.Add(ci.Name); } ModelImportStatus mos = new ModelImportStatus(); Stream fileStream = new FileStream(SelectedFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Stream fileStream = new FileStream(SelectedFile, FileMode.Open); bit.PerformCollarImport(mos, fileStream, null, importMap, this.backgroundWorker, NKDProjectID, ConnectionString, existingHoleNames, overwrite); return(mos); }
/// <summary> /// Carry out the block model import /// </summary> /// <param name="SelectedBMFile"></param> /// <param name="SelectedFormatBMFile"></param> /// <param name="importMap"></param> /// <param name="rawFileReader"></param> /// <returns></returns> internal bool DoBMImport(string SelectedBMFile, string SelectedFormatBMFile, ImportDataMap importMap, RawFileReader rawFileReader, string NKDProjectID, string modelAlias) { BaseImportTools bit = new BaseImportTools(); int cxColumnID = importMap.GetColumnIDMappedTo("CentroidX"); int cyColumnID = importMap.GetColumnIDMappedTo("CentroidY"); int czColumnID = importMap.GetColumnIDMappedTo("CentroidZ"); ColumnStats xOrigin = rawFileReader.GetDimensions(cxColumnID); ColumnStats yOrigin = rawFileReader.GetDimensions(cyColumnID); ColumnStats zOrigin = rawFileReader.GetDimensions(czColumnID); int approxNumLines = xOrigin.count; Stream bmFileStream = new FileStream(SelectedBMFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); // Stream bmFileStream = new FileStream(SelectedBMFile, FileMode.Open); ModelImportStatus mos = new ModelImportStatus(); Guid newModelGuid = Guid.NewGuid(); Guid authorGuid = new Guid(); List <string> status = bit.PerformBMImport(mos, newModelGuid, bmFileStream, null, importMap, xOrigin.min, yOrigin.min, zOrigin.min, backgroundWorker, approxNumLines, NKDProjectID, modelAlias, authorGuid, ConnectionString); return(true); }
internal ModelImportStatus DoLithoImport(string SelectedFile, string SelectedFormatFile, ImportDataMap importMap, RawFileReader rawFileReader, Guid NKDProjectID, bool doOverwrite, bool checkForDuplicates) { BaseImportTools bit = new BaseImportTools(); ModelImportStatus mos = new ModelImportStatus(); GeneralFileInfo gfi = new GeneralFileInfo(); gfi.GeneralFileStats(SelectedFile); int numLines = gfi.numLines; //Stream fileStream = new FileStream(SelectedFile, FileMode.Open); Stream fileStream = new FileStream(SelectedFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); bit.PerformLithoImport(mos, fileStream, null, importMap, this.backgroundWorker, NKDProjectID, ConnectionString, numLines, doOverwrite, checkForDuplicates); return(mos); }