Skip to content
Merged
22 changes: 11 additions & 11 deletions src/hpc/arrow_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub const PLANE_BINARY_BYTES: usize = 2048;
pub const BINARY_BYTES: usize = PLANE_BYTES; // 2048

/// Soaking accumulator length (i8 entries per plane).
pub const SOAKING_DIMS: usize = 10000;
pub const SOAKING_DIMS: usize = 16_384;

/// Sigma attention mask width in bytes (10000-bit mask).
pub const SIGMA_MASK_BYTES: usize = 1250;
/// Sigma attention mask width in bytes (16384-bit mask = 2048 bytes).
pub const SIGMA_MASK_BYTES: usize = 2048;

/// Default soaking dimension count.
pub const DEFAULT_SOAKING_DIM: usize = 10000;
pub const DEFAULT_SOAKING_DIM: usize = 16_384;

/// Schema field names for the bind_nodes_v2 three-plane layout.
pub mod schema {
Expand Down Expand Up @@ -266,7 +266,7 @@ pub struct BindNodeV2 {
pub object_soaking: Option<Vec<i8>>,
/// Composite XOR fingerprint: S XOR P XOR O.
pub spo_binary: [u8; PLANE_BINARY_BYTES],
/// 10000-bit attention mask (sigma).
/// 16384-bit attention mask (sigma).
pub sigma_mask: [u8; SIGMA_MASK_BYTES],
/// NARS frequency (u16 fixed-point, 0..65535).
pub nars_frequency: u16,
Expand Down Expand Up @@ -572,7 +572,7 @@ impl BindNodeV2 {

/// Convert a Plane accumulator (16384 i8) to a soaking vector (SOAKING_DIMS i8).
///
/// Truncates if the accumulator is longer than SOAKING_DIMS, pads with 0 if shorter.
/// With SOAKING_DIMS = 16384, the copy is one-to-one (no truncation, no padding).
fn acc_to_soaking(acc: &[i8; 16384]) -> Vec<i8> {
let mut soaking = vec![0i8; SOAKING_DIMS];
let copy_len = SOAKING_DIMS.min(acc.len());
Expand Down Expand Up @@ -878,8 +878,8 @@ mod tests {
#[test]
fn schema_constants() {
assert_eq!(PLANE_BINARY_BYTES, 2048);
assert_eq!(SOAKING_DIMS, 10000);
assert_eq!(SIGMA_MASK_BYTES, 1250);
assert_eq!(SOAKING_DIMS, 16_384);
assert_eq!(SIGMA_MASK_BYTES, 2048);
}

#[test]
Expand Down Expand Up @@ -1140,9 +1140,9 @@ mod tests {
let (mut s, mut p, mut o) = make_test_planes();
let node = BindNodeV2::new(&mut s, &mut p, &mut o, "test");
assert_eq!(node.sigma_mask.len(), SIGMA_MASK_BYTES);
assert_eq!(node.sigma_mask.len(), 1250);
// sigma_mask * 8 = 10000 bits
assert_eq!(node.sigma_mask.len() * 8, 10000);
assert_eq!(node.sigma_mask.len(), 2048);
// sigma_mask * 8 = 16384 bits
assert_eq!(node.sigma_mask.len() * 8, 16_384);
}

#[test]
Expand Down
13 changes: 13 additions & 0 deletions src/hpc/audio/codec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@
/// what aspect of that codec it captures, and what it replaces.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CodecSource {
/// Opus / CELT.
Opus,
/// OpenAI Whisper.
Whisper,
/// MP3.
Mp3,
/// Ogg Vorbis.
OggVorbis,
/// Suno Bark.
Bark,
/// ElevenLabs.
ElevenLabs,
}

Expand All @@ -66,11 +72,17 @@ pub enum AudioAspect {

/// Complete provenance record for one primitive.
pub struct Provenance {
/// Name of the primitive in this codebase.
pub our_type: &'static str,
/// Byte size of the primitive (0 = transform/decision, not stored).
pub byte_size: usize,
/// Production codec the primitive was transcoded from.
pub source: CodecSource,
/// Aspect of audio the primitive captures.
pub aspect: AudioAspect,
/// Concept in the source codec that this corresponds to.
pub source_concept: &'static str,
/// What this primitive replaces (in the source codec or a peer).
pub what_it_replaces: &'static str,
}

Expand Down Expand Up @@ -212,6 +224,7 @@ pub const PROVENANCE: &[Provenance] = &[
/// Bark tokens: ~128 bytes per frame
/// Ours: 52-69 bytes per frame (complete, including phase + identity)
pub const FRAME_BUDGET: usize = 52;
/// Per-frame byte budget when the TTS RvqFrame (17 bytes) is also carried.
pub const FRAME_BUDGET_WITH_TTS: usize = 69;

/// Codec comparison: bits per second at comparable quality.
Expand Down
7 changes: 7 additions & 0 deletions src/hpc/audio/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ use super::bands;
/// and maps to a Base17 stride for spectral character.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Mode {
/// Ionian (major): W-W-H-W-W-W-H — bright, resolved.
Ionian, // Major: W-W-H-W-W-W-H → bright, resolved
/// Dorian: minor with natural 6th — warm, jazz.
Dorian, // Minor with ♮6: warm, jazz
/// Phrygian: minor with flat 2nd — dark, flamenco.
Phrygian, // Minor with ♭2: dark, flamenco
/// Lydian: major with sharp 4th — dreamy, floating.
Lydian, // Major with ♯4: dreamy, floating
/// Mixolydian: major with flat 7th — dominant, bluesy.
Mixolydian, // Major with ♭7: dominant, bluesy
/// Aeolian (natural minor) — sad, reflective.
Aeolian, // Natural minor: sad, reflective
/// Locrian (diminished) — unstable, tense.
Locrian, // Diminished: unstable, tense
}

Expand Down
1 change: 1 addition & 0 deletions src/hpc/audio/phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub fn phase_gradient(
/// Together: complete nonverbal vocal characterization in 52 bytes.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PhaseDescriptor {
/// 4-byte packed descriptor (coherence, gradient, entropy, stability).
pub bytes: [u8; 4],
}

Expand Down
9 changes: 9 additions & 0 deletions src/hpc/audio/voice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ pub const N_VOICE_CHANNELS: usize = 16;
/// Compression: 16 bytes (vs Bark's 1024-dim semantic token embedding).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct VoiceArchetype {
/// 16 i8 voice-identity channels (pitch / resonance / articulation / prosody).
pub channels: [i8; N_VOICE_CHANNELS],
}

impl VoiceArchetype {
/// Serialized size of a VoiceArchetype, in bytes.
pub const BYTE_SIZE: usize = N_VOICE_CHANNELS;

/// Zero archetype (neutral voice).
Expand Down Expand Up @@ -177,6 +179,7 @@ impl VoiceArchetype {
/// For a 256-entry codebook: 256 × 16 bytes = 4 KB.
#[derive(Clone, Debug)]
pub struct VoiceCodebook {
/// Voice archetype prototypes; index = codebook ID.
pub entries: Vec<VoiceArchetype>,
}

Expand Down Expand Up @@ -245,6 +248,7 @@ pub struct RvqFrame {
}

impl RvqFrame {
/// Serialized size of an RvqFrame, in bytes.
pub const BYTE_SIZE: usize = 17;

/// Serialize to 17 bytes.
Expand Down Expand Up @@ -292,20 +296,25 @@ impl RvqFrame {
/// VoiceFrame (21B) is the compressed synthesis frame.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct VoiceFrame {
/// Compressed RVQ codes (archetype + coarse + fine).
pub rvq: RvqFrame,
/// Per-frame phase dynamics descriptor.
pub phase: super::phase::PhaseDescriptor,
}

impl VoiceFrame {
/// Serialized size of a VoiceFrame, in bytes (RvqFrame + 4-byte phase).
pub const BYTE_SIZE: usize = RvqFrame::BYTE_SIZE + 4; // 21 bytes

/// Serialize this VoiceFrame to its 21-byte wire representation.
pub fn to_bytes(&self) -> [u8; Self::BYTE_SIZE] {
let mut bytes = [0u8; Self::BYTE_SIZE];
bytes[..17].copy_from_slice(&self.rvq.to_bytes());
bytes[17..21].copy_from_slice(&self.phase.bytes);
bytes
}

/// Deserialize a VoiceFrame from its 21-byte wire representation.
pub fn from_bytes(bytes: &[u8; Self::BYTE_SIZE]) -> Self {
let mut rvq_bytes = [0u8; 17];
rvq_bytes.copy_from_slice(&bytes[..17]);
Expand Down
22 changes: 9 additions & 13 deletions src/hpc/deepnsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,14 @@ pub fn nsm_decompose(text: &str) -> NsmDecomposition {
NsmDecomposition { weights, dominant }
}

/// Encode an NSM decomposition as a 10000-bit binary vector (1250 bytes).
/// Encode an NSM decomposition as a 16384-bit binary vector (2048 bytes).
///
/// For each prime with weight > 0, hash prime_index with blake3 to produce
/// a deterministic bit pattern, then XOR into result for primes whose
/// normalised weight exceeds 0.5 of the max weight (or any nonzero weight
/// when only one prime is present).
pub fn nsm_to_fingerprint(decomp: &NsmDecomposition) -> [u8; 1250] {
let mut result = [0u8; 1250];
pub fn nsm_to_fingerprint(decomp: &NsmDecomposition) -> [u8; 2048] {
let mut result = [0u8; 2048];

let max_w = decomp.weights.iter().cloned().fold(0.0f32, f32::max);
if max_w == 0.0 {
Expand All @@ -665,31 +665,27 @@ pub fn nsm_to_fingerprint(decomp: &NsmDecomposition) -> [u8; 1250] {
if w < threshold {
continue;
}
// Hash the prime index to get a deterministic 1250-byte pattern
// Hash the prime index to get a deterministic 2048-byte pattern
let hash_input = (i as u32).to_le_bytes();
let mut pattern = [0u8; 1250];
// Use blake3 in extended-output mode to fill 1250 bytes
let mut pattern = [0u8; 2048];
// Use blake3 in extended-output mode to fill 2048 bytes
let mut hasher = blake3::Hasher::new();
hasher.update(&hash_input);
let mut reader = hasher.finalize_xof();
reader.fill(&mut pattern);

// XOR 1250 bytes via crate::simd::U8x64.
// 1250 = 19×64 (1216) + 34 scalar remainder.
// XOR 2048 bytes via crate::simd::U8x64.
// 2048 = 32×64 exactly (no scalar remainder, SIMD-clean).
{
use crate::simd::U8x64;
let chunks = 1250 / 64; // 19
let chunks = 2048 / 64; // 32
for c in 0..chunks {
let off = c * 64;
let vr = U8x64::from_slice(&result[off..off + 64]);
let vp = U8x64::from_slice(&pattern[off..off + 64]);
let xored = vr ^ vp;
xored.copy_to_slice(&mut result[off..off + 64]);
}
// Scalar remainder (34 bytes).
for j in (chunks * 64)..1250 {
result[j] ^= pattern[j];
}
}
}

Expand Down
Loading
Loading