Commit Graph

415 Commits

Author SHA1 Message Date
mitchmindtree e7979d2dfe Fix some strangely formatted commented code 2020-01-21 00:15:52 +01:00
mitchmindtree aab0d90add Remove old `.rustfmt.toml` config. Run default `cargo fmt` on repo.
Seeing as a few large refactors have landed recently, I thought I'd take
this opportunity to do a `cargo fmt` run and standardise on the default
rustfmt settings.
2020-01-20 20:35:23 +01:00
mitchmindtree a7008b63a5 Address deprecated `mem::uninitialized` warnings in WASAPI host
This uses `ptr::null_mut()` and `MaybeUninit` to remove use of
deprecated `mem::uninitialized()` which could possibly result in UB.
2020-01-20 20:22:15 +01:00
mitchmindtree 64f8fd12cc Update CoreAudio host for the addition of the new stream `Data` type 2020-01-19 19:42:43 +01:00
mitchmindtree c0a28b5198 Update ASIO host for addition of new stream `Data` type. 2020-01-19 19:35:35 +01:00
mitchmindtree 1b5cf579cb Update WASAPI backend for addition of new stream `Data` type 2020-01-19 19:17:40 +01:00
mitchmindtree dbb1cc4140 Add some notes for devs about the safety requirements of `Data` 2020-01-19 19:05:17 +01:00
mitchmindtree 3fdf189848 Update docs for addition of the new stream Data type 2020-01-19 16:16:09 +01:00
mitchmindtree 7f27b897bb Update emscripten backend for new stream Data type 2020-01-19 16:04:06 +01:00
mitchmindtree 58356f49b4 An alternative approach to removing `UnknownBufferType`.
This is a potential alternative to #359. This PR is based on #359.

This approach opts for a dynamically checked sample type approach with
the aim of minimising compile time and binary size.

