Skip to content

Commit ce57c56

Browse files
committed
Merge remote-tracking branch 'upstream/master' into aaron/openbsd_sndio_host
2 parents d419f0f + 1d72ae7 commit ce57c56

39 files changed

+2792
-1010
lines changed

.github/workflows/cpal.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: cpal
33
on: [push, pull_request]
44

55
jobs:
6+
67
clippy-test:
78
runs-on: ubuntu-latest
89
steps:
@@ -98,6 +99,51 @@ jobs:
9899
command: test
99100
args: --all --all-features --verbose
100101

102+
linux-check-and-test-armv7:
103+
runs-on: ubuntu-latest
104+
steps:
105+
- name: Checkout sources
106+
uses: actions/checkout@v2
107+
108+
- name: Install stable toolchain
109+
uses: actions-rs/toolchain@v1
110+
with:
111+
profile: minimal
112+
toolchain: stable
113+
target: armv7-unknown-linux-gnueabihf
114+
override: true
115+
116+
- name: Build image
117+
run: docker build -t cross/cpal_armv7:v1 ./
118+
119+
- name: Check without features for armv7
120+
uses: actions-rs/cargo@v1
121+
with:
122+
command: check
123+
use-cross: true
124+
args: --target armv7-unknown-linux-gnueabihf --workspace --no-default-features --verbose
125+
126+
- name: Test without features for armv7
127+
uses: actions-rs/cargo@v1
128+
with:
129+
command: test
130+
use-cross: true
131+
args: --target armv7-unknown-linux-gnueabihf --workspace --no-default-features --verbose
132+
133+
- name: Check all features for armv7
134+
uses: actions-rs/cargo@v1
135+
with:
136+
command: check
137+
use-cross: true
138+
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose
139+
140+
- name: Test all features for armv7
141+
uses: actions-rs/cargo@v1
142+
with:
143+
command: test
144+
use-cross: true
145+
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose
146+
101147
asmjs-wasm32-test:
102148
strategy:
103149
matrix:
@@ -216,6 +262,8 @@ jobs:
216262
toolchain: stable
217263
override: true
218264
target: armv7-linux-androideabi
265+
- name: Check android
266+
run: cargo check --example android --target armv7-linux-androideabi --verbose
219267
- name: Check beep
220268
run: cargo check --example beep --target armv7-linux-androideabi --verbose
221269
- name: Check enumerate
@@ -224,3 +272,38 @@ jobs:
224272
run: cargo check --example feedback --target armv7-linux-androideabi --verbose
225273
- name: Check record_wav
226274
run: cargo check --example record_wav --target armv7-linux-androideabi --verbose
275+
276+
android-apk-build:
277+
runs-on: ubuntu-latest
278+
steps:
279+
- uses: actions/checkout@v2
280+
- name: Install Android targets
281+
run: |
282+
rustup target add armv7-linux-androideabi
283+
rustup target add aarch64-linux-android
284+
rustup target add i686-linux-android
285+
rustup target add x86_64-linux-android
286+
- name: Install Cargo APK
287+
run: cargo install cargo-apk
288+
- name: Build APK
289+
run: cargo apk build --example android
290+
291+
ios-build:
292+
runs-on: macOS-latest
293+
steps:
294+
- uses: actions/checkout@v2
295+
- name: Install llvm and clang
296+
run: brew install llvm
297+
- name: Install stable
298+
uses: actions-rs/toolchain@v1
299+
with:
300+
profile: minimal
301+
toolchain: stable
302+
override: true
303+
- name: Add iOS targets
304+
run: rustup target add aarch64-apple-ios x86_64-apple-ios
305+
- name: Install cargo lipo
306+
run: cargo install cargo-lipo
307+
- name: Build iphonesimulator feedback example
308+
run: cd examples/ios-feedback && xcodebuild -scheme cpal-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator
309+

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Version 0.13.1 (2020-11-08)
2+
3+
- Don't panic when device is plugged out on Windows
4+
- Update `parking_lot` dependency
5+
6+
# Version 0.13.0 (2020-10-28)
7+
8+
- Add Android support via `oboe-rs`.
9+
- Add Android APK build an CI job.
10+
111
# Version 0.12.1 (2020-07-23)
212

313
- Bugfix release to get the asio feature working again.

Cargo.toml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cpal"
3-
version = "0.12.1"
3+
version = "0.13.1"
44
authors = ["The CPAL contributors", "Pierre Krieger <[email protected]>"]
55
description = "Low-level cross-platform audio I/O library in pure Rust."
66
repository = "https://github.com/rustaudio/cpal"
@@ -11,37 +11,43 @@ keywords = ["audio", "sound"]
1111
[features]
1212
asio = ["asio-sys", "num-traits"] # Only available on Windows. See README for setup instructions.
1313

14-
1514
[dependencies]
1615
thiserror = "1.0.2"
1716

1817
[dev-dependencies]
1918
anyhow = "1.0.12"
2019
hound = "3.4"
21-
ringbuf = "0.1.6"
20+
ringbuf = "0.2"
21+
clap = { version = "2.33.3", default-features = false }
2222

2323
[target.'cfg(target_os = "windows")'.dependencies]
2424
winapi = { version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "profileapi", "std", "synchapi", "winbase", "winuser"] }
2525
asio-sys = { version = "0.2", path = "asio-sys", optional = true }
2626
num-traits = { version = "0.2.6", optional = true }
27-
parking_lot = "0.9"
27+
parking_lot = "0.11"
2828
lazy_static = "1.3"
2929

