Commit Graph

330 Commits

Author SHA1 Message Date
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
Tom Gowan a3defde208 Checks formats 2019-07-05 05:51:27 +10:00
Tom Gowan c255da24bf stream id bug 2019-07-05 05:51:27 +10:00
Tom Gowan fd808b95e9 indentation and no clean up on destroy stream 2019-07-05 05:51:27 +10:00
Tom Gowan ab3b76ad75 fixes, remove transmute 2019-07-05 05:51:26 +10:00
Tom Gowan 7950045240 minor fixes 2019-07-05 05:51:26 +10:00
Tom Gowan 25070464f9 git ignore, temp files, fetch_add, os cfg 2019-07-05 05:51:26 +10:00
Tom Gowan 523d25ad49 remove u16 2019-07-05 05:51:26 +10:00
Tom Gowan 616974353b opt in and bug fix 2019-07-05 05:51:26 +10:00
Tom Gowan 1f24c76e6a commenting and rustfmt for device 2019-07-05 05:51:26 +10:00
Tom Gowan 5248455cb7 commets and rustfmt for stream 2019-07-05 05:51:25 +10:00
Tom Gowan ffcbc02e52 multi channels 2019-07-05 05:51:25 +10:00
Tom Gowan 6e0eb073d1 sample rate support 2019-07-05 05:51:25 +10:00
Tom Gowan b0b0484d4b endian conversion 2019-07-05 05:51:25 +10:00
Tom Gowan 5ec6da3aad Fixed driver bug 2019-07-05 05:51:24 +10:00
Tom Gowan 6a71f0a801 choose backend 2019-07-05 05:51:24 +10:00
Tom Gowan 91f2edb277 utils as mod 2019-07-05 05:51:24 +10:00
Tom Gowan ed50bb9923 adding outputs 2019-07-05 05:51:24 +10:00
Tom Gowan ff7fd62a2d clean up 2019-07-05 05:51:24 +10:00
Tom Gowan 93f75940d6 fixed offset bug 2019-07-05 05:51:24 +10:00
Tom Gowan 8193bc9f79 sharing asio streams 2019-07-05 05:51:24 +10:00
Tom Gowan 76eb07a274 Multiple streams 2019-07-05 05:51:23 +10:00
Tom Gowan 4ba291e8be multi channel support 2019-07-05 05:51:23 +10:00
Tom Gowan ae7a03d788 Device rewrite Fixes #1 Fixes #12 2019-07-05 05:51:23 +10:00
Tom Gowan 056630cca3 removed allocation from output 2019-07-05 05:51:23 +10:00
Tom Gowan 910e0ba351 working record wav 2019-07-05 05:51:22 +10:00
Tom Gowan d430000d2c beep working 2019-07-05 05:51:22 +10:00
Tom Gowan 8d5cb951d8 asio_utils 2019-07-05 05:51:22 +10:00
Tom Gowan 9c355f5579 fixed buffer 2019-07-05 05:51:22 +10:00
DMSDeveloper c8c00793c0 attemp at removing buffer 2 2019-07-05 05:51:22 +10:00
DMSDeveloper ab7e17558f attemp at removing buffer 2019-07-05 05:51:22 +10:00
DMSDeveloper 9a084347db removed itertools 2019-07-05 05:51:21 +10:00
DMSDeveloper 892024f5d8 minor fixes 2 2019-07-05 05:51:21 +10:00
DMSDeveloper a1740a9282 record wav working v1 2019-07-05 05:51:21 +10:00
DMSDeveloper fe4d108477 minor fixes 2019-07-05 05:51:21 +10:00
DMSDeveloper c978583863 recording v1 2019-07-05 05:51:21 +10:00
DMSDeveloper 2cfd60757a working on windows 2019-07-05 05:51:21 +10:00
Tom Gowan 49968f4b82 change of branch 2019-07-05 05:51:21 +10:00
mitchmindtree 5e4f384992 Refactor `Host` and related traits into a new `traits` module
This is a draft implementation of #294. I'll leave this open for
feedback and potentially better trait naming suggestions or better
solutions in general!

