Skip to main content

TuningTable

Struct TuningTable 

Source
pub struct TuningTable {
    pub frequencies: Vec<f32>,
    pub name: String,
    pub description: String,
}
Expand description

Maps MIDI note numbers (0–127) to frequencies in Hz. Stored as Vec for serde compatibility.

Fields§

§frequencies: Vec<f32>

Frequency in Hz for each MIDI note 0–127.

§name: String

Human-readable name.

§description: String

Description of the tuning system.

Implementations§

Source§

impl TuningTable

Source

pub fn equal_temperament(concert_a: f32) -> Self

Standard 12-tone equal temperament. A4 (MIDI note 69) = concert_a Hz (typically 440.0).

Examples found in repository?
examples/tuning_comparison.rs (line 15)
10fn main() {
11    println!("AetherDSP MIDI - Tuning System Comparison");
12    println!("==========================================\n");
13
14    // Create tuning tables (all use A4=440Hz)
15    let equal_temp = TuningTable::equal_temperament(440.0);
16    let tizita = TuningTable::ethiopian_tizita(440.0);
17    let rast = TuningTable::arabic_maqam_rast(440.0);
18    let yaman = TuningTable::indian_raga_yaman(440.0);
19
20    println!("Comparing tuning systems for one octave (C4-C5):\n");
21    println!("{:4} | {:>10} | {:>10} | {:>10} | {:>10} | {:>8}",
22        "MIDI", "12-TET", "Tizita", "Rast", "Yaman", "Cents");
23    println!("{}", "-".repeat(70));
24
25    // Compare middle C octave (MIDI 60-72)
26    for midi_note in 60..=72 {
27        let freq_12tet = equal_temp.frequency(midi_note);
28        let freq_tizita = tizita.frequency(midi_note);
29        let freq_rast = rast.frequency(midi_note);
30        let freq_yaman = yaman.frequency(midi_note);
31
32        // Calculate cents deviation from 12-TET
33        let cents_tizita: f32 = 1200.0 * (freq_tizita / freq_12tet).log2();
34        let cents_rast: f32 = 1200.0 * (freq_rast / freq_12tet).log2();
35        let cents_yaman: f32 = 1200.0 * (freq_yaman / freq_12tet).log2();
36
37        let note_name = get_note_name(midi_note);
38
39        println!("{:4} | {:10.2} | {:10.2} | {:10.2} | {:10.2} | {:+8.1}",
40            format!("{} ({})", midi_note, note_name),
41            freq_12tet,
42            freq_tizita,
43            freq_rast,
44            freq_yaman,
45            cents_tizita.max(cents_rast).max(cents_yaman)
46        );
47    }
48
49    println!("\n📊 Key Observations:");
50    println!("  • Ethiopian Tizita: Pentatonic scale with characteristic flat intervals");
51    println!("  • Arabic Maqam Rast: Quarter-tone flats on 3rd and 7th degrees");
52    println!("  • Indian Raga Yaman: Just intonation with raised 4th (Kalyan thaat)");
53    println!("  • Cents: Deviation from 12-TET (100 cents = 1 semitone)");
54
55    println!("\n✓ Try these tuning systems in your music!");
56}
Source

pub fn from_cents_offsets(concert_a: f32, offsets: &[f32; 12]) -> Self

