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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use std::time::Duration;
pub use crate::types::Stream;
use crate::rpa_error::{PaError, PaResult};
use crate::rportaudio;
use crate::types::*;
pub const FRAMES_PER_BUFFER_UNSPECIFIED: u64 = 0;
impl<'a, T: SampleType> Stream<'a, T, T> {
pub fn open_default(num_input_channels: u32,
num_output_channels: u32,
sample_rate: f64,
frames_per_buffer: u64,
callback: Option<Box<StreamCallback<'a, T, T>>>)
-> Result<Stream<'a, T, T>, PaError> {
rportaudio::open_default_stream(
num_input_channels,
num_output_channels,
sample_rate,
frames_per_buffer,
callback,
)
}
}
impl<'a, I: SampleType, O: SampleType> Stream<'a, I, O> {
pub fn open(input: Option<PaStreamParameters<I>>,
output: Option<PaStreamParameters<O>>,
sample_rate: f64,
frames_per_buffer: u64,
flags: PaStreamFlags,
callback: Option<Box<StreamCallback<'a, I, O>>>)
-> Result<Stream<'a, I, O>, PaError> {
rportaudio::open_stream(
input,
output,
sample_rate,
frames_per_buffer,
flags,
callback,
)
}
pub fn start(&self) -> PaResult {
rportaudio::start_stream(self)
}
pub fn stop(&self) -> PaResult {
rportaudio::stop_stream(self)
}
pub fn abort(&self) -> PaResult {
rportaudio::abort_stream(self)
}
fn close(&self) -> PaResult {
rportaudio::close_stream(self)
}
pub fn is_stopped(&self) -> Result<bool, PaError> {
rportaudio::is_stream_stopped(self)
}
pub fn is_active(&self) -> Result<bool, PaError> {
rportaudio::is_stream_active(self)
}
pub fn num_read_available(&self) -> Result<u32, PaError> {
rportaudio::stream_num_read_available(self)
}
pub fn num_write_available(&self) -> Result<u32, PaError> {
rportaudio::stream_num_write_available(self)
}
pub fn write(&self, buffer: &[O]) -> PaResult {
rportaudio::write_stream(self, buffer)
}
pub fn read(&self, frames: u32) -> Result<Vec<I>, PaError> {
rportaudio::read_stream(self, frames)
}
pub fn cpu_load(&self) -> f64 {
rportaudio::stream_cpu_load(self)
}
pub fn time(&self) -> Duration {
rportaudio::stream_time(self)
}
pub fn info(&self) -> Option<PaStreamInfo> {
rportaudio::stream_info(self)
}
pub fn set_finished_callback(&mut self, finished_callback: Box<StreamFinishedCallback<'a>>) -> PaResult {
rportaudio::set_stream_finished_callback(self, finished_callback)
}
pub fn unset_finished_callback(&mut self) -> PaResult {
rportaudio::unset_stream_finished_callback(self)
}
}
pub fn is_format_supported<I: SampleType, O: SampleType>(input: Option<PaStreamParameters<I>>, output: Option<PaStreamParameters<O>>, sample_rate: f64) -> PaResult {
rportaudio::is_format_supported(input, output, sample_rate)
}