cc @ishitatsuyuki
2019-06-29 14:45:15 +02:00
mitchmindtree 3603cbaee7 Remove macOS sleep loop in favour of using `Condvar`
This solution was originally posted by @HybridEidolon in #185. Sorry it
took so long! I thought it might be easier to open a new PR as half of
your implementation here has already been implemented in a following PR
(namely, the change from an unnecessary `Vec` of callbacks to a single
user callback).

Closes #185.
2019-06-25 17:38:54 +02:00
mitchmindtree 51eba20c44 Remove DefaultHost type in favour of determining at runtime
Re-exports host-specific types so that they are available within the
platform module if necessary (e.g. host::asla::Host as AlsaHost).

Allows for converting platform-specific host types (e.g. AlsaHost) into
the dynamically dispatched type generated for the target platform
(`Host`).
2019-06-25 16:54:50 +02:00
mitchmindtree 283a73054e Address some nits highlighted by ishitatsuyuki 2019-06-25 16:26:27 +02:00
mitchmindtree e131979d22 Update README for addition of host enumeration API 2019-06-25 00:39:51 +02:00
mitchmindtree 6e9b40e225 Minimize compiler flags by using nested platform_impl mods
Also addresses some other CI errors:

- Add Host::new constructor for null backend
- Add missing DevicesError import to coreaudio backend
2019-06-24 23:22:37 +02:00
mitchmindtree f7cf0c65b8 Implement `Host` API for coreaudio backend 2019-06-24 22:44:57 +02:00
mitchmindtree 6b6830ab57 Implement `Host` API for emscripten backend 2019-06-24 22:38:48 +02:00
mitchmindtree 69cd058d28 Implement new `Host` API for WASAPI backend 2019-06-24 22:21:19 +02:00
mitchmindtree e8a05379c2 [WIP] Introduce a `Host` API
This is an implementation of the API described at #204. Please see that
issue for more details on the motivation.

-----

A **Host** provides access to the available audio devices on the system.
Some platforms have more than one host available, e.g.
wasapi/asio/dsound on windows, alsa/pulse/jack on linux and so on. As a
result, some audio devices are only available on certain hosts, while
others are only available on other hosts. Every platform supported by
CPAL has at least one **DefaultHost** that is guaranteed to be available
(alsa, wasapi and coreaudio). Currently, the default hosts are the only
hosts supported by CPAL, however this will change as of landing #221 (cc
@freesig). These changes should also accommodate support for other hosts
such as jack #250 (cc @derekdreery) and pulseaudio (cc @knappador) #259.

This introduces a suite of traits allowing for both compile time and
runtime dispatch of different hosts and their uniquely associated device
and event loop types.

A new private **host** module has been added containing the individual
host implementations, each in their own submodule gated to the platforms
on which they are available.

A new **platform** module has been added containing platform-specific
items, including a dynamically dispatched host type that allows for
easily switching between hosts at runtime.

The **ALL_HOSTS** slice contains a **HostId** for each host supported on
the current platform. The **available_hosts** function produces a
**HostId** for each host that is currently *available* on the platform.
The **host_from_id** function allows for initialising a host from its
associated ID, failing with a **HostUnavailable** error. The
**default_host** function returns the default host and should never
fail.

Please see the examples for a demonstration of the change in usage. For
the most part, things look the same at the surface level, however the
role of device enumeration and creating the event loop have been moved
from global functions to host methods. The enumerate.rs example has been
updated to enumerate all devices for each host, not just the default.

**TODO**

- [x] Add the new **Host** API
- [x] Update examples for the new API.
- [x] ALSA host
- [ ] WASAPI host
- [ ] CoreAudio host
- [ ] Emscripten host **Follow-up PR**
- [ ] ASIO host #221

