formatting
This commit is contained in:
parent
23f2d4da02
commit
c5b2e216cf
|
@ -15,7 +15,13 @@ pub const AUDIO_FREQUENCY_11KHZ: u32 = 11025;
|
||||||
|
|
||||||
pub const SILENCE: u8 = sdl2::audio::AudioFormatNum::SILENCE;
|
pub const SILENCE: u8 = sdl2::audio::AudioFormatNum::SILENCE;
|
||||||
|
|
||||||
pub const TARGET_AUDIO_SPEC: AudioSpec = AudioSpec { frequency: AUDIO_FREQUENCY_22KHZ, channels: 1, format: AudioFormat::U8 };
|
pub const TARGET_AUDIO_SPEC: AudioSpec = AudioSpec {
|
||||||
|
frequency: AUDIO_FREQUENCY_22KHZ,
|
||||||
|
channels: 1,
|
||||||
|
format: AudioFormat::U8,
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct AudioSpec {
|
pub struct AudioSpec {
|
||||||
|
@ -29,7 +35,7 @@ impl AudioSpec {
|
||||||
AudioSpec {
|
AudioSpec {
|
||||||
frequency,
|
frequency,
|
||||||
channels,
|
channels,
|
||||||
format
|
format,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +55,8 @@ impl AudioSpec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct AudioChannel {
|
pub struct AudioChannel {
|
||||||
pub playing: bool,
|
pub playing: bool,
|
||||||
|
@ -145,10 +153,12 @@ impl AudioChannel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum AudioDeviceError {
|
pub enum AudioDeviceError {
|
||||||
#[error("That buffer's AudioSpec does not match the device's AudioSpec")]
|
#[error("That buffer's AudioSpec does not match the device's AudioSpec")]
|
||||||
AudioSpecMismatch
|
AudioSpecMismatch,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AudioDevice {
|
pub struct AudioDevice {
|
||||||
|
@ -197,7 +207,11 @@ impl AudioDevice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play_buffer(&mut self, buffer: &AudioBuffer, loops: bool) -> Result<Option<&mut AudioChannel>, AudioDeviceError> {
|
pub fn play_buffer(
|
||||||
|
&mut self,
|
||||||
|
buffer: &AudioBuffer,
|
||||||
|
loops: bool,
|
||||||
|
) -> Result<Option<&mut AudioChannel>, AudioDeviceError> {
|
||||||
if buffer.spec != self.spec {
|
if buffer.spec != self.spec {
|
||||||
Err(AudioDeviceError::AudioSpecMismatch)
|
Err(AudioDeviceError::AudioSpecMismatch)
|
||||||
} else {
|
} else {
|
||||||
|
@ -267,6 +281,8 @@ impl IndexMut<usize> for AudioDevice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum AudioBufferError {
|
pub enum AudioBufferError {
|
||||||
#[error("Error during format conversion: {0}")]
|
#[error("Error during format conversion: {0}")]
|
||||||
|
|
Loading…
Reference in a new issue