public void DrawGraph(WaveFunction waveFunction, Color color) { double xIncrement = _xLength / _sampleSize; double previousX = _xPosition; double previousY = _yPosition + (0.5 * _yLength); GL.Color3(color.Red, color.Green, color.Blue); GL.Begin(PrimitiveType.Lines); { for (int i = 0; i < _sampleSize; i++) { // work out new x and y positions double newX = previousX + xIncrement; // Increment one unit on the x // from 0-1 how far through the plotting the graph are we? double percentDone = (i / _sampleSize); double percentRadians = percentDone * (Math.PI * _frequency); // Scale the wave value by half o fthe length double newY = _yPosition + waveFunction(percentRadians) * (_yLength / 2); // Ignore the first value because the previous X and Y haven't been worked out yet if (i > 1) { GL.Vertex2(previousX, previousY); GL.Vertex2(newX, newY); } // Store previous positions previousX = newX; previousY = newY; } } GL.End(); }
public void DrawGraph(WaveFunction waveFunction, Color color) { double xIncrement = _xLength / _sampleSize; double previousX = _xPosition; double previousY = _yPosition + (0.5 * _yLength); Gl.glColor3f(color.Red, color.Green, color.Blue); Gl.glBegin(Gl.GL_LINES); { for (int i = 0; i < _sampleSize; i++) { //Work out new x and y double newX = previousX + xIncrement; double percentDone = (i / _sampleSize); double percentRadians = percentDone * (Math.PI * _frequency); //Scale the wave value by the half os length double newY = _yPosition + waveFunction(percentRadians) * (_yLength / 2); //Ignore the first value if (i > 1) { Gl.glVertex2d(previousX, previousY); Gl.glVertex2d(newX, newY); } previousX = newX; previousY = newY; } Gl.glEnd(); } }
public Signal(double Amplitude, int FrequencyInHz, WaveFunction waveFunction) { this.FrequencyInHz = FrequencyInHz; this.TimePeriod = 1 / FrequencyInHz; this.Amplitude = Amplitude; this.waveFunction = waveFunction; }
public FunctionWave(WaveFunction function, int period, double voltage_times, double function_mean) { this.function = function; this.period = period; this.voltage_times = voltage_times; this.mean_voltage = voltage_times * function_mean; }
void Update() { if (isEditorMode) { float[,] tmpCoefficients = new float[WaveFunction.NumberOfStates, 2]; if (coefficientsActive != null) { for (int i = 0; i < WaveFunction.NumberOfStates; i++) { tmpCoefficients[i, 0] = coefficientsActive[i, 0]; tmpCoefficients[i, 1] = coefficientsActive[i, 1]; } } else { foreach (float[,] element in coefficientsList) { for (int i = 0; i < WaveFunction.NumberOfStates; i++) { tmpCoefficients[i, 0] += element[i, 0]; tmpCoefficients[i, 1] += element[i, 1]; } } } float norm2 = QSystemController.currentQuantumSystem.qMath.InnerProductV(tmpCoefficients); if (norm2 > minimumCoefficiantNorm2) { QSystemController.currentQuantumSystem.qMath.NormalizeV(tmpCoefficients); } WaveFunction.SetCoefficients(tmpCoefficients); WaveFunction.UpdateRender(); } }
public void DrawGraph(WaveFunction waveFunction, Color color) { double xIncrement = _xlength / _sampleSize; double previousX = _xPosition; double previousY = _yPosition + (0.5 * _ylength); Gl.glColor3f(color.Red, color.Green, color.Blue); Gl.glBegin(Gl.GL_LINES); //画出线条 { for (int i = 0; i < _sampleSize; i++) { //Work out new X and Y positions double newX = previousX + xIncrement; //Increment one unit on the x //From 0-1 how far through plotting the graph are we? double percentDone = (i / _sampleSize); double percentRadians = percentDone * (Math.PI * _frequency); //Scale the wave value by the half the length double newY = _yPosition + waveFunction(percentRadians) * (_ylength / 2); //Ignore the first value because the previous X and Y //haven't been worked out yet if (i > 1) { Gl.glVertex2d(previousX, previousY); Gl.glVertex2d(newX, newY); } //Store the previous position previousX = newX; previousY = newY; } } Gl.glEnd(); } //Empty Update and Render methods omitted
public FunctionWave(WaveFunction function, int period, double voltage_times = 1) { this.function = function; this.period = period; this.voltage_times = voltage_times; this.mean_voltage = Waves.CalculateMeanVoltage(this); }
public void DrawGraph(WaveFunction waveFunction, Color color) { double xIncrement = _xLength / _sampleSize; double previousX = _xPos; double previousY = _yPos + (0.5f * _yLength); Gl.glColor3f(color.Red, color.Green, color.Blue); Gl.glBegin(Gl.GL_LINES); { for (int i = 0; i < _sampleSize; ++i) { double newX = previousX + xIncrement; double percentDone = (i / _sampleSize); double percentRadians = percentDone * (Math.PI * _frequency); double newY = _yPos + waveFunction(percentRadians) * (_yLength / 2); if (i > 1) { Gl.glVertex2d(previousX, previousY); Gl.glVertex2d(newX, newY); } previousX = newX; previousY = newY; } } Gl.glEnd(); }
public void DrawGraph(WaveFunction waveFunction, Color color) { double xIncrement = _xLength / _sampleSize; double previousX = _xPosition; double previousY = _yPosition + (0.5 * _yLength); Gl.glColor3f(color.Red, color.Green, color.Blue); Gl.glBegin(Gl.GL_LINES); { for (int i = 0; i < _sampleSize; i++) { //new x and y pos double newX = previousX + xIncrement; double percentDone = (i / _sampleSize); double percentRadians = percentDone * (Math.PI * _frequency); double newY = _yPosition + waveFunction(percentRadians) * (_yLength / 2); if (i > 1) { Gl.glVertex2d(previousX, previousY); Gl.glVertex2d(newX, newY); } //store previous previousX = newX; previousY = newY; } } Gl.glEnd(); }
IEnumerator LoadingCoroutine() { yield return(null); WaveFunction.Reload(); ProgramStateMachine.AttemptTransition("View"); }
public void DrawGraph(WaveFunction waveFunction, Color color) { double xIncrement = _xlength / _sampleSize; double previousX = _xPosition; double previousY = _yPosition + (0.5 * _ylength); Gl.glColor3f(color.Red, color.Green, color.Blue); Gl.glBegin(Gl.GL_LINES); //画出线条 { for (int i = 0; i < _sampleSize; i++) { //Work out new X and Y positions double newX = previousX + xIncrement; //Increment one unit on the x //From 0-1 how far through plotting the graph are we? double percentDone = (i / _sampleSize); double percentRadians = percentDone * (Math.PI * _frequency); //Scale the wave value by the half the length double newY = _yPosition + waveFunction(percentRadians) * (_ylength / 2); //Ignore the first value because the previous X and Y //haven't been worked out yet if (i > 1) { Gl.glVertex2d(previousX, previousY); Gl.glVertex2d(newX, newY); } //Store the previous position previousX = newX; previousY = newY; } } Gl.glEnd(); }
void OnCycleShader() { int oldExponent = displayModes[shaderIndex].scaleExponent; if (shaderIndex + 1 < displayModes.Length) { shaderIndex++; } else if (displayModes.Length > 0) { shaderIndex = 0; } else { Debug.LogError("MaterialController has not been assigned any shaders."); } // maintaine intesity after switching displayModes shaderScale *= displayModes[shaderIndex].scaleExponent / ((float)oldExponent); material.shader = displayModes[shaderIndex].shader; material.SetInt("_MaxIndex", QSystemController.currentQuantumSystem.maxTextureLayer); Debug.Log("set _MaxIndex:" + QSystemController.currentQuantumSystem.maxTextureLayer); currentMaterial.SetFloat("_Scale", shaderScale); WaveFunction.UpdateRender(); }
public void ResetSimulation() { if (isRunMode) { time = 0; WaveFunction.UpdateRender(time); } }
void Update() { if (isRunMode) { time += speed * Time.deltaTime; WaveFunction.UpdateRender(time); } }
/// <summary> /// This is the repeating input fed into the various functions to generate /// the desired waveforms. It generates _sampleRate number of steps /// from between 0 and 1. This is fed into the various equations to /// generate desired waveforms. /// </summary> public Wave(WaveFunction f) { _waveFunction = f; _duration = 1; _sampleRate = 96000; _frequency = 1; _phase = 0; _amplitude = 1; }
public static short[] CreateSong(IList <RPCCommand> data, WaveFunction waveType, double volume, bool clip, int frequency) { var song = new WaveSong(); song.NoClipping = !clip; song.Volume = volume; int time = 0; var channels = new Dictionary <int, WaveSong.Track>(); foreach (var cmd in data) { WaveSong.Track playing; switch (cmd.Type) { case RPCCommandType.Delay: time += cmd.DelayValue; break; case RPCCommandType.SetCountdown: double freq = LoadMDT.CountdownToFrequency(cmd.Data); if (!channels.TryGetValue(cmd.Channel, out playing) || playing.Wave.Frequency != freq) { if (playing.Wave != null) { playing.Wave.Duration = time - playing.Start; } playing = new WaveSong.Track(time, new Wave(freq, 0) { Type = waveType }); song.Waves.Add(playing); channels[cmd.Channel] = playing; } break; case RPCCommandType.ClearCountdown: if (channels.TryGetValue(cmd.Channel, out playing)) { if (playing.Wave != null) { playing.Wave.Duration = time - playing.Start; } channels.Remove(cmd.Channel); } break; } } foreach (WaveSong.Track playing in channels.Values) { playing.Wave.Duration = time - playing.Start; } return(song.GetSamples <short>(frequency)); }
public static void AddInstrument(string instrumentName, WaveFunction instrument) { if (Instruments.ContainsKey(instrumentName)) { throw new InstrumentException("Instrument already exists"); } Instruments.Add(instrumentName, instrument); IsNotePlaying.Add(instrumentName, new bool[49]); MainWindow.InstrumentsList.Items.Add(instrumentName); NoteDb.Add(instrumentName, new List <Note>()); }
/// <summary> /// Create a wavepack /// </summary> /// <param name="waveCount">how many wave in wave pack</param> /// <param name="random">random number generator</param> /// <returns>wave pack</returns> public IWave Build(int waveCount, Random random) { WavePack wavePack = new WavePack(); for (int i = 0; i < waveCount; i++) { WaveFunction waveFunction = WaveFunctions.GetRandomWaveFunction(random, true); double phase = (random.NextDouble() * 2.0) - 1.0; double amplitude = random.NextDouble(); double frequency = random.NextDouble(); wavePack.Add(new Wave(amplitude, frequency, phase)); } wavePack.Normalize(); return(wavePack); }
IEnumerator Start() { waveType = WaveType.Sine; function = Sine; OnFreqChange.AddListener(updateHertz); OnOffsetChange.AddListener(updateOffset); if (customWaveform != null) { customWaveform.OnWaveFormUpdate.AddListener(OnCustomWaveformChanged); } yield return(null); OnFreqChange.Invoke(Freq); }
void ViewUpdate() { float[,] coefficients = new float[WaveFunction.NumberOfStates, 2]; for (int i = 0; i < WaveFunction.NumberOfStates; i++) { coefficients[i, 0] = 0.0f; coefficients[i, 1] = 0.0f; if (i == viewStateIndex) { coefficients[i, 0] = 1.0f; } } WaveFunction.SetCoefficients(coefficients); MaterialController.ResetScale(QSystemController.currentQuantumSystem.MaxStateValue(viewStateIndex)); WaveFunction.UpdateRender(); }
public Map(int w, int h, TileSet tileset) { Width = w; Height = h; Cells = new WaveFunction[Width, Height]; Tileset = tileset; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { var waveFunction = new WaveFunction(); waveFunction.Choices = tileset.Fetch(); Cells[x, y] = waveFunction; } } }
//This needs to use the same function as the heightAt(x, z) method so that the normal at a point can be calculated e.g. the normal at a point on top of the wave would be straight up public Vector3 normalAt(float x, float z) { Vector3 normal = new Vector3(); foreach (GameObject wave in GameObject.FindGameObjectsWithTag(Tags.waveFunction)) { WaveFunction function = wave.GetComponent <WaveFunction> (); normal += function.normalAt(x, z) * function.amplitude; //, transform.forward.x, transform.forward.z); } return(normal); //return wave1.normalAt (x, z) * wave1.amplitude + wave2.normalAt (x, z) * wave2.amplitude; //return Vector3.up; //float argument = Time.realtimeSinceStartup + x * frequency * transform.forward.x + z * frequency * transform.forward.z; //float nx = amplitude * frequency * transform.forward.x * Mathf.Cos (argument); //float ny = 0;//-1.0f; //float nz = amplitude * frequency * transform.forward.z * Mathf.Cos (argument); //return new Vector3 (nx, ny, nz).normalized * -1; // Not sure about sign. Maybe you need to multiply the result by -1. }
IEnumerator Start() { var a = gameObject.GetComponent <AudioSource>(); if (a == null) { a = gameObject.AddComponent <AudioSource>(); a.volume = 0.075f; } running = true; waveType = WaveType.Sine; usingWaveFunc = Sine; newWaveFunc = Sine; _usingFreq = Freq; samples = new float[1024]; if (line != null) { for (int i = 0; i < 1024; i++) { GameObject o = Instantiate(objs, line.transform); o.name = "Obj " + i.ToString("0000"); } } OnFreqChange.AddListener(updateOscilloscope); OnOffsetChange.AddListener(updateOscilloscope); if (customWaveform != null) { customWaveform.OnWaveFormUpdate.AddListener(updateOscilloscope); } OnFreqChange.AddListener(updateHertz); OnOffsetChange.AddListener(updateOffset); yield return(null); OnFreqChange.Invoke(Freq); }
public void SetFunction(WaveFunction f) { _waveFunction = f; }
public OrbitalViewerPlotModel(WaveFunction waveFunction) { _waveFunction = waveFunction; }
void OnAudioFilterRead(float[] data, int channels) { if (!running) { return; } int dataLen = data.Length / channels; samplesStack.Enqueue((float[])samples.Clone()); samples = new float[dataLen]; float target = 0; if (setTranstion) { target = newWaveFunc(usingPosition + dataLen, Freq, sampleRate); transition = true; } int n = 0; while (n < dataLen) { int i = 0; while (i < channels) { if (transition) { data[n * channels + i] = Mathf.MoveTowards(lastSamples[i], target, stepsize); lastSamples[i] = data[n * channels + i]; if (Mathf.Abs(lastSamples[0] - target) <= stepsize) { _usingFreq = Freq; usingWaveFunc = newWaveFunc; transition = false; setTranstion = false; } } else { data[n * channels + i] += getSample(n); lastSamples[i] = data[n * channels + i]; } i++; } samples[n] = data[n * channels]; n++; } if (transition) { _usingFreq = Freq; usingWaveFunc = newWaveFunc; transition = false; setTranstion = false; } GeneratorUpdates++; if (GeneratorUpdates >= NumberOfGenerators) { position += n; GeneratorUpdates = 0; } }
public static short[] CreateSong(IList<RPCCommand> data, WaveFunction waveType, double volume, bool clip, int frequency, double? clickLength) { var song = new WaveSong(); song.NoClipping = !clip; song.Volume = volume; bool informed = false; int time = 0; var channels = new Dictionary<int,WaveSong.Track>(); foreach(var cmd in data) { WaveSong.Track playing; switch(cmd.Type) { case RPCCommandType.Delay: time += cmd.DelayValue; break; case RPCCommandType.SetCountdown: double freq = LoadMDT.CountdownToFrequency(cmd.Data); if(!channels.TryGetValue(cmd.Channel, out playing) || playing.Wave.Frequency != freq) { double phase = 0; if(playing.Wave != null) { playing.Wave.Duration = time-playing.Start; phase = playing.Wave.RemainingPhaseShift; } playing = new WaveSong.Track(time, new Wave(freq, 0){Type = waveType, PhaseShiftCoef = phase}); song.Waves.Add(playing); channels[cmd.Channel] = playing; } break; case RPCCommandType.ClearCountdown: if(channels.TryGetValue(cmd.Channel, out playing)) { if(playing.Wave != null) { playing.Wave.Duration = time-playing.Start; if(playing.Wave.Duration == 0) { if(clickLength != null) { playing.Wave.Duration = 1000*clickLength.Value/playing.Wave.Frequency; }else if(!informed) { Console.WriteLine("Song contains zero-length waves. Use --clicks 0.5 to render them as clicks."); informed = true; } } } channels.Remove(cmd.Channel); } break; } } foreach(WaveSong.Track playing in channels.Values) { playing.Wave.Duration = time-playing.Start; } return song.GetSamples<short>(frequency); }
/// <summary> /// Resets the internal system. /// </summary> public void reset() { currentWave = level.getInitialWaveFunction(); level.reset(); nextPoint = level.getStartPoint(); lastPoint = nextPoint; time = 0.0f; calculateFidelity(); if(onFrameReset != null) onFrameReset(); }
/// <summary> /// Set the level currently maintained in the QFrame. /// </summary> /// <param name="str">The level</param> public void setLevel(Level level) { levelString = level.id; this.level = level; worldAxis = new Axis(level.xMinVal, level.xMaxVal, level.ampMinVal, level.ampMaxVal, transform.position.x, transform.position.x + transform.localScale.x, transform.position.y, transform.position.y + transform.localScale.y); localAxis = new Axis(level.xMinVal, level.xMaxVal, level.ampMinVal, level.ampMaxVal, 0.0, 1.0, 0.0, 1.0); currentWave = level.getInitialWaveFunction(); nextPoint = level.getStartPoint(); lastPoint = nextPoint; transform.GetComponent<Drawer>().refresh(); transform.FindChild("Target").GetComponent<Target>().refresh(); }
public static short[] CreateSong(IList <RPCCommand> data, WaveFunction waveType, double volume, bool clip, int frequency, double?clickLength, bool temper) { var song = new WaveSong(); song.NoClipping = !clip; song.Volume = volume; bool informed = false; int time = 0; var channels = new Dictionary <int, WaveSong.Track>(); foreach (var cmd in data) { WaveSong.Track playing; switch (cmd.Type) { case RPCCommandType.Delay: time += cmd.DelayValue; break; case RPCCommandType.SetCountdown: double freq = LoadMDT.CountdownToFrequency(cmd.Data); if (temper) { freq = TemperFrequency(freq); } if (!channels.TryGetValue(cmd.Channel, out playing) || playing.Wave.Frequency != freq) { double phase = 0; if (playing.Wave != null) { playing.Wave.Duration = time - playing.Start; phase = playing.Wave.RemainingPhaseShift; } playing = new WaveSong.Track(time, new Wave(freq, 0) { Type = waveType, PhaseShiftCoef = phase }); song.Waves.Add(playing); channels[cmd.Channel] = playing; } break; case RPCCommandType.ClearCountdown: if (channels.TryGetValue(cmd.Channel, out playing)) { if (playing.Wave != null) { playing.Wave.Duration = time - playing.Start; if (playing.Wave.Duration == 0) { if (clickLength != null) { playing.Wave.Duration = 1000 * clickLength.Value / playing.Wave.Frequency; } else if (!informed) { Console.WriteLine("Song contains zero-length waves. Use --clicks 0.5 to render them as clicks."); informed = true; } } } channels.Remove(cmd.Channel); } break; } } foreach (WaveSong.Track playing in channels.Values) { playing.Wave.Duration = time - playing.Start; } return(song.GetSamples <short>(frequency)); }