public override void Initialize(AudioCaptureInitializeArgs captureArgs) { Microphone = Microphone.Default; Microphone.BufferDuration = TimeSpan.FromMilliseconds(100); // 100 minimum Microphone.BufferReady += Microphone_BufferReady; Resampler = new Resampler(DesiredClockRate / 16000); RunOnUIThread(() => { XnaTimer = new DispatcherTimer(); XnaTimer.Interval = TimeSpan.FromMilliseconds(50); XnaTimer.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } }; XnaTimer.Start(); }); }
private void btnCreate_Click(object sender, EventArgs e) { string srcBits = txtSequence.Text; double BT = 0; double Oversampling = 0; try { BT = double.Parse(txtBT.Text); Oversampling = double.Parse(txtOversampling.Text); } catch (ArgumentException) { MessageBox.Show("Invalid parameter. Either BT or Oversampling value is wrong."); return; } double[] srcData = new double[srcBits.Length]; for (int pos = 0; pos < srcBits.Length; pos++) { if (srcBits.Substring(pos, 1) == "1") { srcData[pos] = 1.0; } else if (srcBits.Substring(pos, 1) == "0") { srcData[pos] = -1.0; } else { MessageBox.Show("Invalid binary sequence."); return; } } // byte[] srcData = new byte[] {0xB9, 0x62, 0x04, 0x0F, 0x2D, 0x45, 0x76, 0x1B}; // srcData = DifferenceCode.Encode(srcData); Resampler sampler = new Resampler((decimal)Oversampling); double[] samples = sampler.Resample(srcData); GaussFilter filter = new GaussFilter(BT); double[] gaussSamples = filter.Process(samples, Oversampling); waveformDisplay.Clear(); waveformDisplay.XAxisUnit = Oversampling; waveformDisplay.XAxisGridOffset = 128; waveformDisplay.ProcessData(new double[128]); waveformDisplay.ProcessData(gaussSamples); if (ShmemChannel != null) { double[] diffSamples = Differenciator.Differenciate(gaussSamples); ShmemChannel.Write(ByteUtil.convertToBytesInterleaved(gaussSamples, diffSamples)); } }
public static void Main(string[] args) { try { var demuxer = new Demuxer(); demuxer.Open("C:\\Temp\\Gus.mp3"); Console.WriteLine("Demuxer opened"); var audioParameters = demuxer.GetAudioDecoder().GetAudioParameters() .SetMediaType(MediaType.Audio) .SetCodecType(CodecType.PCM_Signed16BitLittleEndian) .SetSampleRate(44100) .SetBitRate(16 * 44100 * 2) .SetAudioChannelLayout(0x00000003) .SetChannelCount(2) .SetSampleFormat(SampleFormat.Signed16Bit) .SetTimeBase(new RationalNumber(1, 44100)); var muxer = new Muxer(); muxer.Open("C:\\Temp\\Gus.wav", audioParameters, null); Console.WriteLine("Muxer opened"); var resampler = new Resampler(); resampler.Initialise(demuxer.GetAudioDecoder().GetCodec(), muxer.GetAudioEncoder().GetCodec()); var frames = 0; demuxer.FrameDecodedEvent += (frameWrapper) => { switch (frameWrapper.GetMediaType()) { case MediaType.Audio: var resampledFrame = resampler.Convert(frameWrapper); muxer.AddToBuffer(resampledFrame); if (resampler.Flush(resampledFrame) > 0) { muxer.AddToBuffer(resampledFrame); } frames++; Console.WriteLine($"\r{frames} frames decoded"); break; case MediaType.Video: // TODO break; default: break; } }; demuxer.DecodePackets(MediaType.Audio); Console.WriteLine($"\r{frames} audio frames decoded - muxing..."); muxer.WriteBuffer(); Console.WriteLine("Mux complete - cleaning up..."); muxer.Close(); demuxer.Close(); Console.WriteLine("Finished"); } catch (Exception ex) { Console.WriteLine($"Exception: {ex}"); } Console.WriteLine("Enter a character to go away..."); Console.ReadKey(); }
public void CanCreateResamplerMediaObject() { Resampler resampler = new Resampler(); }
private bool IsResamplerInputFormatSupported(WaveFormat waveFormat) { Resampler resampler = new Resampler(); return(resampler.MediaObject.SupportsInputWaveFormat(0, waveFormat)); }
public void SetSoftwareFormat(int samplerate, Format format, int numoutputchannels, int maxinputchannels, Resampler resamplemethod) { Code returnCode = SetSoftwareFormat(DangerousGetHandle(), samplerate, format, numoutputchannels, maxinputchannels, resamplemethod); Errors.ThrowError(returnCode); }
public SequenceGenerator(double oversampling, double BT) { Oversampling = oversampling; Sampler = new Resampler((decimal)Oversampling); Filter = new GaussFilter(BT); }
public void Create() { Stopwatch sw; // var t1 = TextureHelper.LoadTiff16(@"Datasets\Planets\Venus\Venus_Magellan_Topography_Global_4641m_v02.tif"); // for(int y = 0;y<t1.Height;y++) // for(int x = 0;x<t1.Width;x++) // { // short h = t1.Data[y][x]; // if(h != -32678) // NoData // t1.Data[y][x] += 2951; // } // TextureHelper.SaveRaw16(@"Datasets\Planets\Venus\Venus_Magellan_Topography_Global_4641m_v02.raw", t1); // var t1 = TextureHelper.LoadRaw16(@"Datasets\Planets\Venus\Venus_Magellan_Topography_Global_4641m_v02_ca2.raw", 8192, 4096); // for(int y = 0;y<t1.Height;y++) // for(int x = 0;x<t1.Width;x++) // t1.Data[y][x] -= 2951; // TextureHelper.SaveRaw16(@"Datasets\Planets\Venus\Venus_Magellan_Topography_Global_4641m_v02_ca2.raw", t1); int width = 2880; int height = 1440; string elevationTextureSmallFilename = $@"Generated\Planets\Venus\Venus{width}x{height}.raw"; if (!File.Exists(elevationTextureSmallFilename)) { sw = Stopwatch.StartNew(); var elevationTextureLarge = TextureHelper.LoadRaw16(@"Datasets\Planets\Venus\Venus_Magellan_Topography_Global_4641m_v02_ca2.raw", 8192, 4096); Console.WriteLine($"Loading texture used {sw.Elapsed}"); // sw = Stopwatch.StartNew(); // var elevationTextureLarge8 = TextureHelper.LoadAny8(@"Datasets\Planets\Venus\4kVenus.png"); // var elevationTextureLarge = TextureHelper.Convert(elevationTextureLarge8, (p) => {return (short)(p*64);}); // Console.WriteLine($"Loading texture used {sw.Elapsed}"); sw = Stopwatch.StartNew(); _elevationTextureSmall = Resampler.Resample(elevationTextureLarge, width, height); Console.WriteLine($"Resampling used {sw.Elapsed}"); TextureHelper.SaveRaw16($@"Generated\Planets\Venus\Venus{_elevationTextureSmall.Width}x{_elevationTextureSmall.Height}.raw", _elevationTextureSmall); } else { _elevationTextureSmall = TextureHelper.LoadRaw16(elevationTextureSmallFilename, width, height); } TextureHelper.SavePng8($@"Generated\Planets\Venus\Venus{_elevationTextureSmall.Width}x{_elevationTextureSmall.Height}.png", _elevationTextureSmall); string elevationTextureBlurFilename = $@"Generated\Planets\Venus\VenusBlur{width}x{height}.raw"; if (!File.Exists(elevationTextureBlurFilename)) { sw = Stopwatch.StartNew(); var blurFilter = new BlurFilter(PlanetProjection); _elevationTextureBlur = blurFilter.Blur3(_elevationTextureSmall, MathHelper.ToRadians(10)); Console.WriteLine($"Blur used {sw.Elapsed}"); TextureHelper.SaveRaw16($@"Generated\Planets\Venus\VenusBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.raw", _elevationTextureBlur); } else { _elevationTextureBlur = TextureHelper.LoadRaw16(elevationTextureBlurFilename, width, height); } TextureHelper.SavePng8($@"Generated\Planets\Venus\VenusBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.png", _elevationTextureBlur); sw = Stopwatch.StartNew(); CreatePlanetVertexes(RecursionLevel); Console.WriteLine($"Time used to create planet vertexes: {sw.Elapsed}"); SaveSTL($@"Generated\Planets\Venus\Venus{RecursionLevel}.stl"); }
private IEnumerator _Import(ImportInfo info) { var componentManager = ComponentManager.Instance; var dialogManager = componentManager.Get <ModalDialogManager>(); var dataManager = componentManager.Get <DataManager>(); var dataLayers = componentManager.Get <DataLayers>(); bool addedGroupOrLayer = false; // Create group if necessary (also UI panel) DataLayerGroupPanel groupPanel; var group = info.group; if (group == null) { group = dataManager.AddLayerGroup(info.newGroupName); groupPanel = dataLayers.AddLayerGroup(group.name); addedGroupOrLayer = true; } else { groupPanel = dataLayers.GetLayerGroup(group.name); } // Create layer if necessary (also UI panel) var layer = info.layer; if (layer == null) { var layerName = info.newLayerName; layer = group.GetLayer(layerName); if (layer == null) { layer = new DataLayer(dataManager, layerName, info.newLayerColor, group); dataLayers.AddLayer(layer, groupPanel); addedGroupOrLayer = true; } } if (layer.Group != group) { Debug.LogError("Selected group doesn't match selected layer's group"); yield break; } if (addedGroupOrLayer) { dataManager.UpdateLayerConfig(); } var filename = info.inputFilename; var resX = info.resolution.ToDegrees(); var resY = resX; Resampler resampler = null; if (info.needsResampling) { //+ TODO: create appropriate resampler resampler = new NearestNeighbourResampler(); } // Create output directory Directory.CreateDirectory(Path.GetDirectoryName(info.outputFilename)); bool patchAlreadyExists = File.Exists(info.outputFilename); // Show progress bar var progressDialog = dialogManager.NewProgressDialog(); progressDialog.SetMessage(Translator.Get("Importing") + " " + Path.GetFileName(filename)); progressDialog.SetProgress(0); var threadInfo = new ImportThreadInfo { inputFilename = filename, outputFilename = info.outputFilename, resX = resX, resY = resY, units = info.units, metadata = info.metadata, resampler = resampler, running = true }; threadInfo.thread = new Thread(() => ImportThread(threadInfo)) { Name = "ImportDataThread" }; threadInfo.thread.Start(); // Import data do { yield return(null); progressDialog.SetProgress(threadInfo.progress.Total()); }while (threadInfo.running); yield return(null); if (patchAlreadyExists) { dataManager.ReloadPatches(layer, info.site.Name, info.level, info.year); } else { yield return(layer.CreatePatch(info.outputFilename)); } yield return(null); // Update Site Browser var siteBrowser = componentManager.Get <SiteBrowser>(); if (info.site != null && info.site == siteBrowser.ActiveSite) { siteBrowser.UpdateMinMaxLevels(); } else { // If it's the first site, it will change to the new site automatically siteBrowser.RebuildList(); } yield return(null); // Update the Data Layers list componentManager.Get <DataLayers>().UpdateLayers(); yield return(null); // Hide the progress progressDialog.Close(); // Send the event that the import process has finished var site = info.site; if (site == null) { dataManager.TryGetSite(info.newSiteName, out site); } info.OnFinishImport.Invoke(site, layer); // Destroy this (the importer) game object Destroy(gameObject); }
public void Create() { var targetPath = $@"Generated\Planets\Earth\{Name}"; Directory.CreateDirectory(targetPath); int lat0deg = (int)Math.Floor(MathHelper.ToDegrees(Lat0)); int lat1deg = (int)Math.Floor(MathHelper.ToDegrees(Lat1)); int lon0deg = (int)Math.Floor(MathHelper.ToDegrees(Lon0)); int lon1deg = (int)Math.Floor(MathHelper.ToDegrees(Lon1)); double lat0 = MathHelper.ToRadians(lat0deg + 1); double lat1 = MathHelper.ToRadians(lat1deg); double lon0 = MathHelper.ToRadians(lon0deg); double lon1 = MathHelper.ToRadians(lon1deg + 1); // Calculate sector transform _sx = Math.PI * 2 / (lon1 - lon0); _sy = Math.PI / (lat0 - lat1); _sx0 = (Math.PI + lon0) / (Math.PI * 2) * _sx; _sy0 = (Math.PI / 2 - lat0) / Math.PI * _sy; // -- int totalWidth = 3601 * 360; int totalHeight = 3601 * 180; int sectorHeight = (int)Math.Round(totalHeight * (Lat0 - Lat1) / Math.PI); int sectorWidth = (int)Math.Round(totalWidth * (Lon1 - Lon0) / (Math.PI * 2)); Console.WriteLine($"Using image sector {sectorWidth}x{sectorHeight}"); var sw = Stopwatch.StartNew(); if (UseAster) { using (var demReader = new DemZipTiffReader(@"Datasets\Planets\Earth\ASTER.zip", "ASTGTM2_{0}_dem.tif", 3601, 3601)) { var elevationSectorBitmap = demReader.LoadBitmap(lat0deg, lon0deg, lat1deg, lon1deg); Console.WriteLine($"Loading ASTER image {elevationSectorBitmap.Width}x{elevationSectorBitmap.Height}"); int w = Math.Min(elevationSectorBitmap.Width, (elevationSectorBitmap.Width * NumSegmentsLon) / sectorWidth); int h = Math.Min(elevationSectorBitmap.Height, (elevationSectorBitmap.Height * NumSegmentsLat) / sectorHeight); _elevationSectorBitmap = Resampler.Resample(elevationSectorBitmap, w, h).ToBitmap(); } } else { using (var demReader = new DemZipRawReader(@"Datasets\Planets\Earth\SRTM.zip", "{0}.hgt", 3601, 3601)) { var elevationSectorBitmap = demReader.LoadBitmap(lat0deg, lon0deg, lat1deg, lon1deg); Console.WriteLine($"Loading SRTM image {elevationSectorBitmap.Width}x{elevationSectorBitmap.Height}"); int w = Math.Min(elevationSectorBitmap.Width, (elevationSectorBitmap.Width * NumSegmentsLon) / sectorWidth); int h = Math.Min(elevationSectorBitmap.Height, (elevationSectorBitmap.Height * NumSegmentsLat) / sectorHeight); // _elevationSectorBitmap = Resampler.Resample(elevationSectorBitmap, w, h).ToBitmap(); _elevationSectorBitmap = elevationSectorBitmap.ToBitmap(); } } Console.WriteLine($"Loading image sector {_elevationSectorBitmap.Width}x{_elevationSectorBitmap.Height} used {sw.Elapsed}"); using (var tiffWriter = new TiffWriter(File.Create(Path.Combine(targetPath, $"Earth{_elevationSectorBitmap.Width}x{_elevationSectorBitmap.Height}.tif")))) { var bitmap = _elevationSectorBitmap.Convert((p) => { return((ushort)(p - short.MinValue)); }); tiffWriter.WriteImageFile(bitmap); } sw = Stopwatch.StartNew(); var sphericalSector = new SphericalSector(); sphericalSector.ComputeRadiusTop = ComputeModelElevationTop; sphericalSector.Create(Lat0, Lon0, Lat1, Lon1, NumSegmentsLat, NumSegmentsLon, ModelScale * (PlanetRadius + ElevationBottom * ElevationScale)); CenterVertexes(sphericalSector.Vertexes); PlanetVertexes = sphericalSector.Vertexes; PlanetTriangles = sphericalSector.Triangles; Console.WriteLine($"Time used to create planet vertexes: {sw.Elapsed}"); SaveStl(Path.Combine(targetPath, $"{Name}{NumSegmentsLon}_{ElevationScale}x.stl")); }
public void Create() { Stopwatch sw; int width = 2880; int height = 1440; // Topo Bathymetry string elevationTextureSmallFilename = $@"Generated\Planets\Earth\topo.bathymetry.{width}x{height}.raw"; if (!File.Exists(elevationTextureSmallFilename)) { sw = Stopwatch.StartNew(); var elevationTextureLargeW = BitmapHelper.LoadRaw16(@"Datasets\Planets\Earth\Blue Marble\topo.bathymetry.W.21600x21600.raw", 21600, 21600); var elevationTextureLargeE = BitmapHelper.LoadRaw16(@"Datasets\Planets\Earth\Blue Marble\topo.bathymetry.E.21600x21600.raw", 21600, 21600); var elevationTextureLarge = BitmapTools.Concatenate(elevationTextureLargeW, elevationTextureLargeE); elevationTextureLarge = elevationTextureLarge.Convert((p) => { int p2 = ((p >> 8) & 0xff) | ((p << 8) & 0xff00); return((short)(p2 - 32768)); }); Console.WriteLine($"Loading elevation texture used {sw.Elapsed}"); sw = Stopwatch.StartNew(); _elevationTexture = Resampler.Resample(elevationTextureLarge, width, height).ToBitmap(); Console.WriteLine($"Resampling used {sw.Elapsed}"); BitmapHelper.SaveRaw16($@"Generated\Planets\Earth\topo.bathymetry.{_elevationTexture.Width}x{_elevationTexture.Height}.raw", _elevationTexture); } else { _elevationTexture = BitmapHelper.LoadRaw16(elevationTextureSmallFilename, width, height); } BitmapHelper.SaveTiff8($@"Generated\Planets\Earth\topo.bathymetry.{_elevationTexture.Width}x{_elevationTexture.Height}.tif", _elevationTexture); // Landcover string landcoverTextureSmallFilename = $@"Generated\Planets\Earth\landcover.{width}x{height}.raw"; if (!File.Exists(landcoverTextureSmallFilename)) { sw = Stopwatch.StartNew(); var landcoverTextureLargeW = BitmapHelper.LoadRaw8(@"Datasets\Planets\Earth\Blue Marble\landcover.W.21600x21600.raw", 21600, 21600); var landcoverTextureLargeE = BitmapHelper.LoadRaw8(@"Datasets\Planets\Earth\Blue Marble\landcover.E.21600x21600.raw", 21600, 21600); var landcoverTextureLarge = BitmapTools.Concatenate(landcoverTextureLargeW, landcoverTextureLargeE); Console.WriteLine($"Loading landcover texture used {sw.Elapsed}"); var histo = new long[256]; landcoverTextureLarge.Process((p) => { histo[p]++; return(p != 0 ? (byte)0xff : (byte)0x00); }); sw = Stopwatch.StartNew(); _landcoverTextureSmall = Resampler.Resample(landcoverTextureLarge, width, height).ToBitmap(); Console.WriteLine($"Resampling used {sw.Elapsed}"); BitmapHelper.SaveRaw8($@"Generated\Planets\Earth\landcover.{width}x{height}.raw", _landcoverTextureSmall); } else { _landcoverTextureSmall = BitmapHelper.LoadRaw8(landcoverTextureSmallFilename, width, height); } BitmapHelper.SaveTiff8($@"Generated\Planets\Earth\landcover.{width}x{height}.tif", _landcoverTextureSmall); // string elevationTextureBlurFilename = $@"Generated\Planets\Earth\EarthBlur{width}x{height}.raw"; // if(!File.Exists(elevationTextureBlurFilename)) // { // sw = Stopwatch.StartNew(); // var blurFilter = new BlurFilter(PlanetProjection); // _elevationTextureBlur = blurFilter.Blur3(_elevationTexture, MathHelper.ToRadians(10)); // Console.WriteLine($"Blur used {sw.Elapsed}"); // TextureHelper.SaveRaw16($@"Generated\Planets\Earth\EarthBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.raw", _elevationTextureBlur); // } // else // { // _elevationTextureBlur = TextureHelper.LoadRaw16(elevationTextureBlurFilename, width, height); // } // TextureHelper.SaveTiff8($@"Generated\Planets\Earth\EarthBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.tif", _elevationTextureBlur); sw = Stopwatch.StartNew(); CreatePlanetVertexes(RecursionLevel); Console.WriteLine($"Time used to create planet vertexes: {sw.Elapsed}"); SaveStl($@"Generated\Planets\Earth\Earth{RecursionLevel}.stl"); }
public void Create() { Stopwatch sw; int width = 2880; int height = 1440; string elevationTextureSmallFilename = $@"Generated\Planets\Mars\Mars{width}x{height}.raw"; if (!File.Exists(elevationTextureSmallFilename)) { sw = Stopwatch.StartNew(); var elevationTextureLarge = TextureHelper.LoadTiff16(@"Datasets\Planets\Mars\Mars_MGS_MOLA_DEM_mosaic_global_463m.tif"); Console.WriteLine($"Loading texture used {sw.Elapsed}"); sw = Stopwatch.StartNew(); _elevationTextureSmall = Resampler.Resample(elevationTextureLarge, width, height); Console.WriteLine($"Resampling used {sw.Elapsed}"); TextureHelper.SaveRaw16($@"Generated\Planets\Mars\Mars{_elevationTextureSmall.Width}x{_elevationTextureSmall.Height}.raw", _elevationTextureSmall); } else { _elevationTextureSmall = TextureHelper.LoadRaw16(elevationTextureSmallFilename, width, height); } TextureHelper.SavePng8($@"Generated\Planets\Mars\Mars{_elevationTextureSmall.Width}x{_elevationTextureSmall.Height}.png", _elevationTextureSmall); // var sw = Stopwatch.StartNew(); // var elevationTextureLarge = TextureHelper.LoadTiff16(@"Datasets\Planets\Mars\Mars_MGS_MOLA_DEM_mosaic_global_463m.tif"); // Console.WriteLine($"Loading texture used {sw.Elapsed}"); // sw = Stopwatch.StartNew(); // _elevationTextureSmall = Resampler.Resample(elevationTextureLarge, 2400, 1200); // Console.WriteLine($"Resampling used {sw.Elapsed}"); // TextureHelper.SaveRaw16($@"Generated\Planets\Mars\Mars{_elevationTextureSmall.Width}x{_elevationTextureSmall.Height}.raw", _elevationTextureSmall); // TextureHelper.SavePng8($@"Generated\Planets\Mars\Mars{_elevationTextureSmall.Width}x{_elevationTextureSmall.Height}.png", _elevationTextureSmall); string elevationTextureBlurFilename = $@"Generated\Planets\Mars\MarsBlur{width}x{height}.raw"; if (!File.Exists(elevationTextureBlurFilename)) { sw = Stopwatch.StartNew(); var blurFilter = new BlurFilter(PlanetProjection); _elevationTextureBlur = blurFilter.Blur3(_elevationTextureSmall, MathHelper.ToRadians(10)); Console.WriteLine($"Blur used {sw.Elapsed}"); TextureHelper.SaveRaw16($@"Generated\Planets\Mars\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.raw", _elevationTextureBlur); } else { _elevationTextureBlur = TextureHelper.LoadRaw16(elevationTextureBlurFilename, width, height); } TextureHelper.SavePng8($@"Generated\Planets\Mars\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.png", _elevationTextureBlur); // var blurFilter = new BlurFilter(PlanetProjection); // sw = Stopwatch.StartNew(); // _elevationTextureBlur = blurFilter.Blur3(_elevationTextureSmall, MathHelper.ToRadians(10)); // Console.WriteLine($"Blur used {sw.Elapsed}"); // TextureHelper.SaveRaw16($@"Generated\Planets\Mars\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.raw", _elevationTextureBlur); // TextureHelper.SavePng8($@"Generated\Planets\Mars\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.png", _elevationTextureBlur); sw = Stopwatch.StartNew(); CreatePlanetVertexes(RecursionLevel); Console.WriteLine($"Time used to create planet vertexes: {sw.Elapsed}"); SaveSTL($@"Generated\Planets\Mars\Mars{RecursionLevel}.stl"); }
public void Create() { Stopwatch sw; int width = 2880; int height = 1440; // Topo Bathymetry string elevationTextureSmallFilename = $@"Generated\Planets\Earth\topo.bathymetry.{width}x{height}.raw"; if (!File.Exists(elevationTextureSmallFilename)) { sw = Stopwatch.StartNew(); var elevationTextureLarge = TextureHelper.LoadRaw16(@"Datasets\Planets\Earth\Blue Marble\topo.bathymetry.43200x21600.raw", 43200, 21600); Console.WriteLine($"Loading texture used {sw.Elapsed}"); TextureHelper.Process(elevationTextureLarge, (p) => { return((short)(p - 32768)); }); sw = Stopwatch.StartNew(); _elevationTextureSmall = Resampler.Resample(elevationTextureLarge, width, height); Console.WriteLine($"Resampling used {sw.Elapsed}"); TextureHelper.SaveRaw16($@"Generated\Planets\Earth\topo.bathymetry.{_elevationTextureSmall.Width}x{_elevationTextureSmall.Height}.raw", _elevationTextureSmall); } else { _elevationTextureSmall = TextureHelper.LoadRaw16(elevationTextureSmallFilename, width, height); } TextureHelper.SavePng8($@"Generated\Planets\Earth\topo.bathymetry.{_elevationTextureSmall.Width}x{_elevationTextureSmall.Height}.png", _elevationTextureSmall); // Landcover string landcoverTextureSmallFilename = $@"Generated\Planets\Earth\landcover.{width}x{height}.raw"; if (!File.Exists(landcoverTextureSmallFilename)) { sw = Stopwatch.StartNew(); var landcoverTextureLarge = TextureHelper.LoadRaw8(@"Datasets\Planets\Earth\Blue Marble\landcover.43200x21600.raw", 43200, 21600); Console.WriteLine($"Loading texture used {sw.Elapsed}"); var histo = new long[256]; TextureHelper.Process(landcoverTextureLarge, (p) => { histo[p]++; return(p != 0 ? (byte)0xff : (byte)0x00); }); sw = Stopwatch.StartNew(); _landcoverTextureSmall = Resampler.Resample(landcoverTextureLarge, width, height); Console.WriteLine($"Resampling used {sw.Elapsed}"); TextureHelper.SaveRaw8($@"Generated\Planets\Earth\landcover.{width}x{height}.raw", _landcoverTextureSmall); } else { _landcoverTextureSmall = TextureHelper.LoadRaw8(landcoverTextureSmallFilename, width, height); } TextureHelper.SavePng8($@"Generated\Planets\Earth\landcover.{width}x{height}.png", _landcoverTextureSmall); // string elevationTextureBlurFilename = $@"Generated\Planets\Earth\EarthBlur{width}x{height}.raw"; // if(!File.Exists(elevationTextureBlurFilename)) // { // sw = Stopwatch.StartNew(); // var blurFilter = new BlurFilter(PlanetProjection); // _elevationTextureBlur = blurFilter.Blur3(_elevationTextureSmall, MathHelper.ToRadians(10)); // Console.WriteLine($"Blur used {sw.Elapsed}"); // TextureHelper.SaveRaw16($@"Generated\Planets\Earth\EarthBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.raw", _elevationTextureBlur); // } // else // { // _elevationTextureBlur = TextureHelper.LoadRaw16(elevationTextureBlurFilename, width, height); // } // TextureHelper.SavePng8($@"Generated\Planets\Earth\EarthBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.png", _elevationTextureBlur); sw = Stopwatch.StartNew(); CreatePlanetVertexes(RecursionLevel); Console.WriteLine($"Time used to create planet vertexes: {sw.Elapsed}"); SaveSTL($@"Generated\Planets\Earth\Earth{RecursionLevel}.stl"); }
private static extern Code GetSoftwareFormat(IntPtr system, ref int samplerate, ref Format format, ref int numoutputchannels, ref int maxinputchannels, ref Resampler resamplemethod, ref int bits);
private static extern Code SetSoftwareFormat(IntPtr system, int samplerate, Format format, int numoutputchannels, int maxinputchannels, Resampler resamplemethod);
public static IResampler GetInstance(this Resampler mode) { if (mode == Resampler.NearestNeighbor) { return(new NearestNeighborResampler()); } if (mode == Resampler.Box) { return(new BoxResampler()); } if (mode == Resampler.Triangle) { return(new TriangleResampler()); } if (mode == Resampler.Bicubic) { return(new BicubicResampler()); } if (mode == Resampler.Spline) { return(new SplineResampler()); } if (mode == Resampler.CatmullRom) { return(new CatmullRomResampler()); } if (mode == Resampler.Hermite) { return(new HermiteResampler()); } if (mode == Resampler.Robidoux) { return(new RobidouxResampler()); } if (mode == Resampler.RobidouxSharp) { return(new RobidouxSharpResampler()); } if (mode == Resampler.Welch) { return(new WelchResampler()); } if (mode == Resampler.Lanczos2) { return(new Lanczos2Resampler()); } if (mode == Resampler.Lanczos3) { return(new Lanczos3Resampler()); } if (mode == Resampler.Lanczos5) { return(new Lanczos5Resampler()); } if (mode == Resampler.Lanczos8) { return(new Lanczos8Resampler()); } if (mode == Resampler.MitchellNetravali) { return(new MitchellNetravaliResampler()); } throw new NotImplementedException(); }
public void Create() { Stopwatch sw; int width = 2880; int height = 1440; string elevationTextureFilename = $@"Generated\Planets\Mars2\Mars{width}x{height}.tif"; if (!File.Exists(elevationTextureFilename)) { sw = Stopwatch.StartNew(); using (var tiffReader = new TiffReader(File.OpenRead(@"Datasets\Planets\Mars\Mars_HRSC_MOLA_BlendDEM_Global_200mp.tif"))) { // Right-most pixel column in the Mars dataset is broken. This trick will skip it. var ifd = tiffReader.ImageFileDirectories[0]; var elevationTexture = tiffReader.ReadImageFile <short>(0, 0, ifd.ImageWidth - 1, ifd.ImageHeight); _elevationTexture = Resampler.Resample(elevationTexture, width, height).ToBitmap(); Console.WriteLine($"Resampling used {sw.Elapsed}"); } BitmapHelper.SaveTiff16(elevationTextureFilename, _elevationTexture); } else { _elevationTexture = BitmapHelper.LoadTiff16(elevationTextureFilename); } //BitmapHelper.SaveTiff8($@"Generated\Planets\Mars2\Mars{_elevationTexture.Width}x{_elevationTexture.Height}.tif", _elevationTexture); // Blur string elevationTextureBlurFilename = $@"Generated\Planets\Mars2\MarsBlur{width}x{height}.tif"; if (!File.Exists(elevationTextureBlurFilename)) { sw = Stopwatch.StartNew(); var blurFilter = new BlurFilter(Projection.Equirectangular); _elevationTextureBlur = blurFilter.Blur3(_elevationTexture, MathHelper.ToRadians(10)); Console.WriteLine($"Blur used {sw.Elapsed}"); BitmapHelper.SaveTiff16(elevationTextureBlurFilename, _elevationTextureBlur); } else { _elevationTextureBlur = BitmapHelper.LoadTiff16(elevationTextureBlurFilename); } //BitmapHelper.SaveTiff8($@"Generated\Planets\Mars2\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.tif", _elevationTextureBlur); Init(); sw = Stopwatch.StartNew(); Split(); Console.WriteLine($"Time used to split planet geometry: {sw.Elapsed}"); PrintSummary(); sw = Stopwatch.StartNew(); Merge(); Console.WriteLine($"Time used to merge planet geometry: {sw.Elapsed}"); PrintSummary(); SaveStl("Generated/Planets/Mars2/Mars2.stl"); }
private void WasapiIn_DataAvailable(object sender, WaveInEventArgs e) { if (WasapiInBuffer == null) { WasapiInBuffer = new byte[48000]; WasapiOutBuffer = new byte[48000]; if (DesiredClockRate != WasapiIn.WaveFormat.SampleRate) { Resampler = new Resampler(WasapiIn.WaveFormat.SampleRate, DesiredClockRate); } } byte[] inputBuffer; int inputLength = 0; if (WasapiIn.WaveFormat.BitsPerSample == 32) { // convert to shorts var sampleCount = e.BytesRecorded / 4; FloatBytesToShortBytes(e.Buffer, 0, WasapiInBuffer, 0, sampleCount); inputBuffer = WasapiInBuffer; inputLength = sampleCount * 2; } else { inputBuffer = e.Buffer; inputLength = e.BytesRecorded; } var buffer = new AudioBuffer(inputBuffer, 0, inputLength); if (Resampler.ResampleAndConvert(buffer, Resampler, WasapiIn.WaveFormat.Channels, DesiredChannels)) { RaiseFrame(buffer); } else { Log.Error("Could not resample captured audio."); } }
public void Create() { double dLat = Lat0 - Lat1; double dLon = Lon1 - Lon0; // Calculate sector transform _sx = Math.PI * 2 / dLon; _sy = Math.PI / dLat; _sx0 = (Math.PI + Lon0) / (Math.PI * 2) * _sx; _sy0 = (Math.PI / 2 - Lat0) / Math.PI * _sy; Stopwatch sw; sw = Stopwatch.StartNew(); using (var tiffReader = new TiffReader(File.OpenRead(@"Datasets\Planets\Mars\Mars_HRSC_MOLA_BlendDEM_Global_200mp.tif"))) { var ifd = tiffReader.ImageFileDirectories[0]; _elevationWidth = ifd.ImageWidth; _elevationHeight = ifd.ImageHeight; _sectorOffsetY = (int)(_elevationHeight * (Math.PI / 2 - Lat0) / Math.PI); _sectorOffsetX = (int)(_elevationWidth * (Math.PI + Lon0) / (Math.PI * 2)); _sectorHeight = (int)Math.Ceiling(_elevationHeight * dLat / Math.PI); _sectorWidth = (int)Math.Ceiling(_elevationWidth * dLon / (Math.PI * 2)); _elevationSectorBitmap = tiffReader.ReadImageFile <short>(ifd, _sectorOffsetX, _sectorOffsetY, _sectorWidth, _sectorHeight).ToBitmap(); Console.WriteLine($"Loading image sector used {sw.Elapsed}"); // _elevationSectorBitmap = Resampler.Resample(elevationBitmap, width, height).ToBitmap(); // Console.WriteLine($"Resampling used {sw.Elapsed}"); using (var tiffWriter = new TiffWriter(File.Create($@"Generated\Planets\MarsSector\Mars{_elevationSectorBitmap.Width}x{_elevationSectorBitmap.Height}.tif"))) { var bitmap = _elevationSectorBitmap.Convert((p) => { return((ushort)(p - short.MinValue)); }); tiffWriter.WriteImageFile(bitmap); } BitmapHelper.SaveTiff8($@"Generated\Planets\MarsSector\Mars{_elevationSectorBitmap.Width}x{_elevationSectorBitmap.Height}.tif", _elevationSectorBitmap); int width = 2880; int height = 1440; string elevationTextureBlurFilename = $@"Generated\Planets\MarsSector\MarsBlur{width}x{height}.raw"; if (!File.Exists(elevationTextureBlurFilename)) { var elevationTextureSmall = Resampler.Resample(_elevationSectorBitmap, width, height).ToBitmap(); sw = Stopwatch.StartNew(); var blurFilter = new BlurFilter(PlanetProjection); _elevationBitmapBlur = blurFilter.Blur3(elevationTextureSmall, MathHelper.ToRadians(10)); Console.WriteLine($"Blur used {sw.Elapsed}"); BitmapHelper.SaveRaw16($@"Generated\Planets\MarsSector\MarsBlur{_elevationBitmapBlur.Width}x{_elevationBitmapBlur.Height}.raw", _elevationBitmapBlur); BitmapHelper.SaveTiff8($@"Generated\Planets\MarsSector\MarsBlur{_elevationBitmapBlur.Width}x{_elevationBitmapBlur.Height}.tif", _elevationBitmapBlur); } else { _elevationBitmapBlur = BitmapHelper.LoadRaw16(elevationTextureBlurFilename, width, height); } } sw = Stopwatch.StartNew(); var sphericalSector = new SphericalSector(); sphericalSector.ComputeRadiusTop = ComputeModelElevationTop; sphericalSector.Create(Lat0, Lon0, Lat1, Lon1, NumSegments, NumSegments, PlanetRadius - 50000); PlanetVertexes = sphericalSector.Vertexes; PlanetTriangles = sphericalSector.Triangles; Console.WriteLine($"Time used to create planet vertexes: {sw.Elapsed}"); SaveStl($@"Generated\Planets\MarsSector\MarsSector{NumSegments}.stl"); }
/* Set decoder sampling rate */ internal int silk_decoder_set_fs( int fs_kHz, /* I Sampling frequency (kHz) */ int fs_API_Hz /* I API Sampling frequency (Hz) */ ) { int frame_length, ret = 0; Inlines.OpusAssert(fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16); Inlines.OpusAssert(this.nb_subfr == SilkConstants.MAX_NB_SUBFR || this.nb_subfr == SilkConstants.MAX_NB_SUBFR / 2); /* New (sub)frame length */ this.subfr_length = Inlines.silk_SMULBB(SilkConstants.SUB_FRAME_LENGTH_MS, fs_kHz); frame_length = Inlines.silk_SMULBB(this.nb_subfr, this.subfr_length); /* Initialize resampler when switching internal or external sampling frequency */ if (this.fs_kHz != fs_kHz || this.fs_API_hz != fs_API_Hz) { /* Initialize the resampler for dec_API.c preparing resampling from fs_kHz to API_fs_Hz */ ret += Resampler.silk_resampler_init(this.resampler_state, Inlines.silk_SMULBB(fs_kHz, 1000), fs_API_Hz, 0); this.fs_API_hz = fs_API_Hz; } if (this.fs_kHz != fs_kHz || frame_length != this.frame_length) { if (fs_kHz == 8) { if (this.nb_subfr == SilkConstants.MAX_NB_SUBFR) { this.pitch_contour_iCDF = Tables.silk_pitch_contour_NB_iCDF; } else { this.pitch_contour_iCDF = Tables.silk_pitch_contour_10_ms_NB_iCDF; } } else { if (this.nb_subfr == SilkConstants.MAX_NB_SUBFR) { this.pitch_contour_iCDF = Tables.silk_pitch_contour_iCDF; } else { this.pitch_contour_iCDF = Tables.silk_pitch_contour_10_ms_iCDF; } } if (this.fs_kHz != fs_kHz) { this.ltp_mem_length = Inlines.silk_SMULBB(SilkConstants.LTP_MEM_LENGTH_MS, fs_kHz); if (fs_kHz == 8 || fs_kHz == 12) { this.LPC_order = SilkConstants.MIN_LPC_ORDER; this.psNLSF_CB = Tables.silk_NLSF_CB_NB_MB; } else { this.LPC_order = SilkConstants.MAX_LPC_ORDER; this.psNLSF_CB = Tables.silk_NLSF_CB_WB; } if (fs_kHz == 16) { this.pitch_lag_low_bits_iCDF = Tables.silk_uniform8_iCDF; } else if (fs_kHz == 12) { this.pitch_lag_low_bits_iCDF = Tables.silk_uniform6_iCDF; } else if (fs_kHz == 8) { this.pitch_lag_low_bits_iCDF = Tables.silk_uniform4_iCDF; } else { /* unsupported sampling rate */ Inlines.OpusAssert(false); } this.first_frame_after_reset = 1; this.lagPrev = 100; this.LastGainIndex = 10; this.prevSignalType = SilkConstants.TYPE_NO_VOICE_ACTIVITY; Arrays.MemSetShort(this.outBuf, 0, SilkConstants.MAX_FRAME_LENGTH + 2 * SilkConstants.MAX_SUB_FRAME_LENGTH); Arrays.MemSetInt(this.sLPC_Q14_buf, 0, SilkConstants.MAX_LPC_ORDER); } this.fs_kHz = fs_kHz; this.frame_length = frame_length; } /* Check that settings are valid */ Inlines.OpusAssert(this.frame_length > 0 && this.frame_length <= SilkConstants.MAX_FRAME_LENGTH); return(ret); }
public void Create() { Stopwatch sw; sw = Stopwatch.StartNew(); _elevationTexture = TextureHelper.LoadTiff16(@"Datasets\Planets\Mars\Mars_MGS_MOLA_DEM_mosaic_global_463m.tif"); Console.WriteLine($"Loading texture used {sw.Elapsed}"); int width = 11520; int height = 5760; // string elevationTextureSmallFilename = $@"Generated\Planets\MarsSector\Mars{width}x{height}.raw"; // if (!File.Exists(elevationTextureSmallFilename)) // { // sw = Stopwatch.StartNew(); // var elevationTextureLarge = TextureHelper.LoadTiff16(@"Datasets\Planets\Mars\Mars_MGS_MOLA_DEM_mosaic_global_463m.tif"); // Console.WriteLine($"Loading texture used {sw.Elapsed}"); // sw = Stopwatch.StartNew(); // _elevationTexture = Resampler.Resample(elevationTextureLarge, width, height); // Console.WriteLine($"Resampling used {sw.Elapsed}"); // TextureHelper.SaveRaw16($@"Generated\Planets\MarsSector\Mars{_elevationTexture.Width}x{_elevationTexture.Height}.raw", _elevationTexture); // TextureHelper.SavePng8($@"Generated\Planets\MarsSector\Mars{_elevationTexture.Width}x{_elevationTexture.Height}.png", _elevationTexture); // } // else // { // _elevationTexture = TextureHelper.LoadRaw16(elevationTextureSmallFilename, width, height); // } width = 2880; height = 1440; string elevationTextureBlurFilename = $@"Generated\Planets\MarsSector\MarsBlur{width}x{height}.raw"; if (!File.Exists(elevationTextureBlurFilename)) { var elevationTextureSmall = Resampler.Resample(_elevationTexture, width, height); sw = Stopwatch.StartNew(); var blurFilter = new BlurFilter(PlanetProjection); _elevationTextureBlur = blurFilter.Blur3(elevationTextureSmall, MathHelper.ToRadians(10)); Console.WriteLine($"Blur used {sw.Elapsed}"); TextureHelper.SaveRaw16($@"Generated\Planets\MarsSector\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.raw", _elevationTextureBlur); TextureHelper.SavePng8($@"Generated\Planets\MarsSector\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.png", _elevationTextureBlur); } else { _elevationTextureBlur = TextureHelper.LoadRaw16(elevationTextureBlurFilename, width, height); } sw = Stopwatch.StartNew(); var sphericalSector = new SphericalSector(); sphericalSector.ComputeRadiusTop = ComputeModelElevationTop; sphericalSector.ComputeRadiusBottom = ComputeModelElevationBottom; sphericalSector.Create(MathHelper.ToRadians(-10), MathHelper.ToRadians(133), MathHelper.ToRadians(0), MathHelper.ToRadians(142), NumSegments, NumSegments); PlanetVertexes = sphericalSector.Vertexes; PlanetTriangles = sphericalSector.Triangles; Console.WriteLine($"Time used to create planet vertexes: {sw.Elapsed}"); SaveSTL($@"Generated\Planets\MarsSector\MarsSector{NumSegments}.stl"); }
public void GetSoftwareFormat(ref int samplerate, ref Format format, ref int numoutputchannels, ref int maxinputchannels, ref Resampler resamplemethod, ref int bits) { Code returnCode = GetSoftwareFormat(DangerousGetHandle(), ref samplerate, ref format, ref numoutputchannels, ref maxinputchannels, ref resamplemethod, ref bits); Errors.ThrowError(returnCode); }