void Start() { //octopi for (int i = 0; i < OctopusCount; i++) { octopus = new chapter1Creature(); octopi.Add(octopus); } //wisps for (int i = 0; i < WispCount; i++) { Vector3 randomLocation = new Vector3(Random.Range(0, 100), Random.Range(3, 100), Random.Range(0, 100)); Vector3 randomVelocity = new Vector3(Random.Range(-2f, 2f), Random.Range(-2f, 2f), Random.Range(-2f, 2f)); Mover2_7 m = new Mover2_7(Random.Range(0.2f, .5f), randomVelocity, randomLocation); //Each Mover is initialized randomly. movers.Add(m); } a = new Attractor2_7(); //worms for (int i = 0; i < WormCount; i++) { float x = Random.Range(0, 100); float z = Random.Range(0, 100); float y = ExtensionMethods.Remap(Mathf.PerlinNoise(x * .06f, z * .06f), 0f, 1f, 0f, 7f); worms.Add(new baton(new Vector3(x, y - 1f, z))); } //fish for (int i = 0; i < FishCount; i++) { Vector3 randomLocation = new Vector3(Random.Range(50f, 100f), Random.Range(50f, 100f), Random.Range(50f, 20f)); Vector3 randomVelocity = new Vector3(Random.Range(0f, 3f), Random.Range(0f, 3f), Random.Range(0f, 3f)); Movers m = new Movers(Random.Range(0.2f, 1f), randomVelocity, randomLocation); //Each Mover is initialized randomly. fish.Add(m); } fishLead = new fishLead(); //randomFish for (int i = 0; i < randomFishCount; i++) { randomFish a = new randomFish(); fishR.Add(a); } //squid randomFish2 = new randomFish2(); while (oscillate.Count < SquidCount) { oscillator o = new oscillator(new Vector3(2f, 2f, 2f)); o.oGameObject.transform.SetParent(randomFish2.body.transform); oscillate.Add(o); Debug.Log("Squid instantiated"); squid.Add(randomFish2); } }
void Start() { a = new randomFish2(); while (oscilattors.Count < 10) { oscillator o = new oscillator(new Vector3(2f, 2f, 2f)); o.oGameObject.transform.SetParent(a.parent.transform); oscilattors.Add(o); } }
// samples/sec private bool newCWToneGen(ref oscillator osc, float gain, // dB float freq, // ms float rise, // ms float fall, // ms int size, // samples float samplerate) { setCWToneGenVals(ref Transmiter.cwt, gain, freq, rise, fall); Transmiter.cwt.size = size; Transmiter.cwt.sr = samplerate; newOSC(ref osc, Transmiter.cwt.size, OscType.ComplexTone, (double)freq, 0.0, Transmiter.cwt.sr); return true; }
// Start is called before the first frame update void Start() { cols = GetComponents <BoxCollider2D>(); os = GetComponent <oscillator>(); player = GameObject.Find("Atlas"); }
void OnAudioFilterRead(float[] data, int channels) { int samples = data.Length / channels; //HOW MANY MS THIS COVERS float ms = samples / (float)sampling_frequency * 1000; totalT += ms; //ADJUST GAIN PER SAMPLE // update increment in case frequency has changed for (var j = 0; j < oscillators.Length; ++j) { oscillators[j].increment = baseFrequencyMult * oscillators[j].frequency * 2 * Math.PI / sampling_frequency; } for (var i = 0; i < data.Length; i = i + channels) { //CALCULATE GLOBAL GAIN VALUE BEFORE WE LOOP THROUGH OSCILLATORS gain_trigger.current += gain_trigger.sample_delta * gain_trigger.direction; if (gain_trigger.direction == 1 && gain_trigger.current > gain_trigger.value - 0.001) { gain_trigger.current = gain_trigger.value; gain_trigger.direction = 0; gain_trigger.sample_delta = 0; } if (gain_trigger.direction == -1 && gain_trigger.current < gain_trigger.value - 0.001) { gain_trigger.current = gain_trigger.value; gain_trigger.direction = 0; gain_trigger.sample_delta = 0; } for (var j = 0; j < oscillators.Length; ++j) { oscillator curOsc = oscillators[j]; //MOVE GAIN CURRENT TOWARDS GAIN TARGET curOsc.gain_target.current += curOsc.gain_target.sample_delta * curOsc.gain_target.direction; if (curOsc.gain_target.direction == 1 && curOsc.gain_target.current > curOsc.gain_target.value - 0.001) { curOsc.gain_target.current = curOsc.gain_target.value; curOsc.gain_target.direction = 0; curOsc.gain_target.sample_delta = 0; } if (curOsc.gain_target.direction == -1 && curOsc.gain_target.current < curOsc.gain_target.value - 0.001) { curOsc.gain_target.current = curOsc.gain_target.value; curOsc.gain_target.direction = 0; curOsc.gain_target.sample_delta = 0; } curOsc.phase = curOsc.phase + curOsc.increment; // this is where we copy audio data to make them “available” to Unity data[i] = data[i] + (float)(curOsc.gain_target.current * gain_trigger.current * Math.Sin(curOsc.phase)); // if we have stereo, we copy the mono data to each channel if (channels == 2) { data[i + 1] = data[i]; } if (curOsc.phase > 2 * Math.PI) { curOsc.phase -= 2 * Math.PI; } } } //CHECK INTERNAL GAIN AND AND ADJUST PER VOLUME }
private void newOSC(ref oscillator osc, int size, OscType TypeOsc, double Frequency, double Phase, float SampleRate) { try { osc.gen.signalpoints = new ComplexF[2048]; osc.gen.size = size; osc.gen.Frequency = 2.0 * Math.PI * Frequency / SampleRate; osc.gen.Phase = Phase; } catch (Exception ex) { Debug.Write(ex.ToString()); } }