public SampleBrowserLayer(ISample[] samples) { Name = "BrowserLayer"; Layouter = new TableLayouter { ItemSpan = ItemOffset, Position = new Vector2DF(SampleBrowser.Margin + 16, SampleBrowser.Margin), LineCapacity = 3 }; Selector = new PointingSelector<ISample>(Layouter); AddObject(Selector); var font = Engine.Graphics.CreateDynamicFont("", 12, new Color(255, 255, 255, 255), 1, new Color(0, 0, 0, 255)); foreach (var sample in samples) { var item = new SampleItem(sample, font); Selector.AddChoice(sample, item, SampleItem.Size); } camera = new CameraObject2D { Src = new RectI(0, 0, 640, (int) SampleBrowser.ViewerHeight), Dst = new RectI(0, 20, 640, (int) SampleBrowser.ViewerHeight) }; AddObject(camera); }
static void Main(string[] args) { var samples = new ISample[] { new NormalReading(), new SimpleAdapter(), new TwoWayAdapter(), new ListSample(), new UseAppSettings(), new CustomKeys(), new CustomPrefix(), new NestedObjects() }; for (int i = 0; i < samples.Length; i++) { Console.WriteLine("{0}: {1}", i, samples[i].GetType().Name); } while (true) { Console.Write("\r\nSelect a sample number to run..."); int sampleIndex = int.Parse(Console.ReadLine()); ISample sample = samples[sampleIndex]; Console.WriteLine("\r\n{0}:", sample.GetType().Name); sample.Run(); } }
private HistogramMetric(ISample sample, bool clear) { _sample = sample; if(clear) { Clear(); } }
public bool Select( ISample sample ) { if (sample.IsLabeled) { return false; } else { return true; } }
static void Main(string[] args) { var samples = new ISample[] { new Controller.Controller_Keyboard(), new Controller.Controller_Bundle(), new Controller.Controller_Stepping(), new Selector.Selector_Basic(), }; var browser = new SampleBrowser(samples); browser.Run(); }
public void SetUp() { Sample = Substitute.For<ISample>(); ConfigureContext(); try { ExpectedCall(); } catch (CallNotReceivedException ex) { _exception = ex; } }
public Histogram(SampleType type) { switch(type) { case SampleType.BIASED: _sample = new ExponentiallyDecayingSample(); break; case SampleType.UNIFORM: _sample = new UniformSample(); break; default: throw new ArgumentException("Unknown enum value found."); } }
internal ISample _nxt(ISample s) { if (_invert != null) { for (ushort c = 0; c < s.NumChannels; c++) { if (_invert[c]) { s[c] = -s[c]; } } } return s; }
public void Show(ISample sample) { if (sample == null) { Title.Text = ""; Description.Text = ""; ClassName.Text = ""; } else { Title.Text = sample.Title; ClassName.Text = "(" + sample.GetType().Name + ")"; Description.Text = sample.Description; ClassName.Position = new Vector2DF(Title.Font.CalcTextureSize(Title.Text, WritingDirection.Horizontal).X + 8, 2); } }
internal ISample _next(ISample s) { if (_nc != 2) { // NOP! } else { double L = s[0]; double R = s[1]; // Set sample values in-place (quicker than newing another sample) s[0] = (L + R) * _sigmaGain; s[1] = (L - R) * _deltaGain; } return s; }
/// <summary> /// Creates a new <see cref="HistogramMetric" /> with the given sample /// </summary> public HistogramMetric(ISample sample) : this(sample, true) { _sample = sample; Clear(); }
private void ReadSPDIF() { if (_ok) { byte[] spdif = { 0x72, 0xf8, 0x1f, 0x4e }; if (_rdr.BaseStream.CanSeek) { _seekpos = _rdr.BaseStream.Position; } // Read the first sample "manually" // so we can check whether there's a SPDIF or other magic number // at the beginning of the stream. int nFirst = (_nc * _bitsPerSample / 8); byte[] firstBytes = _rdr.ReadBytes(nFirst); MemoryStream ms = new MemoryStream(firstBytes); BinaryReader mr = new BinaryReader(ms); // Save the sample for later use _first = Next(mr, out _moreThanFirst); if (firstBytes.Length >= nFirst) { // Check whether it's SPDIF-wrapped _isSPDIF = true; for (int b = 0; _isSPDIF && b < spdif.Length && b < nFirst; b++) { _isSPDIF &= (spdif[b] == firstBytes[b]); } } } }
private void SkipToStart(TimeSpan ts) { if (_ok) { // Number of samples = seconds * samplerate long pos = (long)(ts.TotalSeconds * _sr); if (pos > 0) { if (_rdr.BaseStream.CanSeek) { Trace.WriteLine("Skip to time {0} (sample {1})", ts, pos); _rdr.BaseStream.Seek(_seekpos + (pos * _nc * (_bitsPerSample / 8)), SeekOrigin.Begin); // remember our new base-position, so Seek() works relative to this _seekpos = _rdr.BaseStream.Position; // Read the first sample again (see ReadSPDIF) int nFirst = (_nc * _bitsPerSample / 8); byte[] firstBytes = _rdr.ReadBytes(nFirst); MemoryStream ms = new MemoryStream(firstBytes); BinaryReader mr = new BinaryReader(ms); _first = Next(mr, out _moreThanFirst); } else { // Laboriously skip samples until we reach the right place? // Bah. TODO. For now we only care about file-input sources, which are seekable. } } } }
ISample _nxt(ref int n, ISample s) { if (_s == 0 || s.NumChannels != 2) { return s; } else { double L = s[0]; double R = s[1]; if (_skew < 0) { _data[n % _s] = L; n = (n + 1) % _s; L = _data[n]; } else { _data[n % _s] = R; n = (n + 1) % _s; R = _data[n]; } s[0] = L; s[1] = R; return s; } }
private ISample Next(BinaryReader rdr, out bool more) { try { if (_nc == 2) { if (_pos < _max) { _pos++; double a = NextDouble(rdr); double b = NextDouble(rdr); more = true; _current = new Sample2(a, b); } else { more = false; _current = null; } } else { if (_pos < _max) { _pos++; ISample sample = new Sample(_nc); for (int n = 0; n < _nc; n++) { sample[n] = NextDouble(rdr); } more = true; _current = sample; } else { more = false; _current = null; } } } catch (EndOfStreamException) { Trace.WriteLine("End of input ({0}) at {1}.", streamName, _pos); more = false; _current = null; } catch (IOException e) { Trace.WriteLine("IO error ({0}) at {1}: {2}", streamName, _pos, e.Message); more = false; _current = null; } return _current; }
/// <summary> /// Standard deviation in dB of all samples in buffer /// </summary> /// <returns></returns> public ISample StdDevDb() { if (_stddevdB != null) { return _stddevdB; } ISample meandb = MeanDb(); ushort nc = _input.NumChannels; _stddevdB = new Sample(nc); for (int n = 0; n < _length; n++) { if (_data[n] != null) { for (ushort c = 0; c < nc; c++) { double devdb = (MathUtil.dB(_data[n][c]) - meandb[c]); _stddevdB[c] += (devdb * devdb); } } } for (ushort c = 0; c < nc; c++) { _stddevdB[c] = Math.Sqrt(_stddevdB[c] / _length); } return _stddevdB; }
public ErrorCode nextSample(int streamId, out ISample sample) { UInt64 length = reader_.size() - pos_; sample = null; if (length == 0) { return ErrorCode.EndOfStream; } UInt64 bufSize = Math.Min(BLOCK_SIZE, length); byte[] buf = new byte[bufSize]; Int32 size = (Int32)bufSize; reader_.read(buf, ref size); UInt64 start = (pos_ - 44) * 800000 / ((UInt64)frequency_ * (UInt64)channels_ * (UInt64)bps_); UInt64 stop = (pos_ - 44 + bufSize) * 800000 / ((UInt64)frequency_ * (UInt64)channels_ * (UInt64)bps_); sample = new Sample(buf, start, stop, seekTime_, discontinuous_); pos_ += bufSize; discontinuous_ = false; return ErrorCode.Success; }
public SampleExplicitExposer(ISample sample) { this.innerSample = sample; }
/// <summary> /// Process a ISample (in-place; the original object is returned, with modified data) /// </summary> /// <param name="samp"></param> public ISample process(ISample samp) { for (int c = 0; c < samp.NumChannels; c++) { samp[c] = processDouble(samp[c]); } return samp; }
public abstract double Rank( ISample sample );
public void SetUp() { _sample = Substitute.For<ISample>(); }
public Histogram(ISample sample) { _sample = sample; }
public bool Select( ISample sample ) { return true; }
public SampleBrowser(ISample[] samples) { this.samples = samples; }
public abstract double Rank( ISample sample, string category );
public abstract bool Classify( ISample sample, string category );
public SampleMembersExposer(ISample sample) { this.innerSample = sample; }
public abstract string Classify( ISample sample );
public string Ref(int i, ref FooBase foo, string s, ref ISample sample) { sample.Prop = i.ToString(); return sample.Prop; }
public HandCodedSampleMembersExposer(ISample innerSample) { this.innerSample = innerSample; }