You can read more discussion on this [here](https://github.com/RustAudio/cpal/pull/359#issuecomment-575931461)

Implemented backends:

- [x] null
- [x] ALSA
- [ ] CoreAudio
- [ ] WASAPI
- [ ] ASIO
- [ ] Emscripten
2020-01-19 15:06:19 +01:00
mitchmindtree 6fbb701826 Update CoreAudio backend for removal of `UnknownBufferType` 2020-01-18 15:15:41 +01:00
mitchmindtree 9e832c6eb3 Update ASIO backend for removal of `UnknownBufferType` 2020-01-18 15:13:17 +01:00
mitchmindtree b5bfb8d422 Update WASAPI backend for removal of `UnknownTypeBuffer` 2020-01-18 15:13:17 +01:00
mitchmindtree 5a619877f9 Update docs for removal of UnknownTypeBuffer 2020-01-18 15:13:17 +01:00
mitchmindtree 6fc2185c99 Update emscripten backend for removal of `UnknownTypeBuffer` 2020-01-18 15:13:17 +01:00
mitchmindtree 05b62bb1c0 Remove `UnknownTypeBuffer` in favour of specifying sample type.
This is an implementation of the planned changes described in #119.

For a quick overview of how the API has changed, check out the updated
examples.

**TODO:**

- [x] Update API.
- [x] Update examples.
- [ ] Remove `data_type` field from `Format` (see [here](https://github.com/RustAudio/cpal/issues/119#issuecomment-573788380)).
- Update backends:
  - [x] null
  - [x] ALSA
  - [ ] ASIO
  - [ ] WASAPI
  - [ ] CoreAudio
  - [ ] Emscripten

Closes #119
Closes #260
2020-01-18 15:13:17 +01:00
Alex Moon 1b10f92f9d Fix undeclared module errors on Mac. 2020-01-16 12:24:33 -08:00
mitchmindtree 2bf905f3ec
Merge pull request #358 from jbeich/dragonfly
DragonFly support
2020-01-13 15:47:45 +01:00
mitchmindtree 32d39bcfd3 Relax `Sync` restriction on `Device` and `Host`
Originally this restriction was placed due to uncertainty around the
thread safety of the ASIO API. While the ASIO API itself makes no
thread-safety guarantees that we are aware of, the `asio-sys` high-level
bindings enforce synchronised access to the API and state transitions
via a mutex.
2020-01-12 22:43:05 +01:00
Jan Beich 3ac6f6a689 Enable ALSA on DragonFly
DragonFly like FreeBSD uses OSS under the hood but OSS backend isn't
available, so use ALSA.
2020-01-07 16:18:52 +00:00
mitchmindtree 33ddf74954 Explicitly make dynamically dispatched API !Send + !Sync
This is in order to ensure consistent restrictions across platforms in a
manner that ensures thread safety across each of the supported
platforms.

Please see added comments in the diff for details on which platforms
impose these restrictions.
2020-01-05 17:43:14 +01:00
mitchmindtree 2afebb2806 Clarify the current state of stream behaviour in docs and comments 2019-12-31 16:02:08 +01:00
mitchmindtree 39ade49347 RAII cleanup wthin the ASIO backend
- Shares the `Device`'s `driver` and `asio_streams` `Arc`s with the
`Stream`s to ensure they remain valid if the `Host` or `Device` are
dropped early.
- Ensures that a stream's callback is removed upon `Drop`.
2019-12-31 15:46:10 +01:00
msiglreith 972cce0f8c asio: Re-add possibility to create stream individually 2019-12-31 15:46:10 +01:00
msiglreith bfda575218 Port ASIO host to new stream-based API 2019-12-31 15:46:10 +01:00
Viktor Lazarev 64ba84de81 Move code from stream to device 2019-12-31 15:46:10 +01:00
mitchmindtree f34a062fac Update docs for removal of the `EventLoop` 2019-12-31 15:46:10 +01:00
mitchmindtree 27245444a7 Remove redundant from backend 2019-12-31 15:45:15 +01:00
mitchmindtree 37d80b98cf Update the `emscripten` backend for the removal of the `EventLoop`
For the most part, behaviour should be largely unchanged, however each
individual stream now has its own `set_timeout` callback loop, rather
than using one for processing all streams at once.

Many TODOs remain within the `emscripten` backend. These were left
untouched for the most part in favour of addressing this in a more
web-focused, future PR.
2019-12-31 15:45:15 +01:00
Tatsuyuki Ishi 70dcf2390a Port CoreAudio backend 2019-12-31 15:45:15 +01:00
ishitatsuyuki c09a58ac02 Fix the remainder of WASAPI backend 2019-12-31 15:42:35 +01:00
Tatsuyuki Ishi 7f7914434c Additional clippy fixes 2019-12-31 15:42:35 +01:00
Viktor Lazarev d46415a6e7 `cargo clippy` 2019-12-31 15:42:35 +01:00
Tatsuyuki Ishi 49a38c2641 Fix up WASAPI host 2019-12-31 15:42:35 +01:00
Viktor Lazarev d4965d3673 `cargo fmt` 2019-12-31 15:42:35 +01:00
Viktor Lazarev c62cb48e19 Apply suggestions proposed by Clippy 2019-12-31 15:42:35 +01:00
Viktor Lazarev 10dc779943 Return back missed play/pause implementation 2019-12-31 15:42:35 +01:00
Viktor Lazarev a218dc90e6 Fixing compile errors 2019-12-31 15:42:35 +01:00
Viktor Lazarev a412b00336 Fix the "Stream::new' method 2019-12-31 15:42:35 +01:00
Viktor Lazarev e7f708701c Remove old code 2019-12-31 15:42:35 +01:00
Viktor Lazarev 1021141d16 Fix "build_input/output_stream_inner" methods 2019-12-31 15:42:35 +01:00
Viktor Lazarev f65d0e65bc Expose Stream instead of StreamId 2019-12-31 15:42:35 +01:00
Viktor Lazarev 125bebd733 Clean up wasdapi mod 2019-12-31 15:42:35 +01:00
Viktor Lazarev d12d9f479b Remove redundant field names 2019-12-31 15:42:35 +01:00
Viktor Lazarev 7765e941ed Implement Drop for Stream 2019-12-31 15:42:35 +01:00
Viktor Lazarev 0541bf8667 Add Stream struct 2019-12-31 15:42:35 +01:00
Viktor Lazarev e25c44a4a1 Move code from stream to device 2019-12-31 15:42:35 +01:00
Viktor Lazarev dd418c08ae Adjust "process_commands" and "Command" 2019-12-31 15:42:35 +01:00
Viktor Lazarev 28cf3fee43 Fix "run_inner" fn 2019-12-31 15:42:35 +01:00
Viktor Lazarev b00630bdcc Extract "run_inner" as a standalone function 2019-12-31 15:42:35 +01:00
Viktor Lazarev 463540f370 Keep a single stream only 2019-12-31 15:42:35 +01:00
Viktor Lazarev cffd2da582 Rename "StreamDataResult" to "StreamData" 2019-12-31 15:42:35 +01:00
Viktor Lazarev 37e7b5b63b Move DeviceTrait implementation to wasapi::device 2019-12-31 15:42:35 +01:00
Tatsuyuki Ishi e782ca1ac8 Suppress warnings in null backend 2019-12-31 15:42:35 +01:00
Tatsuyuki Ishi 508e7d8ccf Add one missing error handling 2019-12-31 15:42:35 +01:00
Tatsuyuki Ishi 3cce3e43d9 Change callback interface so that it takes a dedicated error callback 2019-12-31 15:42:35 +01:00
Tatsuyuki Ishi c97d1dd3fa Remove EventLoop and port the ALSA backend 2019-12-31 15:42:35 +01:00
Sebastian Imlay d8743b34ce Fixed compiler warnings
* Removed extra semi-colon
* Added dyn where requested
* Removed ::std:: in thead::sleep call.
2019-12-29 15:02:34 -08:00
Ryan Adolf 264cd31b03 Update struct links in crate documentation 2019-12-22 19:22:35 -08:00
est31 90be524400
Merge pull request #339 from lucy/master
Implement WASAPI loopback support
2019-11-17 17:49:49 +01:00
lucy dcabad105b Implement WASAPI loopback support
This works by detecting output devices in build_input_stream() and
setting the AUDCLNT_STREAMFLAGS_LOOPBACK flag to enable loopback
recording.

closes #251
2019-10-27 14:52:12 +01:00
mitchmindtree d9d4a906c9 Switch to dtolnay's `thiserror` for handling error boilerplate
Currently CPAL only really uses `failure` for its `derive` capabilities
and the ability to easily generate implementations for `Display`. That
said there are a few issues with using the `failure` crate:

- `failure` does not provie a `std::error::Error` implementation without
  first converting error types into `failure::Error`.
- It leaks significantly into the public API and expects downstream
  users to also depend on `failure` and the non-std `Fail` trait for
  their own error handling.
- Solved problems such as downcasting of causal errors which have since
  been addressed in `std`.
- Provides application-friendly `Fail` trait and `failure::Error` type,
  not particularly useful to libraries like CPAL.

The [`thiserror` crate](https://github.com/dtolnay/thiserror) is better
targeted towards libraries, does not leak into the public API while
providing easy generation of `Display`, `From` and `std::error::Error`
implementations including proper handling of the newish
`std::error::Error::source` method.
2019-10-13 12:29:21 +02:00
Luni-4 8234df7f3d Fix clippy 2019-10-04 11:54:11 +02:00
Tatsuyuki Ishi 43450a6dec
Move errors into separate module (#332)
Move errors into separate module
2019-10-01 11:10:02 +09:00
msiglreith edc365f708 Move error into separate module 2019-09-29 14:05:06 +02:00
Alex Butler b1228fc3ff
Alsa: Set buffer size near to 100ms 2019-08-31 13:33:57 +01:00
Tatsuyuki Ishi a5783d14c5 Use snd_pcm_avail_update 2019-08-24 12:32:19 +09:00
est31 447ad5d727
Merge pull request #321 from RustAudio/wasapi-capture
Fix WASAPI capture logic
2019-08-14 00:42:08 +02:00
ishitatsuyuki e9043c605a Fix WASAPI capture logic
The buffer size handling differs from what render streams uses. Logic is based on https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/WindowsAudioSession/cpp/WASAPICapture.cpp.
2019-08-12 10:56:14 +09:00
mitchmindtree d3fdb2dd4b
Merge pull request #307 from derekdreery/relax_buffer_size
Remove the (arbitary) restriction on buffer size
2019-08-10 20:10:24 +02:00
est31 624ca7624f
Update mod.rs (#314)
Fixes #309
2019-08-10 16:42:47 +02:00
est31 14c1258a57 Remove uninitalized from coreaudio backend
uninitialized is being deprecated in favour of
MaybeUninit and friends.

In fact, using mem::zeroed() here is the
initialization method that apple docs recommend.

https://developer.apple.com/documentation/coreaudiotypes/audiostreambasicdescription
2019-08-10 15:40:34 +02:00
est31 268ea6cfbf Remove mem::uninitialized from alsa backend
uninitialized is being deprecated in favour of
MaybeUninit and friends.
2019-08-10 15:08:21 +02:00
Richard Dodd (dodj) 684aa6392a
Update mod.rs
Fixes #309
2019-08-04 11:49:15 +01:00
Richard Dodd 1c34dd682e Remove code rather than comment out 2019-07-27 16:41:19 +01:00
Richard Dodd b7d230150c Remove the (arbitary) restriction on buffer size 2019-07-24 20:43:20 +01:00
mitchmindtree 68bccdb325
Merge pull request #304 from ishitatsuyuki/host-name
Add name to HostId
2019-07-18 15:17:31 +02:00
Tatsuyuki Ishi 984ff0fd30 Add name to HostId 2019-07-18 09:46:50 +09:00
Tatsuyuki Ishi 447300101d Small tweak for ALSA underruns
The hardcoded errno was replaced by a constant, and `snd_pcm_prepare` was replaced by `snd_pcm_recover` per best practice (the underlying implementation seems same for now, though).
2019-07-07 19:42:08 +09:00
mitchmindtree 6cd7492f4c Add missing `Hash` constraint to `StreamId`
This existed prior to the introduction of the `Host` API, but was lost
in translation. This re-adds the bounds so that downstream code does not
suddenly break due to a lacking `Hash` implementation in the next
CPAL version.
2019-07-05 19:28:34 +02:00
mitchmindtree 6245dd899c Add some missing re-exports from the platform module into the crate root 2019-07-05 19:20:30 +02:00
mitchmindtree 714dab7270 Refactor asio message to use a match expr. Fix some typos. 2019-07-05 13:19:42 +02:00
mitchmindtree 64dc6accf9 Rebase for the trait refactor in #295. 2019-07-05 06:03:33 +10:00
mitchmindtree cc5b0555c2 Refactor of asio-sys while reviewing for code correctness
Most of this is an attempt at improving readability and modularity of
the asio-sys crate while attempting to review it for correctness. Still
unsure why glitching is occasionally occuring on output, but recorded
input sounds perfectly clean.
2019-07-05 05:51:31 +10:00
mitchmindtree 9182f00e20 Check that sample format is supported by ASIO when building streams 2019-07-05 05:51:31 +10:00
mitchmindtree c432f2b18d Update asio-sys to allow for having multiple handles to the same driver
ASIO has a limitation where it only supports loading a single audio
driver at a time. This fixes a common error where CPAL users would
request both the default input device and output device in separate
`load_driver` calls. Now, `load_driver` will return another handle to
the existing driver if the existing driver has the same name.
2019-07-05 05:51:31 +10:00
mitchmindtree 7d0f9c7265 Remove unreachable_patterns gate onto relevant fns so all platforms benefit 2019-07-05 05:51:31 +10:00
mitchmindtree 8f95042b8d Add `asio` cargo feature for optional ASIO support
ASIO introduces quite a few extra crates and requires a fairly
complicated setup process (see the readme), so this feature is disabled
by default.
2019-07-05 05:51:30 +10:00
mitchmindtree 191b90909a Make Driver type responsible for managing user callbacks 2019-07-05 05:51:30 +10:00
mitchmindtree 4dafb212fb Refactor build_input_stream callback to, like recent output refactor 2019-07-05 05:51:30 +10:00
mitchmindtree cc70a10c12 Remove unused supported_formats_err function 2019-07-05 05:51:29 +10:00
mitchmindtree dc6c5c5a7c Remove unnecessary asio_utils mod 2019-07-05 05:51:29 +10:00
mitchmindtree 50aa0585be Remove unwieldy macro from output stream callback
Instead, we use some traits and generics in an attempt to retain a
little readability. See the remaining TODOs in this section for required
future work.
2019-07-05 05:51:29 +10:00
mitchmindtree d739a5b79d Majority of ASIO host update following refactor
Currently not compiling - still need to address some global items within
asio-sys, including the `set_callback` function and the double buffer
globals.
2019-07-05 05:51:29 +10:00
mitchmindtree 05f8b7dc43 Fix remaining compile errors for ASIO host
Now runs the beep and enumerate examples nicely! Time to do a proper
code review of the ASIO stuff and see how to best take advantage of the
new `Host` API.
2019-07-05 05:51:28 +10:00
mitchmindtree 09fd5562be Update ASIO implementation for new error handling and Host API
This is currently untested and will almost certainly not build. I'm
about to move into a Windows VM to get everything running properly
again.
2019-07-05 05:51:28 +10:00
mitchmindtree 2bc9f85970 Update supported_formats methods for all sample rates and channel combos
Closes #32.
2019-07-05 05:51:28 +10:00
Tom Gowan bc94d167ae fix endianess 2019-07-05 05:51:28 +10:00
Tom Gowan f2c8099810 bug fix and comment 2019-07-05 05:51:27 +10:00
Tom Gowan 5eb311d8be float conversion fix 2019-07-05 05:51:27 +10:00