microphone example: detect incompatible in/out devices

This commit is contained in:
Andrew Kelley 2015-07-06 17:16:03 -07:00
parent 5048d7aa57
commit d6fcef468b
3 changed files with 35 additions and 4 deletions

View file

@ -10,7 +10,7 @@ exposed.
**This library is a work-in-progress.** **This library is a work-in-progress.**
## Why libsoundio? ## Alternatives
* [PortAudio](http://www.portaudio.com/) * [PortAudio](http://www.portaudio.com/)
- It does not support [PulseAudio](http://www.freedesktop.org/wiki/Software/PulseAudio/). - It does not support [PulseAudio](http://www.freedesktop.org/wiki/Software/PulseAudio/).
@ -97,6 +97,22 @@ cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/i686-w64-mingw32.static/share/c
make make
``` ```
#### Running the Tests
```
make test
```
For more detailed output:
```
make
./unit_tests
```
To see test coverage, install lcov, run `make coverage` and then
view `coverage/index.html` in a browser.
## Roadmap ## Roadmap
0. pipe record to playback example working with dummy linux, osx, windows 0. pipe record to playback example working with dummy linux, osx, windows
@ -112,6 +128,8 @@ make
0. -fvisibility=hidden and then explicitly export stuff 0. -fvisibility=hidden and then explicitly export stuff
0. Integrate into libgroove and test with Groove Basin 0. Integrate into libgroove and test with Groove Basin
0. Consider testing on FreeBSD 0. Consider testing on FreeBSD
0. look at microphone example and determine if fewer memcpys can be done
with the audio data
## Planned Uses for libsoundio ## Planned Uses for libsoundio

View file

@ -71,12 +71,23 @@ int main(int argc, char **argv) {
soundio_device_name(out_device), soundio_device_name(out_device),
soundio_device_description(out_device)); soundio_device_description(out_device));
const struct SoundIoChannelLayout *in_layout = soundio_device_channel_layout(in_device);
const struct SoundIoChannelLayout *out_layout = soundio_device_channel_layout(out_device);
if (!soundio_channel_layout_equal(in_layout, out_layout))
panic("channel layouts not compatible");
if (soundio_device_sample_rate(in_device) != soundio_device_sample_rate(out_device))
panic("sample rates not compatible");
double latency = 0.1;
struct SoundIoInputDevice *input_device; struct SoundIoInputDevice *input_device;
soundio_input_device_create(in_device, SoundIoSampleFormatFloat, 0.1, NULL, soundio_input_device_create(in_device, SoundIoSampleFormatFloat, latency, NULL,
read_callback, &input_device); read_callback, &input_device);
struct SoundIoOutputDevice *output_device; struct SoundIoOutputDevice *output_device;
soundio_output_device_create(out_device, SoundIoSampleFormatFloat, 0.1, NULL, soundio_output_device_create(out_device, SoundIoSampleFormatFloat, latency, NULL,
write_callback, underrun_callback, &output_device); write_callback, underrun_callback, &output_device);
if ((err = soundio_input_device_start(input_device))) if ((err = soundio_input_device_start(input_device)))

View file

@ -314,8 +314,10 @@ int soundio_input_device_create(struct SoundIoDevice *device,
void soundio_input_device_destroy(struct SoundIoInputDevice *input_device); void soundio_input_device_destroy(struct SoundIoInputDevice *input_device);
int soundio_input_device_start(struct SoundIoInputDevice *input_device); int soundio_input_device_start(struct SoundIoInputDevice *input_device);
void soundio_input_device_peek(struct SoundIoInputDevice *input_device, void soundio_input_device_peek(struct SoundIoInputDevice *input_device,
const char **data, int *frame_count); const char **data, int *out_frame_count);
// this will drop all of the frames from when you called soundio_input_device_peek
void soundio_input_device_drop(struct SoundIoInputDevice *input_device); void soundio_input_device_drop(struct SoundIoInputDevice *input_device);
void soundio_input_device_clear_buffer(struct SoundIoInputDevice *input_device); void soundio_input_device_clear_buffer(struct SoundIoInputDevice *input_device);