Skip to content

Commit 2e7db42

Browse files
committed
refactor!: make SampleRate a u32 alias
1 parent 6dbb4fb commit 2e7db42

File tree

26 files changed

+110
-149
lines changed

26 files changed

+110
-149
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Add `Display` and `FromStr` implementations for `HostId`.
66
- Add support for custom `Host`s, `Device`s, and `Stream`s.
77
- Add `Sample::bits_per_sample` method.
8+
- Change `SampleRate` from struct to type `u32` alias.
89
- Update `audio_thread_priority` to 0.34.
910
- AAudio: Configure buffer to ensure consistent callback buffer sizes.
1011
- AAudio: Make `Stream` implement `Send` and `Sync`.
@@ -17,7 +18,7 @@
1718
- ALSA: Fix format selection to probe hardware endianness instead of assuming native byte order.
1819
- ALSA: Add support for 12, 24, 352.8, 384, 705.6, and 768 kHz sample rates.
1920
- ALSA: Update `alsa` to 0.10.
20-
- ALSA(process_output): Pass `silent=true` to `PCM.try_recover`, so it doesn't write to stderr.
21+
- ALSA: Pass `silent=true` to `PCM.try_recover`, so it doesn't write to stderr.
2122
- ASIO: Fix linker flags for MinGW cross-compilation.
2223
- ASIO: Add packed(4) to representation of ASIO time structs in bindings.
2324
- CI: Added native ARM64 Linux support in GitHub Actions.

examples/android/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn run<T>(device: &cpal::Device, config: &cpal::StreamConfig) -> Result<(), anyh
4242
where
4343
T: SizedSample + FromSample<f32>,
4444
{
45-
let sample_rate = config.sample_rate.0 as f32;
45+
let sample_rate = config.sample_rate as f32;
4646
let channels = config.channels as usize;
4747

4848
// Produce a sinusoid of maximum amplitude.

examples/audioworklet-beep/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn run<T>(device: &cpal::Device, config: &cpal::StreamConfig) -> Stream
6868
where
6969
T: cpal::Sample + cpal::SizedSample + cpal::FromSample<f32>,
7070
{
71-
let sample_rate = config.sample_rate.0 as f32;
71+
let sample_rate = config.sample_rate as f32;
7272
let channels = config.channels as usize;
7373

7474
// Produce a sinusoid of maximum amplitude.

examples/beep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn run<T>(device: &cpal::Device, config: &cpal::StreamConfig) -> Result<(),
9898
where
9999
T: SizedSample + FromSample<f32>,
100100
{
101-
let sample_rate = config.sample_rate.0 as f32;
101+
let sample_rate = config.sample_rate as f32;
102102
let channels = config.channels as usize;
103103

104104
// Produce a sinusoid of maximum amplitude.

examples/custom.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl DeviceTrait for MyDevice {
7878
) -> Result<Self::SupportedOutputConfigs, cpal::SupportedStreamConfigsError> {
7979
Ok(std::iter::once(cpal::SupportedStreamConfigRange::new(
8080
2,
81-
cpal::SampleRate(44100),
82-
cpal::SampleRate(44100),
81+
44100,
82+
44100,
8383
cpal::SupportedBufferSize::Unknown,
8484
cpal::SampleFormat::F32,
8585
)))
@@ -96,7 +96,7 @@ impl DeviceTrait for MyDevice {
9696
) -> Result<cpal::SupportedStreamConfig, cpal::DefaultStreamConfigError> {
9797
Ok(cpal::SupportedStreamConfig::new(
9898
2,
99-
cpal::SampleRate(44100),
99+
44100,
100100
cpal::SupportedBufferSize::Unknown,
101101
cpal::SampleFormat::I16,
102102
))
@@ -302,7 +302,7 @@ pub fn make_stream(
302302
let num_channels = config.channels as usize;
303303
let mut oscillator = Oscillator {
304304
waveform: Waveform::Sine,
305-
sample_rate: config.sample_rate.0 as f32,
305+
sample_rate: config.sample_rate as f32,
306306
current_sample_index: 0.0,
307307
frequency_hz: 440.0,
308308
};

examples/feedback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn main() -> anyhow::Result<()> {
104104
let config: cpal::StreamConfig = input_device.default_input_config()?.into();
105105

106106
// Create a delay in case the input and output devices aren't synced.
107-
let latency_frames = (opt.latency / 1_000.0) * config.sample_rate.0 as f32;
107+
let latency_frames = (opt.latency / 1_000.0) * config.sample_rate as f32;
108108
let latency_samples = latency_frames as usize * config.channels as usize;
109109

110110
// The buffer to share samples

examples/ios-feedback/src/feedback.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ extern crate cpal;
1111
extern crate ringbuf;
1212

1313
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
14-
use ringbuf::{HeapRb, traits::{Split, Producer, Consumer}};
14+
use ringbuf::{
15+
traits::{Consumer, Producer, Split},
16+
HeapRb,
17+
};
1518

1619
const LATENCY_MS: f32 = 1000.0;
1720

@@ -32,7 +35,7 @@ pub fn run_example() -> Result<(), anyhow::Error> {
3235
let config: cpal::StreamConfig = input_device.default_input_config()?.into();
3336

3437
// Create a delay in case the input and output devices aren't synced.
35-
let latency_frames = (LATENCY_MS / 1_000.0) * config.sample_rate.0 as f32;
38+
let latency_frames = (LATENCY_MS / 1_000.0) * config.sample_rate as f32;
3639
let latency_samples = latency_frames as usize * config.channels as usize;
3740

3841
// The buffer to share samples

examples/record_wav.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn sample_format(format: cpal::SampleFormat) -> hound::SampleFormat {
160160
fn wav_spec_from_config(config: &cpal::SupportedStreamConfig) -> hound::WavSpec {
161161
hound::WavSpec {
162162
channels: config.channels() as _,
163-
sample_rate: config.sample_rate().0 as _,
163+
sample_rate: config.sample_rate() as _,
164164
bits_per_sample: (config.sample_format().sample_size() * 8) as _,
165165
sample_format: sample_format(config.sample_format()),
166166
}

examples/synth_tones.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ where
139139
let num_channels = config.channels as usize;
140140
let mut oscillator = Oscillator {
141141
waveform: Waveform::Sine,
142-
sample_rate: config.sample_rate.0 as f32,
142+
sample_rate: config.sample_rate as f32,
143143
current_sample_index: 0.0,
144144
frequency_hz: 440.0,
145145
};

examples/wasm-beep/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn run<T>(device: &cpal::Device, config: &cpal::StreamConfig) -> Stream
6666
where
6767
T: cpal::Sample + cpal::SizedSample + cpal::FromSample<f32>,
6868
{
69-
let sample_rate = config.sample_rate.0 as f32;
69+
let sample_rate = config.sample_rate as f32;
7070
let channels = config.channels as usize;
7171

7272
// Produce a sinusoid of maximum amplitude.

0 commit comments

Comments
 (0)