1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Wavy
// Copyright © 2019-2021 Jeron Aldaron Lau.
//
// Licensed under any of:
// - Apache License, Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
// - MIT License (https://mit-license.org/)
// - Boost Software License, Version 1.0 (https://www.boost.org/LICENSE_1_0.txt)
// At your choosing (See accompanying files LICENSE_APACHE_2_0.txt,
// LICENSE_MIT.txt and LICENSE_BOOST_1_0.txt).
//
//! Asynchronous cross-platform real-time audio recording & playback.
//!
//! # Getting Started
//! Add the following to your *Cargo.toml*:
//!
//! ```toml
//! [dependencies]
//! pasts = "0.7"
//! wavy = "0.8"
//! fon = "0.4"
//! ```
//!
//! This example records audio and plays it back in real time as it's being
//! recorded.  (Make sure to wear headphones to avoid feedback):
//!
//! ```rust,no_run
//! use fon::{stereo::Stereo32, Sink, Audio};
//! use pasts::{exec, wait};
//! use wavy::{Speakers, Microphone, SpeakersSink, MicrophoneStream};
//!
//! /// An event handled by the event loop.
//! enum Event<'a> {
//!     /// Speaker is ready to play more audio.
//!     Play(SpeakersSink<'a, Stereo32>),
//!     /// Microphone has recorded some audio.
//!     Record(MicrophoneStream<'a, Stereo32>),
//! }
//!
//! /// Shared state between tasks on the thread.
//! struct State {
//!     /// Temporary buffer for holding real-time audio samples.
//!     buffer: Audio<Stereo32>,
//! }
//!
//! impl State {
//!     /// Event loop.  Return false to stop program.
//!     fn event(&mut self, event: Event<'_>) {
//!         match event {
//!             Event::Play(mut speakers) => speakers.stream(self.buffer.drain()),
//!             Event::Record(microphone) => self.buffer.extend(microphone),
//!         }
//!     }
//! }
//!
//! /// Program start.
//! fn main() {
//!     let mut state = State { buffer: Audio::with_silence(48_000, 0) };
//!     let mut speakers = Speakers::default();
//!     let mut microphone = Microphone::default();
//!
//!     exec!(state.event(wait! {
//!         Event::Record(microphone.record().await),
//!         Event::Play(speakers.play().await),
//!     }));
//! }
//! ```

#![doc(
    html_logo_url = "https://libcala.github.io/logo.svg",
    html_favicon_url = "https://libcala.github.io/icon.svg",
    html_root_url = "https://docs.rs/wavy"
)]
#![deny(unsafe_code)]
#![warn(
    anonymous_parameters,
    missing_copy_implementations,
    missing_debug_implementations,
    missing_docs,
    nonstandard_style,
    rust_2018_idioms,
    single_use_lifetimes,
    trivial_casts,
    trivial_numeric_casts,
    unreachable_pub,
    unused_extern_crates,
    unused_qualifications,
    variant_size_differences
)]

#[cfg_attr(target_arch = "wasm32", path = "ffi/wasm/ffi.rs")]
#[cfg_attr(
    not(target_arch = "wasm32"),
    cfg_attr(target_os = "linux", path = "ffi/linux/ffi.rs"),
    cfg_attr(target_os = "android", path = "ffi/android/ffi.rs"),
    cfg_attr(target_os = "macos", path = "ffi/macos/ffi.rs"),
    cfg_attr(target_os = "ios", path = "ffi/ios/ffi.rs"),
    cfg_attr(target_os = "windows", path = "ffi/windows/ffi.rs"),
    cfg_attr(
        any(
            target_os = "freebsd",
            target_os = "dragonfly",
            target_os = "bitrig",
            target_os = "openbsd",
            target_os = "netbsd"
        ),
        path = "ffi/bsd/ffi.rs"
    ),
    cfg_attr(target_os = "fuchsia", path = "ffi/fuchsia/ffi.rs"),
    cfg_attr(target_os = "redox", path = "ffi/redox/ffi.rs"),
    cfg_attr(target_os = "none", path = "ffi/none/ffi.rs"),
    cfg_attr(target_os = "dummy", path = "ffi/dummy/ffi.rs")
)]
mod ffi;

mod consts;
mod microphone;
mod speakers;

pub use microphone::{Microphone, MicrophoneStream};
pub use speakers::{Speakers, SpeakersSink};