diff --git a/CHANGELOG.md b/CHANGELOG.md index 07d2092..2dbc913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ backwards compatibility. ## Unreleased +* Allow audio sampling rate of 96 kHz. + ## 0.8.0 * **Breaking** Remove logging abstractions from the crate. diff --git a/Cargo.toml b/Cargo.toml index e2c41e5..1fa609d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ stm32h7xx-hal = { version = "0.14", features = [ "stm32h750v", "rt", "revision_v seed = [] seed_1_1 = [ "num_enum" ] patch_sm = [ "num_enum" ] +sampling_rate_96khz = [] [[example]] name = "blinky" diff --git a/Makefile b/Makefile index 691228a..355f039 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ format: clippy: cargo clippy --all --examples --features seed -- -D warnings cargo clippy --all --examples --features seed_1_1 -- -D warnings + cargo clippy --all --examples --features seed_1_1,sampling_rate_96khz -- -D warnings cargo clippy --all --examples --features patch_sm -- -D warnings cargo clippy --all --examples --features seed -- -D warnings diff --git a/README.md b/README.md index 3eddedf..e8be0a8 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ Select the board by using its respective feature. make flash WHAT=blinky BOARD=seed_1_1 ``` +# Sampling rate + +By default, the audio sampling rate is set to 48 kHz. This can be increased to +96 kHz by enabling the `sampling_rate_96khz` feature. + # API stability I am still trying to figure out a good API for the project. Expect it to change. diff --git a/src/audio/codec/wm8731.rs b/src/audio/codec/wm8731.rs index d1fe967..2d4eb60 100644 --- a/src/audio/codec/wm8731.rs +++ b/src/audio/codec/wm8731.rs @@ -74,6 +74,11 @@ enum Register { RESET = 0x0F, } +#[cfg(not(feature = "sampling_rate_96khz"))] +const SAMPLING_RATE: u8 = 0x00; // 48 kHz +#[cfg(feature = "sampling_rate_96khz")] +const SAMPLING_RATE: u8 = 0x07; // 96 kHz + const REGISTER_CONFIG: &[(Register, u8)] = &[ // Reset Codec. (Register::RESET, 0x00), @@ -91,7 +96,7 @@ const REGISTER_CONFIG: &[(Register, u8)] = &[ // Configure digital format. (Register::IFACE, 0x09), // Set samplerate. - (Register::SRATE, 0x00), + (Register::SRATE, SAMPLING_RATE), (Register::ACTIVE, 0x00), (Register::ACTIVE, 0x01), ]; diff --git a/src/audio/mod.rs b/src/audio/mod.rs index 9ff1a43..513edc6 100644 --- a/src/audio/mod.rs +++ b/src/audio/mod.rs @@ -12,4 +12,8 @@ pub use interface::{Block, Interface}; pub const BLOCK_LENGTH: usize = 32; // 32 samples pub const HALF_DMA_BUFFER_LENGTH: usize = BLOCK_LENGTH * 2; // 2 channels pub const DMA_BUFFER_LENGTH: usize = HALF_DMA_BUFFER_LENGTH * 2; // 2 half-blocks + +#[cfg(not(feature = "sampling_rate_96khz"))] pub const FS: time::Hertz = time::Hertz::from_raw(48_000); +#[cfg(feature = "sampling_rate_96khz")] +pub const FS: time::Hertz = time::Hertz::from_raw(96_000); diff --git a/src/lib.rs b/src/lib.rs index 6f6cdb0..645e2e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,12 @@ //! //! Select the board by using its respective feature. //! +//! # Sampling rate +//! +//! By default, the audio sampling rate is set to 48 kHz. This can be increased to +//! 96 kHz by enabling the `sampling_rate_96khz` feature. +//! +//! //! # API stability //! //! I am still trying to figure out a good API for the project. Expect it to change.