private static AudioClip createAudioFromWave(float[] wave, LeanAudioOptions options) { float num = wave[wave.Length - 2]; float[] array = new float[(int)((float)options.frequencyRate * num)]; int num2 = 0; float num3 = wave[num2]; float num4 = 0f; float num11 = wave[num2]; float num5 = wave[num2 + 1]; for (int i = 0; i < array.Length; i++) { float num6 = (float)i / (float)options.frequencyRate; if (num6 > wave[num2]) { num4 = wave[num2]; num2 += 2; num3 = wave[num2] - wave[num2 - 2]; num5 = wave[num2 + 1]; } float num7 = num6 - num4; float num8 = num7 / num3; float num9 = Mathf.Sin(num8 * (float)Math.PI); num9 = (array[i] = num9 * num5); } int num10 = array.Length; AudioClip val = AudioClip.Create("Generated Audio", num10, 1, options.frequencyRate, false); val.SetData(array, 0); return(val); }
private static AudioClip createAudioFromWave(float[] wave, LeanAudioOptions options) { float num = wave[wave.Length - 2]; float[] array = new float[(int)((float)options.frequencyRate * num)]; int num2 = 0; float num3 = wave[num2]; float num4 = 0f; float num5 = wave[num2]; float num6 = wave[num2 + 1]; for (int i = 0; i < array.Length; i++) { float num7 = (float)i / (float)options.frequencyRate; if (num7 > wave[num2]) { num4 = wave[num2]; num2 += 2; num3 = wave[num2] - wave[num2 - 2]; num6 = wave[num2 + 1]; } num5 = num7 - num4; float num8 = num5 / num3; float num9 = Mathf.Sin(num8 * 3.14159274f); num9 *= num6; array[i] = num9; } int num10 = array.Length; AudioClip audioClip = AudioClip.Create("Generated Audio", num10, 1, options.frequencyRate, false); audioClip.SetData(array, 0); return(audioClip); }
public static AudioClip createAudio(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null) { if (options == null) { options = new LeanAudioOptions(); } float[] wave = createAudioWave(volume, frequency, options); return(createAudioFromWave(wave, options)); }
private static float[] createAudioWave(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options) { throw new NotImplementedException("なにこれ"); // float time = volume.get_Item(volume.length - 1).time; List <float> list = new List <float>(); generatedWaveDistances = new List <float>(); float num = 0f; for (int i = 0; i < PROCESSING_ITERATIONS_MAX; i++) { float num2 = frequency.Evaluate(num); if (num2 < MIN_FREQEUNCY_PERIOD) { num2 = MIN_FREQEUNCY_PERIOD; } float num3 = volume.Evaluate(num + 0.5f * num2); if (options.vibrato != null) { for (int j = 0; j < options.vibrato.Length; j++) { float num4 = Mathf.Abs(Mathf.Sin(1.5708f + num * (1f / options.vibrato[j][0]) * (float)Math.PI)); float num5 = 1f - options.vibrato[j][1]; num4 = options.vibrato[j][1] + num5 * num4; num3 *= num4; } } throw new NotImplementedException("なにこれ"); // if (num + 0.5f * num2 >= time) // { // break; //} generatedWaveDistances.Add(num2); num += num2; list.Add(num); list.Add((i % 2 != 0) ? num3 : (0f - num3)); if (i >= PROCESSING_ITERATIONS_MAX - 1) { Debug.LogError("LeanAudio has reached it's processing cap. To avoid this error increase the number of iterations ex: LeanAudio.PROCESSING_ITERATIONS_MAX = " + PROCESSING_ITERATIONS_MAX * 2); } } float[] array = new float[list.Count]; for (int k = 0; k < array.Length; k++) { array[k] = list[k]; } return(array); }
private static float[] createAudioWave(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options) { float time = volume.get_Item(volume.get_length() - 1).get_time(); List <float> list = new List <float>(); LeanAudio.generatedWaveDistances = new List <float>(); float num = 0f; for (int i = 0; i < LeanAudio.PROCESSING_ITERATIONS_MAX; i++) { float num2 = frequency.Evaluate(num); if (num2 < LeanAudio.MIN_FREQEUNCY_PERIOD) { num2 = LeanAudio.MIN_FREQEUNCY_PERIOD; } float num3 = volume.Evaluate(num + 0.5f * num2); if (options.vibrato != null) { for (int j = 0; j < options.vibrato.Length; j++) { float num4 = Mathf.Abs(Mathf.Sin(1.5708f + num * (1f / options.vibrato[j].get_Item(0)) * 3.14159274f)); float num5 = 1f - options.vibrato[j].get_Item(1); num4 = options.vibrato[j].get_Item(1) + num5 * num4; num3 *= num4; } } if (num + 0.5f * num2 >= time) { break; } LeanAudio.generatedWaveDistances.Add(num2); num += num2; list.Add(num); list.Add((i % 2 != 0) ? num3 : (-num3)); if (i >= LeanAudio.PROCESSING_ITERATIONS_MAX - 1) { Debug.LogError("LeanAudio has reached it's processing cap. To avoid this error increase the number of iterations ex: LeanAudio.PROCESSING_ITERATIONS_MAX = " + LeanAudio.PROCESSING_ITERATIONS_MAX * 2); } } float[] array = new float[list.get_Count()]; for (int k = 0; k < array.Length; k++) { array[k] = list.get_Item(k); } return(array); }