Reorganize sound code

This commit is contained in:
Alex Page 2022-01-27 17:22:14 -05:00
parent 6ce6470236
commit b48684201b
5 changed files with 43 additions and 43 deletions

View file

@ -2,21 +2,38 @@ use std::{array, iter, time::Duration};
use bracket_lib::random::RandomNumberGenerator;
use crate::resources::sound_system::{
Sound, SoundEffect, SoundEffectSamples, SoundSystem, SoundType,
};
use crate::resources::sound_output::{SoundOutput, SoundSamples};
type Frequency = u32;
type MinFrequency = u32;
type MaxFrequency = u32;
pub enum SoundType {
Silence,
Tone(Frequency),
Noise(MinFrequency, MaxFrequency),
}
pub struct Sound {
pub sound_type: SoundType,
pub duration: Duration,
}
pub struct SoundEffect {
pub sounds: Vec<Sound>,
}
pub struct SoundEffects {
pub startup: SoundEffectSamples,
pub step: SoundEffectSamples,
pub pickup: SoundEffectSamples,
pub bad_key: SoundEffectSamples,
pub blocked: SoundEffectSamples,
pub startup: SoundSamples,
pub step: SoundSamples,
pub pickup: SoundSamples,
pub bad_key: SoundSamples,
pub blocked: SoundSamples,
rng: RandomNumberGenerator,
}
impl SoundEffects {
pub fn new(ss: &SoundSystem) -> Self {
pub fn new(ss: &SoundOutput) -> Self {
Self {
startup: ss.render_sound_effect(&SoundEffect {
sounds: (30..400)
@ -92,7 +109,7 @@ impl SoundEffects {
}
}
pub fn get_new_static_effect(&mut self, ss: &SoundSystem) -> SoundEffectSamples {
pub fn get_new_static_effect(&mut self, ss: &SoundOutput) -> SoundSamples {
ss.render_sound_effect(&SoundEffect {
sounds: (1..=33)
.map(|_| {