Build a tuning table from cents offsets per semitone within an octave. offsets is a 12-element array of cent offsets from 12-TET for each pitch class (C, C#, D, D#, E, F, F#, G, G#, A, A#, B).

Source

pub fn from_frequencies( freqs: Vec<f32>, name: &str, description: &str, ) -> Option<Self>

Build from explicit frequency list. Length must be 128.

Source

pub fn frequency(&self, note: u8) -> f32

Get frequency for a MIDI note number.

Examples found in repository?
examples/tuning_comparison.rs (line 27)
10fn main() {
11    println!("AetherDSP MIDI - Tuning System Comparison");
12    println!("==========================================\n");
13
14    // Create tuning tables (all use A4=440Hz)
15    let equal_temp = TuningTable::equal_temperament(440.0);
16    let tizita = TuningTable::ethiopian_tizita(440.0);
17    let rast = TuningTable::arabic_maqam_rast(440.0);
18    let yaman = TuningTable::indian_raga_yaman(440.0);
19
20    println!("Comparing tuning systems for one octave (C4-C5):\n");
21    println!("{:4} | {:>10} | {:>10} | {:>10} | {:>10} | {:>8}",
22        "MIDI", "12-TET", "Tizita", "Rast", "Yaman", "Cents");
23    println!("{}", "-".repeat(70));
24
25    // Compare middle C octave (MIDI 60-72)
26    for midi_note in 60..=72 {
27        let freq_12tet = equal_temp.frequency(midi_note);
28        let freq_tizita = tizita.frequency(midi_note);
29        let freq_rast = rast.frequency(midi_note);
30        let freq_yaman = yaman.frequency(midi_note);
31
32        // Calculate cents deviation from 12-TET
33        let cents_tizita: f32 = 1200.0 * (freq_tizita / freq_12tet).log2();
34        let cents_rast: f32 = 1200.0 * (freq_rast / freq_12tet).log2();
35        let cents_yaman: f32 = 1200.0 * (freq_yaman / freq_12tet).log2();
36
37        let note_name = get_note_name(midi_note);
38
39        println!("{:4} | {:10.2} | {:10.2} | {:10.2} | {:10.2} | {:+8.1}",
40            format!("{} ({})", midi_note, note_name),
41            freq_12tet,
42            freq_tizita,
43            freq_rast,
44            freq_yaman,
45            cents_tizita.max(cents_rast).max(cents_yaman)
46        );
47    }
48
49    println!("\n📊 Key Observations:");
50    println!("  • Ethiopian Tizita: Pentatonic scale with characteristic flat intervals");
51    println!("  • Arabic Maqam Rast: Quarter-tone flats on 3rd and 7th degrees");
52    println!("  • Indian Raga Yaman: Just intonation with raised 4th (Kalyan thaat)");
53    println!("  • Cents: Deviation from 12-TET (100 cents = 1 semitone)");
54
55    println!("\n✓ Try these tuning systems in your music!");
56}
Source

pub fn freq_to_note_cents(&self, freq: f32) -> (u8, f32)

Convert frequency to the nearest MIDI note + cents deviation.

Source

pub fn ethiopian_tizita(concert_a: f32) -> Self

Ethiopian Kiñit (pentatonic) approximation. Uses the Tizita major scale pattern.

Examples found in repository?
examples/tuning_comparison.rs (line 16)
10fn main() {
11    println!("AetherDSP MIDI - Tuning System Comparison");
12    println!("==========================================\n");
13
14    // Create tuning tables (all use A4=440Hz)
15    let equal_temp = TuningTable::equal_temperament(440.0);
16    let tizita = TuningTable::ethiopian_tizita(440.0);
17    let rast = TuningTable::arabic_maqam_rast(440.0);
18    let yaman = TuningTable::indian_raga_yaman(440.0);
19
20    println!("Comparing tuning systems for one octave (C4-C5):\n");
21    println!("{:4} | {:>10} | {:>10} | {:>10} | {:>10} | {:>8}",
22        "MIDI", "12-TET", "Tizita", "Rast", "Yaman", "Cents");
23    println!("{}", "-".repeat(70));
24
25    // Compare middle C octave (MIDI 60-72)
26    for midi_note in 60..=72 {
27        let freq_12tet = equal_temp.frequency(midi_note);
28        let freq_tizita = tizita.frequency(midi_note);
29        let freq_rast = rast.frequency(midi_note);
30        let freq_yaman = yaman.frequency(midi_note);
31
32        // Calculate cents deviation from 12-TET
33        let cents_tizita: f32 = 1200.0 * (freq_tizita / freq_12tet).log2();
34        let cents_rast: f32 = 1200.0 * (freq_rast / freq_12tet).log2();
35        let cents_yaman: f32 = 1200.0 * (freq_yaman / freq_12tet).log2();
36
37        let note_name = get_note_name(midi_note);
38
39        println!("{:4} | {:10.2} | {:10.2} | {:10.2} | {:10.2} | {:+8.1}",
40            format!("{} ({})", midi_note, note_name),
41            freq_12tet,
42            freq_tizita,
43            freq_rast,
44            freq_yaman,
45            cents_tizita.max(cents_rast).max(cents_yaman)
46        );
47    }
48
49    println!("\n📊 Key Observations:");
50    println!("  • Ethiopian Tizita: Pentatonic scale with characteristic flat intervals");
51    println!("  • Arabic Maqam Rast: Quarter-tone flats on 3rd and 7th degrees");
52    println!("  • Indian Raga Yaman: Just intonation with raised 4th (Kalyan thaat)");
53    println!("  • Cents: Deviation from 12-TET (100 cents = 1 semitone)");
54
55    println!("\n✓ Try these tuning systems in your music!");
56}
Source

pub fn just_intonation(concert_a: f32) -> Self

Just intonation (pure intervals based on harmonic series).

Source§

impl TuningTable

Source

pub fn arabic_maqam_rast(concert_a: f32) -> Self

Arabic Maqam Rast — the most common Arabic maqam. Uses quarter-tone flats on the 3rd and 7th scale degrees.

Examples found in repository?
examples/tuning_comparison.rs (line 17)
10fn main() {
11    println!("AetherDSP MIDI - Tuning System Comparison");
12    println!("==========================================\n");
13
14    // Create tuning tables (all use A4=440Hz)
15    let equal_temp = TuningTable::equal_temperament(440.0);
16    let tizita = TuningTable::ethiopian_tizita(440.0);
17    let rast = TuningTable::arabic_maqam_rast(440.0);
18    let yaman = TuningTable::indian_raga_yaman(440.0);
19
20    println!("Comparing tuning systems for one octave (C4-C5):\n");
21    println!("{:4} | {:>10} | {:>10} | {:>10} | {:>10} | {:>8}",
22        "MIDI", "12-TET", "Tizita", "Rast", "Yaman", "Cents");
23    println!("{}", "-".repeat(70));
24
25    // Compare middle C octave (MIDI 60-72)
26    for midi_note in 60..=72 {
27        let freq_12tet = equal_temp.frequency(midi_note);
28        let freq_tizita = tizita.frequency(midi_note);
29        let freq_rast = rast.frequency(midi_note);
30        let freq_yaman = yaman.frequency(midi_note);
31
32        // Calculate cents deviation from 12-TET
33        let cents_tizita: f32 = 1200.0 * (freq_tizita / freq_12tet).log2();
34        let cents_rast: f32 = 1200.0 * (freq_rast / freq_12tet).log2();
35        let cents_yaman: f32 = 1200.0 * (freq_yaman / freq_12tet).log2();
36
37        let note_name = get_note_name(midi_note);
38
39        println!("{:4} | {:10.2} | {:10.2} | {:10.2} | {:10.2} | {:+8.1}",
40            format!("{} ({})", midi_note, note_name),
41            freq_12tet,
42            freq_tizita,
43            freq_rast,
44            freq_yaman,
45            cents_tizita.max(cents_rast).max(cents_yaman)
46        );
47    }
48
49    println!("\n📊 Key Observations:");
50    println!("  • Ethiopian Tizita: Pentatonic scale with characteristic flat intervals");
51    println!("  • Arabic Maqam Rast: Quarter-tone flats on 3rd and 7th degrees");
52    println!("  • Indian Raga Yaman: Just intonation with raised 4th (Kalyan thaat)");
53    println!("  • Cents: Deviation from 12-TET (100 cents = 1 semitone)");
54
55    println!("\n✓ Try these tuning systems in your music!");
56}
Source

pub fn arabic_maqam_bayati(concert_a: f32) -> Self

Arabic Maqam Bayati — second most common Arabic maqam. Characteristic half-flat on the 2nd degree.

Source

pub fn ethiopian_bati(concert_a: f32) -> Self

Ethiopian Bati scale — minor pentatonic variant.

Source

pub fn indian_raga_yaman(concert_a: f32) -> Self

Indian Raga Yaman (Kalyan thaat) — the most common North Indian raga. Uses a raised 4th (Ma tivra).

Examples found in repository?
examples/tuning_comparison.rs (line 18)
10fn main() {
11    println!("AetherDSP MIDI - Tuning System Comparison");
12    println!("==========================================\n");
13
14    // Create tuning tables (all use A4=440Hz)
15    let equal_temp = TuningTable::equal_temperament(440.0);
16    let tizita = TuningTable::ethiopian_tizita(440.0);
17    let rast = TuningTable::arabic_maqam_rast(440.0);
18    let yaman = TuningTable::indian_raga_yaman(440.0);
19
20    println!("Comparing tuning systems for one octave (C4-C5):\n");
21    println!("{:4} | {:>10} | {:>10} | {:>10} | {:>10} | {:>8}",
22        "MIDI", "12-TET", "Tizita", "Rast", "Yaman", "Cents");
23    println!("{}", "-".repeat(70));
24
25    // Compare middle C octave (MIDI 60-72)
26    for midi_note in 60..=72 {
27        let freq_12tet = equal_temp.frequency(midi_note);
28        let freq_tizita = tizita.frequency(midi_note);
29        let freq_rast = rast.frequency(midi_note);
30        let freq_yaman = yaman.frequency(midi_note);
31
32        // Calculate cents deviation from 12-TET
33        let cents_tizita: f32 = 1200.0 * (freq_tizita / freq_12tet).log2();
34        let cents_rast: f32 = 1200.0 * (freq_rast / freq_12tet).log2();
35        let cents_yaman: f32 = 1200.0 * (freq_yaman / freq_12tet).log2();
36
37        let note_name = get_note_name(midi_note);
38
39        println!("{:4} | {:10.2} | {:10.2} | {:10.2} | {:10.2} | {:+8.1}",
40            format!("{} ({})", midi_note, note_name),
41            freq_12tet,
42            freq_tizita,
43            freq_rast,
44            freq_yaman,
45            cents_tizita.max(cents_rast).max(cents_yaman)
46        );
47    }
48
49    println!("\n📊 Key Observations:");
50    println!("  • Ethiopian Tizita: Pentatonic scale with characteristic flat intervals");
51    println!("  • Arabic Maqam Rast: Quarter-tone flats on 3rd and 7th degrees");
52    println!("  • Indian Raga Yaman: Just intonation with raised 4th (Kalyan thaat)");
53    println!("  • Cents: Deviation from 12-TET (100 cents = 1 semitone)");
54
55    println!("\n✓ Try these tuning systems in your music!");
56}
Source

pub fn gamelan_slendro(_concert_a: f32) -> Self

Javanese Gamelan Slendro — 5-tone scale. Approximate equal division of the octave into 5 parts.

Source

pub fn gamelan_pelog(concert_a: f32) -> Self

Javanese Gamelan Pelog — 7-tone scale with characteristic large and small intervals.

Trait Implementations§

Source§

impl Clone for TuningTable

Source§

fn clone(&self) -> TuningTable

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TuningTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TuningTable

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TuningTable

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TuningTable

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,