Files
prometeu-runtime/crates/console/prometeu-hal/src/sample.rs
T
bquarkz 8510c5b00d feat(audio): add 32-voice PCM mixing and native music sequencing
Add self-contained SoundBanks and MusicBanks with per-sample PCM16 and IMA ADPCM storage, materialized to resident PCM16. Integrate instrument envelopes, automation, shared DSP and host lifecycle controls while preserving staged real-time execution.
2026-11-20 22:15:24 +00:00

45 lines
1.1 KiB
Rust

#[derive(Debug)]
pub struct Sample {
pub sample_rate: u32,
pub channels: u8,
pub data: Vec<i16>,
pub loop_start: Option<u32>,
pub loop_end: Option<u32>,
pub default_volume: u8,
pub default_pan: u8,
pub default_pitch: f64,
}
impl Sample {
pub fn new(sample_rate: u32, data: Vec<i16>) -> Self {
Self {
sample_rate,
channels: 1,
data,
loop_start: None,
loop_end: None,
default_volume: 255,
default_pan: 128,
default_pitch: 1.0,
}
}
pub fn with_loop(mut self, start: u32, end: u32) -> Self {
self.loop_start = Some(start);
self.loop_end = Some(end);
self
}
pub fn frames_len(&self) -> usize {
self.data.len() / self.channels.max(1) as usize
}
pub fn with_channels(mut self, channels: u8) -> Result<Self, String> {
if !(1..=2).contains(&channels) || !self.data.len().is_multiple_of(channels as usize) {
return Err("audio sample channels/frame count".into());
}
self.channels = channels;
Ok(self)
}
}