public static AudioClip GenerateAdsrSinNote(NoteData noteData, float duration) { NoteSearchKey searchKey = new NoteSearchKey(noteData, duration); if (!audioClips.ContainsKey(searchKey)) { Debug.Log("Generating audio clip for " + searchKey); float[] samples = new float[Mathf.RoundToInt(SAMPLE_FREQUENCY * duration)]; for (int i = 0; i < samples.Length; i++) { samples[i] = makeSinSample(i, noteData.Frequency, calcAdsrMagnitude(((float)i) / samples.Length, new Vector2(0.05f, 1f), new Vector2(0.3f, 0.7f), new Vector2(0.8f, 0.7f))); } AudioClip clip = AudioClip.Create("Note", samples.Length, 1, SAMPLE_FREQUENCY, false); clip.SetData(samples, 0); audioClips[searchKey] = clip; } return(audioClips[searchKey]); }
public NoteSearchKey(NoteData noteData, float duration) { this.noteData = noteData; this.duration = duration; }