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
// 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).
//! Hard-coded constants used throughout the library for dealing with computer
//! audio.
/// Preferred sample rate chosen by this library. 48 KHz is chosen because it
/// is cited as one of the standards for computer audio by
/// [MDN](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Audio_concepts#Audio_channels_and_frames).
/// The other being 44.1 KHz. 48 KHz is also the default for the Ogg Opus
/// audio format, which is the state-of-the-art audio format.
// For web, let the browser choose the sample rate
pub const SAMPLE_RATE: u16 = 48_000;
/// Set latency to be about 1 millisecond. This is how many samples need to be
/// generated at each call to/from microphone or speaker.
///
/// 48 is the minimum period that doesn't create bad-sounding artifacts on ALSA
/// running on PulseAudio for my testing, bumped up to 64 (1.5 ms) should be
/// sufficient. Humans generally can't tell at about 2 ms, which gives .5ms
/// leeway for processing time.
// Not used on WASM
pub const PERIOD: u16 = 64;
// FIXME: Split "Period" into "Buffer Size" and "Block Size"
/// This is the size of the ring buffer used by the system.
///
/// The number 256 is chosen because it's the minimum allowed by the
/// `createScriptProcessor` API, and wavy targets low latency.
// FIXME
pub const BUFFER_SIZE: u16 = 256;
/// This is the target for how many samples are processed at a time (0.75 ms).
///
/// This also means that 8 chunks can be contained in a buffer.
// Not used on WASM
pub const CHUNK_SIZE: u16 = 32;