cc @ishitatsuyuki more to review for you if you're interested, but it
might be easier after #288 lands and this gets rebased.
2019-06-24 21:45:04 +02:00
mitchmindtree c72bafd8ab Update examples eprintln to more accurately reflect error 2019-06-24 21:13:07 +02:00
mitchmindtree c05d2916b1 Remove `StreamEvent` in favour of `StreamDataResult` 2019-06-24 20:43:27 +02:00
mitchmindtree 26f7e99e9b Remove all `Pause`, `Play` and `Close` events
A follow up to [this comment](https://github.com/tomaka/cpal/pull/288#issuecomment-504712574).
2019-06-23 19:04:24 +02:00
mitchmindtree b1539c534f Add handling of `Play`, `Pause` and `Close` stream events to emscripten 2019-06-22 17:47:31 +02:00
mitchmindtree b2c1226b47 Update coreaudio backend for `StreamEvent` API addition. 2019-06-22 17:14:42 +02:00
mitchmindtree fddea2edd8 Update the null and emscripten backends for StreamEvent API 2019-06-22 03:53:51 +02:00
mitchmindtree 3e3cf26cde Update `wasapi` backend for `StreamEvent` API addition.
Refactors much of the `EventLoop::run` implementation in order to make
error handling a little easier.
2019-06-22 03:47:05 +02:00
mitchmindtree e41baa248b Update alsa backend for addition of `StreamEvent` type
This commit significantly refactors the alsa backend's `EventLoop::run`
implementation in order to allow for better error handling throughout
the loop. This removes many cases that would previously `panic!` in
favour of calling the user callback with the necessary error and
removing the corrupt stream. Seeing as the method cannot return, a
catch-all `panic!` still exists at the end of the method, however this
refactor should make it much easier to remove this restriction in the
future.
2019-06-22 00:06:55 +02:00
mitchmindtree 59c789fbcd Add new `StreamEvent` type - enables more flexible user callback API
This adds the following types:

- `StreamEvent`
- `CloseStreamCause`
- `StreamError`

These allow for notifying the user of the following events:

- A stream has been played.
- A stream has been paused.
- A stream has been closed due to user destroying stream.
- A stream has been closed due to an error.
2019-06-22 00:02:57 +02:00
mitchmindtree 2667547a9c Update lib docs to allow for testing on devices with no audio 2019-06-21 15:57:15 +02:00
mitchmindtree 6164f83147 Fix compiler errors in wasapi backend after testing on windows 2019-06-21 23:32:00 +10:00
mitchmindtree a733bdb4f9 Fix compile errors on macOS 2019-06-21 03:11:20 +02:00
mitchmindtree eae0e18714 Add `PlayStreamError` and `PauseStreamError`.
This allows for properly handling potential failure on macOS. We should
also consider propagating the mutex/channel poison errors through these
new types, especially considering the potential removal of the event
loop in favour of switching over to high-priority audio threads on
windows and linux.
2019-06-21 03:04:15 +02:00
mitchmindtree ba8d354e93 Improve handling of `BuildStreamError` throughout crate. 2019-06-21 02:38:59 +02:00
mitchmindtree f0e4e312c1 Improve handling of the `DefaultFormatError` 2019-06-21 01:38:21 +02:00
mitchmindtree 105086a108 Add new `DeviceNameError` type
The coreaudio and wasapi backends may both potentially fail to produce
the name associated with a device. This changes the API to allow for
returning the errors in these cases.
2019-06-21 00:58:15 +02:00
mitchmindtree 78a7cb9e79 Change `SupportedFormatsError::Unknown` variant to `BackendSpecific`
This allows for also passing through a description of the
unknown/platform-specific error.
2019-06-21 00:55:27 +02:00
mitchmindtree 42fc702f53 Add `BackendSpecificError`. Add new `DevicesError`.
See the documentation for both new errors for details.

The new `DevicesError` has been added to allow for returning errors when
enumerating devices. This has allowed to remove multiple potential
`panic!`s in each of the alsa, coreaudio and wasapi backends.
2019-06-20 22:37:36 +02:00
mitchmindtree cf84ab906f Rename `CreationError` to `BuildStreamError`
For clarity and to tie the name more closesly to the methods within from
which it may be returned.
2019-06-20 21:31:15 +02:00
mitchmindtree 0f27c1e0bb Rename `FormatsEnumerationError` to `SupportedFormatsError`
This more tightly associates the error with the device method on which
this might occur.
2019-06-20 21:16:39 +02:00
mitchmindtree 1275db805b Remove std `Error` implementations in favour of using `failure`
This will make adding new errors in the following commits towards better
error handling a lot easier.
2019-06-20 21:12:17 +02:00
Tatsuyuki Ishi 1d3754fa7d Use channels instead of mutex 2019-06-13 15:31:37 +09:00
mitchmindtree 960b1d5a40 Remove unnecessary panic! from OutputBuffer Deref impl
Since #269 this `panic!` is certainly unnecessary as `InputBuffer` and
`OutputBuffer` are a thin wrapper around a slice. That said, I'm
struggling to understand exactly why this `panic!` was necessary in the
first place.

This closes #228.
2019-06-07 21:05:14 +02:00
mitchmindtree d0cafd68bf
Merge pull request #276 from AustinJ235/master
Release 0.9.0
2019-06-07 15:39:52 +02:00
mitchmindtree 48e1a96e60
Merge pull request #244 from azyobuzin/WasapiBufferEmpty
Assertion failed in Windows
2019-06-06 15:24:24 +02:00
Austin Johnson 78adc983f6 update hound & lazy_static; release 0.8.2 2019-06-06 00:49:49 -05:00
Louis Pearson e7c086d0af Return error from set_hw_params_from_format instead of crashing 2019-06-04 12:48:11 -06:00
mitchmindtree b82ca1e348
Merge pull request #235 from ArtemGr/master
Switching the headset on and off
2019-06-04 20:15:26 +02:00
mitchmindtree 72fd027f57
Merge pull request #269 from ishitatsuyuki/better-buffer
Better buffer handling
2019-06-04 19:51:45 +02:00
mitchmindtree 7861dd84da
Merge pull request #248 from RoflCopter24/master
Added error handling for unknown ALSA device errors
2019-05-30 23:56:43 +02:00
Tatsuyuki Ishi 4d3fe57fe3 Improved buffer management
- ALSA backend: reuse the buffers
- Make `InputBuffer` and `OutputBuffer` types just a wrapper of slice
  * Buffer is now submitted at the end of callback
2019-05-30 17:45:16 +09:00
Tatsuyuki Ishi af88cd87e2 Fix #254, logic error in frame/sample size 2019-04-29 20:33:03 +09:00
Simon Repp c2c7089d1a
Minor textual corrections in crate documentation intro 2019-04-22 13:55:42 +02:00
Chris Morgan 2679ea845f impl Debug for Device (#253)
The internal alsa, null and emscripten Device implementations already
implemented Debug; but the coreaudio and wasapi ones, and therefore
also the wrapper, did not.

I decided to eschew the `Device(…)` wrapping in the outer layer
(hence a custom implementation rather than `#[derive(Debug)]`),
because `Device(Device)`, `Device(Device { … })` and so forth all
look better without the extra `Device(…)` wrapping.

On the wasapi and coreaudio implementations I put both the pointer and
name. Name because it’s useful, pointer because on Windows at least
I believe duplicated names are possible. (e.g. two monitors that include
monitors, of the same type; I haven’t strictly confirmed this, because I
killed those off harshly on my machine and don’t want to reinstate
them.)

I do not have access to a macOS device to confirm that the coreaudio
implementation is sane, but I think it is.
2019-03-22 21:27:17 +01:00
Florian Vick 5cb45bfd7e
Added error handling for unknown ALSA device errors (#1)
Instead of taking the easy way out and killing the whole program by panicking, device enumeration and stream creation will now report the error variant 'Unknown'
2018-11-06 21:01:03 +01:00
azyobuzin 8a002b7077 Fix failing the assertion when HRESULT is AUDCLNT_S_BUFFER_EMPTY 2018-10-12 12:12:05 +09:00
Andre-Philippe Paquet 1a3a8956e4 WASPI - Fix stream start after destroy (#241)
* waspi - Fix stream start after destroy

* Fix stream name
2018-09-12 13:13:13 +02:00
Artem 71a5a43e33 Come to think of it, changing comparison logic unexpectedly is a bad idea. 2018-07-14 16:22:56 +02:00