Commit Graph

22 Commits

Author SHA1 Message Date
mitchmindtree bcf962c447 Add a `CallbackInfo` argument to the stream data callback
I began on an implementation of the timestamp API described in #363 but
quickly realised that it might be best to land the API for providing
extra information to the user's callback first.

This PR adds two new types: `InputCallbackInfo` and `OutputCallbackInfo`.
These types are delivered to the user's data callback as a new, second
argument.

While these types are currently empty, the intention is for these types
to provide information relevant to the current request for or delivery
of data. This includes:

- Timestamp information #363.
- Flags related to the state of the stream (e.g buffer
  underflow/overflow).

In order to maintain flexibility to avoid breaking things, I figure we
can keep the fields of these types private and provide methods for
retrieving this info.

@Ralith, @ishitatsuyuki does this seem OK to you?
2020-04-16 14:50:36 +02:00
mitchmindtree 9c781bd381 Rename stream `Format` types to `Config`
This implements the changes described at #370.

This commit implements only the `null` and `alsa` backends - the rest
will be implemented in follow-up commits.

Closes #370.
2020-01-27 21:28:07 +01:00
Benjamin Saunders 076b814a15 Introduce polymorphic stream constructors 2020-01-21 22:20:26 -08:00
Benjamin Saunders 78df791377 Add _raw suffix to stream constructors 2020-01-21 21:52:18 -08: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 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 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
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
mitchmindtree 7b08cb0dae Update examples for switch to `thiserror`
To compensate for the removal of `failure`'s application friendly
`failure::Error` trait, this `anyhow` crate has been added as a
dev-dependency for the examples, but is by no means a necessity for
other crates downstream of CPAL.
2019-10-13 12:36:49 +02:00
Mitchell Hentges 1676bf20b6
Adds comment about latency-push unwrap() 2019-09-27 10:18:23 -07:00
Mitchell Hentges 624d1f8ce6
Uses ringbuffer in feedback example 2019-09-26 17:19:12 -07: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 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 39cd5d0084 Update examples for addition of new StreamEvent API 2019-06-22 00:10:40 +02:00
mitchmindtree 0b6e66d38e Update examples to use std Termination 2019-06-21 14:55:21 +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 fbb97f51ef Update examples for DeviceNameError 2019-06-21 01:37:55 +02:00
Mohanson 6ceb3a215f
Update feedback.rs 2019-06-19 10:34:12 +08:00
mitchmindtree c20978fc01 Add an example that demonstrates feeding input directly to output with some latency 2018-02-17 15:33:00 +11:00