private void PlaySounds() { if (soundsOn) { if (SoundsToPlayList.Count > 0) { for (int i = 0; i < SoundsToPlayList.Count; i++) { PlayableSound sound = SoundsToPlayList[i]; PlaySound(sound); } } SoundsToPlayList.Clear(); } if (metronomeOn) { if (beatOne) { source.PlayOneShot(mainBeat1, metronomeSoundLevel);//play a sound on beat beatOne = false; } else { source.PlayOneShot(mainBeat2, metronomeSoundLevel);//play a sound on beat beatOne = true; } } }
public void PlaySound(int soundID, bool willBeDestroyed = false) { if (willBeDestroyed) { transform.parent = null; } AudioSource source = audioSources[soundID]; PlayableSound sound = sounds[soundID]; if (!sound.playing) { source.clip = sound.clip; source.volume = sound.baseVolume; if (!sound.omnipresentSound) { source.volume *= getVolumeCoefficient(sound.maxDistance); } } source.Play(); if (sound.continuousSound) { sound.playing = true; } if (willBeDestroyed) { Destroy(this.gameObject, sound.clip.length); } }
private void OnBeatEvent(BeatEvent beatEvent) { Queue <AcademicChord> academicChordsQueue = context.academicChordsQueue; PlayableSoundQueue queue = context.playableSoundQueue; while (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count > 0) { AcademicChord academicChord = academicChordsQueue.Dequeue(); PlayableSound lastSound = queue.GetLastSound(); int timeQuantumNumber = beatEvent.timeQuantumNumber; if (lastSound != null) { timeQuantumNumber = lastSound.startTimeQuantumNumber + lastSound.durationTimeQuanta; } float volume = beatEvent.isStrong ? 1f : 0.75f; for (int i = 0; i < academicChord.notes.Length; ++i) { Note chordNote = academicChord.notes[i]; Pitch pitch = new Pitch(chordNote, (i == 0 || chordNote > academicChord.notes[0]) ? 4 : 5); queue.AddSound(new PlayableSound(pitch, volume, timeQuantumNumber, context.beatManager.timeQuantaPerBeat)); } } if (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count == 0) { Debug.LogWarning("Playable sounds queue is not full, but academic chords queue is empty"); } }
public void StopSound(int soundID) { AudioSource source = audioSources[soundID]; PlayableSound sound = sounds[soundID]; source.Stop(); sound.playing = false; }
private void OnSoundAdded(PlayableSound playableSound) { Sound sound = Instantiate(_soundPrefab, _soundsParent); sound.gameObject.SetActive(false); sound.playableSound = playableSound; sound.SetSize(_timeQuantumStep * playableSound.durationTimeQuanta, _pitchStep); _sounds[playableSound.id] = sound; onSoundCreated?.Invoke(sound); }
public void AddSound(PlayableSound sound) { _queue.Enqueue(sound); if (_lastSound == null || _lastSound.startTimeQuantumNumber + _lastSound.durationTimeQuanta < sound.startTimeQuantumNumber + sound.durationTimeQuanta) { _lastSound = sound; } onSoundAdded?.Invoke(sound); }
void Update() { for (int i = 0; i < sounds.Count; i++) { PlayableSound sound = sounds[i]; if (sound.continuousSound && sound.playing) { AudioSource source = audioSources[i]; source.volume = sound.baseVolume * getVolumeCoefficient(sound.maxDistance); } } }
public PlayableSound GetNextForTimeQuantum(int timeQuantumNumber) { if (_queue.Count == 0 || _queue.Peek().startTimeQuantumNumber > timeQuantumNumber) { return(null); } PlayableSound sound = _queue.Dequeue(); onSoundRemoved?.Invoke(sound); return(sound); }
public void Play(string name, float volume = 1f) { if (!sfxToggler.toggleState) { return; } PlayableSound sound = sounds.Find(x => x.name == name); if (sound != null) { source.PlayOneShot(sound.clip, volume); } }
private void OnBeatEvent(BeatEvent beatEvent) { Queue <AcademicChord> academicChordsQueue = context.academicChordsQueue; PlayableSoundQueue queue = context.playableSoundQueue; while (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count > 0) { AcademicChord academicChord = academicChordsQueue.Dequeue(); PlayableSound lastSound = queue.GetLastSound(); int timeQuantumNumber = beatEvent.timeQuantumNumber; if (lastSound != null) { timeQuantumNumber = lastSound.startTimeQuantumNumber + lastSound.durationTimeQuanta; } List <Pitch> pitches = new List <Pitch> { new Pitch(academicChord.notes[0], 4), new Pitch(academicChord.notes[1], academicChord.notes[1] > academicChord.notes[0] ? 4 : 5), new Pitch(academicChord.notes[2], academicChord.notes[2] > academicChord.notes[0] ? 4 : 5), }; List <int> indices = GetIndices(pitches.Count, context.beatManager.timeQuantaPerBeat / SOUND_DURATION_TIME_QUANTA); bool strong = true; foreach (int index in indices) { float volume = strong ? 1f : 0.5f; strong = false; queue.AddSound(new PlayableSound(pitches[index], volume, timeQuantumNumber, SOUND_DURATION_TIME_QUANTA)); timeQuantumNumber += SOUND_DURATION_TIME_QUANTA; } } if (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count == 0) { Debug.LogWarning("Playable sounds queue is not full, but academic chords queue is empty"); } }
/*private void FadeIn() * { * if (audio2Volume < 1) * { * audio2Volume += 0.1 * Time.deltaTime; * audio.volume = audio2Volume; * } * }*/ private void PlaySound(PlayableSound sound) { if (sound.source == SoundSource.LASER_ON) { if (!laserSource.isPlaying) { if (laserCount == 0) { laserSource.PlayOneShot(laserOn, medSoundLevel); laserCount++; } else if (laserCount == 1) { laserSource.PlayOneShot(laser1, medSoundLevel); laserCount++; } else if (laserCount == 2) { laserSource.PlayOneShot(laser2, medSoundLevel); laserCount++; } else { laserSource.PlayOneShot(laser3, medSoundLevel); laserCount = 0; } } } else if (sound.source == SoundSource.LASER_OFF) { if (!laserSource.isPlaying) { laserSource.PlayOneShot(laserOff, medSoundLevel); } } else if (sound.source == SoundSource.CAMERA) { if (!source.isPlaying) { source.PlayOneShot(camera, medSoundLevel); } } else if (sound.source == SoundSource.GUARD) { //TODO: TIE THIS IN WITH SOUND DETECTION SO THAT ONE GUARD DOESNT TRIGGER SO SECOND PLAYS SECOND SOUND Debug.Log("checking if guard should play..."); if (!guardSource.isPlaying) { Debug.Log("Playing guard..."); guardSource.PlayOneShot(guardStepOne, medSoundLevel); //guardSource.volume = highSoundLevel;//medSoundLevel; //guardSource.Play(); //guardSource.UnPause(); } /*if (!playGuard2 && !playGuard3 && !playGuard4) * { * if (sound.type == SoundType.CLOSE) * { * source.PlayOneShot(guardStepOne, highSoundLevel); * } * else if (sound.type == SoundType.NEAR) * { * source.PlayOneShot(guardStepOne, medSoundLevel); * * } * else * { * source.PlayOneShot(guardStepOne, lowSoundLevel); * * } * playGuard2 = true; * } * * else if (playGuard2 && !playGuard3 && !playGuard4) * { * if (sound.type == SoundType.CLOSE) * { * source.PlayOneShot(guardStepTwo, highSoundLevel); * } * else if (sound.type == SoundType.NEAR) * { * source.PlayOneShot(guardStepTwo, medSoundLevel); * * } * else * { * source.PlayOneShot(guardStepTwo, lowSoundLevel); * * } * playGuard3 = true; * playGuard2 = false; * } * * else if (!playGuard2 && playGuard3 && !playGuard4) * { * if (sound.type == SoundType.CLOSE) * { * source.PlayOneShot(guardStepThree, highSoundLevel); * } * else if (sound.type == SoundType.NEAR) * { * source.PlayOneShot(guardStepThree, medSoundLevel); * * } * else * { * source.PlayOneShot(guardStepThree, lowSoundLevel); * * } * playGuard3 = false; * playGuard4 = true; * } * * else if (!playGuard2 && playGuard3 && !playGuard4) * { * if (sound.type == SoundType.CLOSE) * { * source.PlayOneShot(guardStepThree, highSoundLevel); * } * else if (sound.type == SoundType.NEAR) * { * source.PlayOneShot(guardStepThree, medSoundLevel); * * } * else * { * source.PlayOneShot(guardStepThree, lowSoundLevel); * * } * playGuard3 = false; * playGuard4 = true; * } * * else if (!playGuard2 && !playGuard3 && playGuard4) * { * if (sound.type == SoundType.CLOSE) * { * source.PlayOneShot(guardStepFour, highSoundLevel); * } * else if (sound.type == SoundType.NEAR) * { * source.PlayOneShot(guardStepFour, medSoundLevel); * * } * else * { * source.PlayOneShot(guardStepFour, lowSoundLevel); * * } * * playGuard4 = false; * }*/ } }
public void AddSound(PlayableSound sound) { SoundsToPlayList.Add(sound); }
private void OnBeatEvent(BeatEvent beatEvent) { Queue <AcademicChord> academicChordsQueue = context.academicChordsQueue; PlayableSoundQueue queue = context.playableSoundQueue; while (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count > 0) { AcademicChord academicChord = academicChordsQueue.Dequeue(); PlayableSound lastSound = queue.GetLastSound(); int timeQuantumNumber = beatEvent.timeQuantumNumber; if (lastSound != null) { timeQuantumNumber = lastSound.startTimeQuantumNumber + lastSound.durationTimeQuanta; } int beatCounter = timeQuantumNumber / context.beatManager.timeQuantaPerBeat; bool isStrong = beatCounter % context.beatManager.measure == 0; float volume = isStrong ? 1f : 0.75f; if (_useMelody) { for (int i = 0; i < academicChord.notes.Length; ++i) { Note chordNote = academicChord.notes[i]; Pitch pitch = new Pitch(chordNote, (i == 0 || chordNote > academicChord.notes[0]) ? 4 : 5); queue.AddSound(new PlayableSound(pitch, volume, timeQuantumNumber, context.beatManager.timeQuantaPerBeat)); } } if (_useBass) { Pitch bass = new Pitch(academicChord.notes[0], 2); queue.AddSound(new PlayableSound(bass, volume, timeQuantumNumber, context.beatManager.timeQuantaPerBeat)); } if (_useCounterMelody) { List <Pitch> arpeggioPitches = new List <Pitch>(); for (int i = 0; i < academicChord.notes.Length; ++i) { Note chordNote = academicChord.notes[i]; arpeggioPitches.Add(new Pitch(chordNote, (i == 0 || chordNote > academicChord.notes[0]) ? 6 : 7)); } ; const int arpeggioNoteDurationTimeQuanta = 8; List <int> indices = GetIndices(arpeggioPitches.Count, context.beatManager.timeQuantaPerBeat / arpeggioNoteDurationTimeQuanta); int arpeggioTimeQuantumNumber = timeQuantumNumber; foreach (int index in indices) { queue.AddSound(new PlayableSound(arpeggioPitches[index], volume, arpeggioTimeQuantumNumber, arpeggioNoteDurationTimeQuanta)); arpeggioTimeQuantumNumber += arpeggioNoteDurationTimeQuanta; } } } if (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count == 0) { Debug.LogWarning("Playable sounds queue is not full, but academic chords queue is empty"); } }