Skip to content

Commit 33b8919

Browse files
Asio support for int24 (#927)
* added new sample format i24 * added output callback for i24 * added input callback i24 * minor cleanup * added i24 to examples * avoided allocations in callback
1 parent f434967 commit 33b8919

File tree

6 files changed

+325
-64
lines changed

6 files changed

+325
-64
lines changed

examples/android.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate cpal;
55

66
use cpal::{
77
traits::{DeviceTrait, HostTrait, StreamTrait},
8-
SizedSample,
8+
SizedSample, I24,
99
};
1010
use cpal::{FromSample, Sample};
1111

@@ -22,7 +22,7 @@ fn main() {
2222
match config.sample_format() {
2323
cpal::SampleFormat::I8 => run::<i8>(&device, &config.into()).unwrap(),
2424
cpal::SampleFormat::I16 => run::<i16>(&device, &config.into()).unwrap(),
25-
// cpal::SampleFormat::I24 => run::<I24>(&device, &config.into()).unwrap(),
25+
cpal::SampleFormat::I24 => run::<I24>(&device, &config.into()).unwrap(),
2626
cpal::SampleFormat::I32 => run::<i32>(&device, &config.into()).unwrap(),
2727
// cpal::SampleFormat::I48 => run::<I48>(&device, &config.into()).unwrap(),
2828
cpal::SampleFormat::I64 => run::<i64>(&device, &config.into()).unwrap(),

examples/beep.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::Parser;
22
use cpal::{
33
traits::{DeviceTrait, HostTrait, StreamTrait},
4-
FromSample, Sample, SizedSample,
4+
FromSample, Sample, SizedSample, I24,
55
};
66

77
#[derive(Parser, Debug)]
@@ -78,7 +78,7 @@ fn main() -> anyhow::Result<()> {
7878
match config.sample_format() {
7979
cpal::SampleFormat::I8 => run::<i8>(&device, &config.into()),
8080
cpal::SampleFormat::I16 => run::<i16>(&device, &config.into()),
81-
// cpal::SampleFormat::I24 => run::<I24>(&device, &config.into()),
81+
cpal::SampleFormat::I24 => run::<I24>(&device, &config.into()),
8282
cpal::SampleFormat::I32 => run::<i32>(&device, &config.into()),
8383
// cpal::SampleFormat::I48 => run::<I48>(&device, &config.into()),
8484
cpal::SampleFormat::I64 => run::<i64>(&device, &config.into()),

examples/synth_tones.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern crate cpal;
88

99
use cpal::{
1010
traits::{DeviceTrait, HostTrait, StreamTrait},
11-
SizedSample,
11+
SizedSample, I24,
1212
};
1313
use cpal::{FromSample, Sample};
1414

@@ -98,6 +98,7 @@ where
9898
match config.sample_format() {
9999
cpal::SampleFormat::I8 => make_stream::<i8>(&device, &config.into()),
100100
cpal::SampleFormat::I16 => make_stream::<i16>(&device, &config.into()),
101+
cpal::SampleFormat::I24 => make_stream::<I24>(&device, &config.into()),
101102
cpal::SampleFormat::I32 => make_stream::<i32>(&device, &config.into()),
102103
cpal::SampleFormat::I64 => make_stream::<i64>(&device, &config.into()),
103104
cpal::SampleFormat::U8 => make_stream::<u8>(&device, &config.into()),

src/host/asio/device.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,14 @@ pub(crate) fn convert_data_type(ty: &sys::AsioSampleType) -> Option<SampleFormat
209209
let fmt = match *ty {
210210
sys::AsioSampleType::ASIOSTInt16MSB => SampleFormat::I16,
211211
sys::AsioSampleType::ASIOSTInt16LSB => SampleFormat::I16,
212-
sys::AsioSampleType::ASIOSTFloat32MSB => SampleFormat::F32,
213-
sys::AsioSampleType::ASIOSTFloat32LSB => SampleFormat::F32,
212+
sys::AsioSampleType::ASIOSTInt24MSB => SampleFormat::I24,
213+
sys::AsioSampleType::ASIOSTInt24LSB => SampleFormat::I24,
214214
sys::AsioSampleType::ASIOSTInt32MSB => SampleFormat::I32,
215215
sys::AsioSampleType::ASIOSTInt32LSB => SampleFormat::I32,
216+
sys::AsioSampleType::ASIOSTFloat32MSB => SampleFormat::F32,
217+
sys::AsioSampleType::ASIOSTFloat32LSB => SampleFormat::F32,
218+
sys::AsioSampleType::ASIOSTFloat64MSB => SampleFormat::F64,
219+
sys::AsioSampleType::ASIOSTFloat64LSB => SampleFormat::F64,
216220
_ => return None,
217221
};
218222
Some(fmt)

0 commit comments

Comments
 (0)