pub struct NamModel {
pub version: String,
pub architecture: String,
pub config: ModelConfig,
pub weights: Vec<f32>,
pub sample_rate: Option<f64>,
pub metadata: Option<Value>,
}Expand description
A parsed .nam model file.
This is the file representation — the raw config + flat weight blob. To run
inference, build a crate::WaveNet from it.
Fields§
§version: String.nam format version string (e.g. "0.5.4").
architecture: StringModel architecture, e.g. "WaveNet".
config: ModelConfigArchitecture-specific configuration (dispatched on Self::architecture).
weights: Vec<f32>Flat weight blob. The final element is head_scale (see NAM
export_weights). Stored as f32 to match NAM Core’s inference precision.
sample_rate: Option<f64>Training sample rate. Absent in older files; see Self::expected_sample_rate.
metadata: Option<Value>Opaque training/gear metadata. Not used for inference.
Implementations§
Source§impl NamModel
impl NamModel
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error>
Read and parse a .nam model from a file on disk.
Convenience over std::fs::read_to_string + Self::from_json_str.
Returns Error::Io if the file can’t be read, or Error::Json if its
contents aren’t valid .nam JSON.
Sourcepub fn from_json_str(json: &str) -> Result<Self, Error>
pub fn from_json_str(json: &str) -> Result<Self, Error>
Parse a .nam model from a JSON string already in memory.
Sourcepub fn expected_sample_rate(&self) -> f64
pub fn expected_sample_rate(&self) -> f64
The sample rate, in Hz, the model expects its input to be at — falling back
to DEFAULT_SAMPLE_RATE when the file does not specify one.
You must feed the model audio at this rate. nam-rs runs the forward pass
at whatever rate you hand it and does not resample. A model captured at one
rate fed audio at another produces silently wrong output: its dilations and
recurrence are defined in samples, not seconds. If your host runs at a
different rate, resample to this rate before crate::Model::process_buffer
and back afterwards — resampling is the caller’s responsibility. Mirrors NAM
Core’s GetExpectedSampleRate().
Sourcepub fn metadata_typed(&self) -> Metadata
pub fn metadata_typed(&self) -> Metadata
The file’s descriptive Metadata — name, gear, tone, trainer, date, loudness
and calibration levels — parsed from the raw metadata block in one shot.
Returns defaults (every field None) when the file has no metadata block.
Fields the block omits are None; keys we don’t type are ignored, and remain
reachable on Self::metadata. Parsing is per-field lenient, so a single
malformed entry costs only itself.
Prefer this over the single-field accessors (Self::loudness, etc.) when you
want several fields: each single-field accessor re-clones and re-parses the raw
JSON, whereas this parses once. (All are cold-path / load-time, so neither is on
the audio thread.)
Sourcepub fn loudness(&self) -> Option<f32>
pub fn loudness(&self) -> Option<f32>
Output loudness in dBFS RMS, if the file records it — see
Metadata::loudness, and note it is not LUFS.
Sourcepub fn input_level_dbu(&self) -> Option<f32>
pub fn input_level_dbu(&self) -> Option<f32>
Input calibration level in dBu (analog level at 0 dBFS in), if present.
Sourcepub fn includes_cab(&self) -> Option<bool>
pub fn includes_cab(&self) -> Option<bool>
Whether this capture already includes a speaker cabinet — see
Metadata::includes_cab for the details and the None case.
Use this to decide whether to put an impulse response after the model: a cab-inclusive capture followed by an IR puts two cabs in series.
Sourcepub fn output_level_dbu(&self) -> Option<f32>
pub fn output_level_dbu(&self) -> Option<f32>
Output calibration level in dBu (analog level at 0 dBFS out), if present.