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.
This commit is contained in:
@@ -8,6 +8,7 @@ pub type AssetId = i32;
|
||||
pub enum BankType {
|
||||
GLYPH,
|
||||
SOUNDS,
|
||||
MUSIC,
|
||||
SCENE,
|
||||
// TILEMAPS,
|
||||
// BLOBS,
|
||||
@@ -41,9 +42,8 @@ pub struct GlyphBankMetadata {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct SoundBankMetadata {
|
||||
pub sample_rate: u32,
|
||||
pub channels: u32,
|
||||
pub struct AudioBankMetadata {
|
||||
pub version: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
@@ -73,15 +73,16 @@ impl AssetEntry {
|
||||
.map_err(|e| format!("Invalid GLYPH metadata for asset {}: {}", self.asset_id, e))
|
||||
}
|
||||
|
||||
pub fn metadata_as_sound_bank(&self) -> Result<SoundBankMetadata, String> {
|
||||
if self.bank_type != BankType::SOUNDS {
|
||||
return Err(format!(
|
||||
"Asset {} is not a SOUNDS bank (type: {:?})",
|
||||
self.asset_id, self.bank_type
|
||||
));
|
||||
pub fn metadata_as_audio_bank(&self) -> Result<AudioBankMetadata, String> {
|
||||
if !matches!(self.bank_type, BankType::SOUNDS | BankType::MUSIC) {
|
||||
return Err("asset is not an audio bank".into());
|
||||
}
|
||||
serde_json::from_value(self.metadata.clone())
|
||||
.map_err(|e| format!("Invalid SOUNDS metadata for asset {}: {}", self.asset_id, e))
|
||||
let metadata: AudioBankMetadata = serde_json::from_value(self.metadata.clone())
|
||||
.map_err(|e| format!("Invalid audio metadata: {e}"))?;
|
||||
if metadata.version != 1 {
|
||||
return Err("unsupported audio metadata version".into());
|
||||
}
|
||||
Ok(metadata)
|
||||
}
|
||||
|
||||
pub fn metadata_as_scene_bank(&self) -> Result<SceneBankMetadata, String> {
|
||||
@@ -189,6 +190,9 @@ pub struct SlotRef {
|
||||
}
|
||||
|
||||
impl SlotRef {
|
||||
pub fn music(index: usize) -> Self {
|
||||
Self { asset_type: BankType::MUSIC, index }
|
||||
}
|
||||
pub fn gfx(index: usize) -> Self {
|
||||
Self { asset_type: BankType::GLYPH, index }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user