Skip to content

Commit

Permalink
Allow audio sampling rate of 96 kHz
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Horacek <[email protected]>
  • Loading branch information
phoracek committed Sep 28, 2023
1 parent 0a9768f commit a112c9e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ backwards compatibility.

## Unreleased

* Allow audio sampling rate of 96 kHz.

## 0.8.0

* **Breaking** Remove logging abstractions from the crate.
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/audio/codec/wm8731.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
];
4 changes: 4 additions & 0 deletions src/audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a112c9e

Please sign in to comment.