Commit Graph

70 Commits

Author SHA1 Message Date
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 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
Tatsuyuki Ishi 1d3754fa7d Use channels instead of mutex 2019-06-13 15:31:37 +09:00
Louis Pearson e7c086d0af Return error from set_hw_params_from_format instead of crashing 2019-06-04 12:48:11 -06: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
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
mitchmindtree c38bbb26e4 Update to a more general Device and Stream API. Add support for input streams (E.g. microphone). Add default format methods. (#201)
* Update to a more general Device and Stream API

This update prepares for adding input stream support by removing the
`Endpoint` type (which only supports output streams) in favour of a more
general `Device` type which may support any number of input or output
streams. Previously discussed at #117.

The name `Voice` has been replaced with the more ubiquitous name
`Stream`. See #118 for justification.

Also introduces a new `StreamData` which is now passed to the
`EventLoop::run` callback rather than the `UnknownTypeBuffer`.
`StreamData` allows for passing either `Input` data to be read, or
`Output` data to be written.

The `beep.rs` example has been updated for the API changes.

None of the backends have been updated for this API change yet. Backends
will be updated in the following commits.

Closes #117.
Closes #118.

* Update ALSA backend for new `Device` and `Stream` API.

* Update wasapi backend for new `Device` and `Stream` API.

* Update enumerate.rs example for new `Device` and `Stream` API.

* Update coreaudio backend for new `Device` and `Stream` API.

* Fix lib doc tests for Device and Stream API update

* Update emscripten backend for new `Device` and `Stream` API.

* Update null backend for new `Device` and `Stream` API.

* Merge match exprs in beep.rs example

* Add Input variant along with UnknownTypeInputBuffer and InputBuffer

UnknownTypeBuffer and Buffer have been renamed to
UnknownTypeOutputBuffer and OutputBuffer respectively.

No backends have yet been updated for this name change or the addition
of the InputBuffer.

* Update null backend for introduction of InputBuffer

* Update emscripten backend for introduction of InputBuffer

* Make InputBuffer inner field an option to call finish in drop

* Update alsa backend for introduction of InputBuffer

* Update wasapi backend for introduction of InputBuffer

* Update coreaudio backend for introduction of InputBuffer

* Update enumerate.rs example to provide more detail about devices

The enumerate.rs example now also displays:

- Supported input stream formats.
- Default input stream format.
- Default output stream format.

This should also be useful for testing the progress of #201.

* Add `record_wav.rs` example for demonstrating input streams

Records a ~3 second WAV file to `$CARGO_MANIFEST_DIR/recorded.wav` using
the default input device and default input format.

Uses hound 3.0 to create and write to the WAV file.

This should also be useful for testing the input stream implementations
for each different cpal backend.

* Implement input stream support for coreaudio backend

This implements the following for the coreaudio backend:

- Device::supported_input_formats
- Device::default_input_format
- Device::default_output_format
- EventLoop::build_input_stream

The `enumerate.rs` and `record_wav.rs` examples now work successfully on
macos.

* Add `SupportedFormat::cmp_default_heuristics` method

This adds a comparison function which compares two `SupportedFormat`s in
terms of their priority of use as a default stream format.

Some backends (such as ALSA) do not provide a default stream format for
their audio devices. In these cases, CPAL attempts to decide on a
reasonable default format for the user. To do this we use the "greatest"
of all supported stream formats when compared with this method.

* Implement input stream support for ALSA backend

This implements the following for the ALSA backend:

- Device::supported_input_formats
- Device::default_input_format
- Device::default_output_format
- EventLoop::build_input_stream

Note that ALSA itself does not give default stream formats for its
devices. Thus the newly added `SupportedFormat::cmp_default_heuristics`
method is used to determine the most suitable, supported stream format
to use as the default.

The `enumerate.rs` and `record_wav.rs` examples now work successfully on
my linux machine.

* Implement input stream support for wasapi backend

This implements the following for the wasapi backend:

- Device::supported_input_formats
- Device::default_input_format
- Device::default_output_format
- EventLoop::build_input_stream

Note that wasapi does not enumerate supported input/output stream
formats for its devices. Instead, we query the `IsFormatSupported`
method for supported formats ourselves.

* Fix some warnings in the alsa backend

* Update CHANGELOG for introduction of input streams and related items

* Update README to show latest features supported by CPAL

* Simplify beep example using Device::default_output_format

* Remove old commented code from wasapi/stream.rs
2018-02-12 14:10:24 +01:00
mitchmindtree fcc75f4566 Rename `SamplesRate` to `SampleRate` and `ChannelsCount` to `ChannelCount` (#199)
* Rename SamplesRate to SampleRate and samples_rate to sample_rate

* Rename ChannelsCount to ChannelCount

* Update CHANGELOG for SamplesRate and ChannelsCount renaming
2018-02-04 13:02:16 +01:00
mitchmindtree f2728f6bdf Remove unused `ChannelPosition` API (update all backends and examples accordingly) (#198)
* Remove ChannelPosition API

This removes the ChannelPosition API from the lib root and updates the
ALSA backend and examples accordingly. The other backends have not yet
been updated.

Related discussion at #187.

* Update windows backend to removal of ChannelPosition API

The windows backend now assumes the channel position order is equal to
the channel position mask order. E.g. channel 0 will always be front
left, channel 1 will always be front right, etc.

Compiled and ran both examples successfully.

* Update coreaudio backend to removal of ChannelPosition API

Compiled and ran both examples successfully.

* Update emscriptem backend for removal of ChannelPosition API

* Update CHANGELOG for ChannelPosition removal
2018-02-04 10:38:06 +01:00
mitchmindtree 019b27350f Implement `pause` and `play` for ALSA backend (#176)
* Implement `pause` and `play` for ALSA backend

This commit also ensures that the Voice is initially paused when
returned to remain consistent with the rest of the CPAL backends.

Related to #175.

* Remove ineffective pause from end of build_voice method

* ALSA - Change `is_paused` flag from `AtomicBool` to `bool`

* Add pause and play ALSA addition to CHANGELOG
2017-11-02 10:30:15 +01:00
tomaka 743e4e3526
Fix #177 (#179) 2017-11-01 10:15:17 +01:00
tomaka 91adc3e380 Docs and style improvements (#174)
* Improve the crate root documentation

* Add entry in CHANGELOG

* Run rustfmt on the code

* More improvements to documentation
2017-10-23 16:41:38 +02:00
tomaka 87949d859b Add SupportedFormat (#168) 2017-10-20 21:18:40 +02:00
tomaka 6ae01f437c RFC: Rework the API [WIP] (#165)
* Rework the API to not use futures anymore

* Add some comments

* Update the MacOS backend

* Restore the null implementation

* Add an emscripten backend

* Remove erroneously added feature

* Fix to_f32 formula

* [WIP] Alsa backend

* Alsa backend compiling

* Working ALSA backend

* Fix tests

* Move WASAPI endpoint to endpoint module

* Fix WASAPI warnings

* Rework the WASAPI backend

* Check overflows for voice ID

* Add comments and minor fixes to WASAPI backend

* Add a changelog
2017-10-18 20:24:05 +02:00
tomaka 4b019243c2 Rename the methods of the backend as well (#164) 2017-10-12 11:54:09 +02:00
tomaka 2028d5907f Run rustfmt on the code (#162) 2017-10-11 13:24:49 +02:00
Johannes Lundberg e86ffce712 Fixes for *BSDs
Replace linux-only eventfd() with pipe() to enable use on *BSDs for alsa.
Add FreeBSD to supported OSes.
2017-07-13 15:59:40 +02:00
Nikita Chashchinskii 0f8babe8bd Pass period instead of buffer to snd_pcm_sw_params_set_avail_min
* Also bump version from 0.4.2 to 0.4.3
2017-02-04 08:20:21 +03:00
jwestfall 7c03219451 alsa: set sw_params_set_avail_min based on get_params buffer size
snd_pcm_sw_params_set_avail_min was being hardcoded to 4096, which
seems to be problematic for lower sample rates.  This update sets
the value to the buffer size as supplied by snd_pcm_get_params(),
which is what alsa own sample code does.

This should fix https://github.com/tomaka/cpal/issues/142
2017-01-23 16:10:44 -08:00
thiolliere 25bb025a9a arc not necessary 2016-10-02 14:24:30 +02:00
thiolliere 5c86eec4f3 line not necessary 2016-10-02 14:21:33 +02:00
thiolliere 1b0c9f2c54 syntax: space after comma 2016-10-02 14:19:58 +02:00
thiolliere f822631bc4 impl play and pause for ALSA
snd_pcm_pause could have been used but not all hardware implement it, so
I propose not to use it.

In this implementation:

there are two kind of scheduling: wait for resume signal and wait for
pcm to be available

if the stream is paused then it return notready and wait for resume

the event loop is different as it manages descriptors corresponding to
voices according to the nature of the scheduling.

there is still a FIXME: in voice.play the is signal is send even if
the event loop wasn't waiting for resume.
It doesn't seem to create any issue. But it happens when you write
voice.pause();voice.play();
2016-10-02 13:29:01 +02:00
thiolliere e031025abe update to futures 0.1.1: alsa wasapi 2016-10-01 00:44:22 +02:00
Pierre Krieger 0c915cac8f Use a max buffer size in order to avoid problems 2016-08-03 10:31:02 +02:00
Pierre Krieger 7c587853ad Make it work on Linux 2016-08-03 10:17:23 +02:00
Pierre Krieger 752676c818 Be more relaxed with c_void 2016-04-25 13:33:12 +02:00
Mathijs van de Nes f3f194293a Fix underflow detection for alsa
The old method always returned _RUNNING on some machines.
This new method seems to produce the expected behaviour.

Note: -32 is probably -EPIPE, but the appropriate constant was not
available at this time.
2016-02-28 17:01:13 +01:00
Nicolas Koch 606bcf9fa6 Fix underflow bug on linux 2016-01-28 21:27:09 +01:00
psych0d0g 7c3aab71a2 Add some sane error messages 2016-01-15 21:16:34 +01:00
tomaka b049e80ca3 Merge pull request #84 from tomaka/alsa-channels
Use correct ALSA channels
2015-12-15 17:49:42 +01:00
Mathijs van de Nes 951b7f5e65 Catch another 'device not found' error code 2015-10-13 12:22:07 +02:00
Pierre Krieger 55dbfa881e Use correct ALSA channels 2015-09-27 13:27:00 +02:00
Pierre Krieger c93ffcff6c Add Voice::get_period() 2015-09-27 13:00:17 +02:00
Pierre Krieger 6bd28231ec Make sure that all writes succeed 2015-09-22 21:01:26 +02:00
Pierre Krieger 5fc346b34b Make the ALSA implementation more robust by recovering from underruns 2015-09-22 20:20:17 +02:00
Pierre Krieger 44e9dce43f Add Voice::get_pending_samples 2015-09-22 17:59:36 +02:00
Pierre Krieger 5fa41538a6 Various ALSA fixes 2015-09-22 15:46:56 +02:00
tomaka 0a13991f86 Merge pull request #75 from tomaka/alsa-format
Use the correct format in ALSA
2015-09-22 15:23:28 +02:00
Pierre Krieger 46151e09cc Use the correct format in ALSA 2015-09-22 15:20:11 +02:00
Pierre Krieger a2b8b4f4a7 Use the correct device name when enumerating formats 2015-09-22 15:12:41 +02:00
tomaka debb6c957c Merge pull request #73 from tomaka/example-enumerate
Example enumerate
2015-09-22 14:49:31 +02:00
Pierre Krieger ec48453b6f Add endpoint::get_name() and an enumerate example 2015-09-22 14:46:27 +02:00
tomaka d4c7d91fd7 Merge pull request #63 from tomaka/alsa-formats
Correctly enumerate supported formats on ALSA
2015-09-22 13:56:22 +02:00
Pierre Krieger 8d21f5ff25 Store the format in the public `Voice` struct 2015-09-22 13:34:06 +02:00