3030
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))'.dependencies]
31-
alsa = "0.4.1"
31+
alsa = "0.4.3"
3232
nix = "0.15.0"
3333
libc = "0.2.65"
34+
parking_lot = "0.11"
3435
jack = { version = "0.6.5", optional = true }
3536

3637
[target.'cfg(target_os = "openbsd")'.dependencies]
3738
sndio-sys = "0.0.*"
3839
libc = "0.2.65"
3940

4041
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
41-
coreaudio-rs = { version = "0.9.1", default-features = false, features = ["audio_unit", "core_audio"] }
4242
core-foundation-sys = "0.6.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.
4343
mach = "0.3" # For access to mach_timebase type.
4444

45+
[target.'cfg(target_os = "macos")'.dependencies]
46+
coreaudio-rs = { version = "0.10.0", default-features = false, features = ["audio_unit", "core_audio"] }
47+
48+
[target.'cfg(target_os = "ios")'.dependencies]
49+
coreaudio-rs = { version = "0.10.0", default-features = false, features = ["audio_unit", "core_audio", "audio_toolbox"] }
50+
4551
[target.'cfg(target_os = "emscripten")'.dependencies]
4652
stdweb = { version = "0.1.3", default-features = false }
4753

@@ -51,7 +57,24 @@ js-sys = { version = "0.3.35" }
5157
web-sys = { version = "0.3.35", features = [ "AudioContext", "AudioContextOptions", "AudioBuffer", "AudioBufferSourceNode", "AudioNode", "AudioDestinationNode", "Window", "AudioContextState"] }
5258

5359
[target.'cfg(target_os = "android")'.dependencies]
54-
oboe = { version = "0.2.1", features = [ "java-interface" ] }
60+
oboe = { version = "0.3.0", features = [ "java-interface" ] }
5561
ndk = "0.2"
5662
ndk-glue = "0.2"
5763
jni = "0.17"
64+
65+
[[example]]
66+
name = "android"
67+
path = "examples/android.rs"
68+
crate-type = ["cdylib"]
69+
70+
[[example]]
71+
name = "beep"
72+
73+
[[example]]
74+
name = "enumerate"
75+
76+
[[example]]
77+
name = "feedback"
78+
79+
[[example]]
80+
name = "record_wav"

Cross.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[target.armv7-unknown-linux-gnueabihf]
2+
image = "cross/cpal_armv7:v1"
3+
4+
[target.armv7-unknown-linux-gnueabihf.env]
5+
passthrough = [
6+
"RUSTFLAGS",
7+
]

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM rustembedded/cross:armv7-unknown-linux-gnueabihf
2+
3+
ENV PKG_CONFIG_ALLOW_CROSS 1
4+
ENV PKG_CONFIG_PATH /usr/lib/arm-linux-gnueabihf/pkgconfig/
5+
6+
RUN dpkg --add-architecture armhf && \
7+
apt-get update && \
8+
apt-get install libasound2-dev:armhf -y && \
9+
apt-get install libjack-jackd2-dev:armhf libjack-jackd2-0:armhf -y \

examples/android.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#![allow(dead_code)]
2+
3+
extern crate anyhow;
4+
extern crate cpal;
5+
6+
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
7+
8+
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "full"))]
9+
fn main() {
10+
let host = cpal::default_host();
11+
12+
let device = host
13+
.default_output_device()
14+
.expect("failed to find output device");
15+
16+
let config = device.default_output_config().unwrap();
17+
18+
match config.sample_format() {
19+
cpal::SampleFormat::F32 => run::<f32>(&device, &config.into()).unwrap(),
20+
cpal::SampleFormat::I16 => run::<i16>(&device, &config.into()).unwrap(),
21+
cpal::SampleFormat::U16 => run::<u16>(&device, &config.into()).unwrap(),
22+
}
23+
}
24+
25+
fn run<T>(device: &cpal::Device, config: &cpal::StreamConfig) -> Result<(), anyhow::Error>
26+
where
27+
T: cpal::Sample,
28+
{
29+
let sample_rate = config.sample_rate.0 as f32;
30+
let channels = config.channels as usize;
31+
32+
// Produce a sinusoid of maximum amplitude.
33+
let mut sample_clock = 0f32;
34+
let mut next_value = move || {
35+
sample_clock = (sample_clock + 1.0) % sample_rate;
36+
(sample_clock * 440.0 * 2.0 * std::f32::consts::PI / sample_rate).sin()
37+
};
38+
39+
let err_fn = |err| eprintln!("an error occurred on stream: {}", err);
40+
41+
let stream = device.build_output_stream(
42+
config,
43+
move |data: &mut [T], _: &cpal::OutputCallbackInfo| {
44+
write_data(data, channels, &mut next_value)
45+
},
46+
err_fn,
47+
)?;
48+
stream.play()?;
49+
50+
std::thread::sleep(std::time::Duration::from_millis(1000));
51+
52+
Ok(())
53+
}
54+
55+
fn write_data<T>(output: &mut [T], channels: usize, next_sample: &mut dyn FnMut() -> f32)
56+
where
57+
T: cpal::Sample,
58+
{
59+
for frame in output.chunks_mut(channels) {
60+
let value: T = cpal::Sample::from::<f32>(&next_sample());
61+
for sample in frame.iter_mut() {
62+
*sample = value;
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)