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
163
164
165
166
167
168
169
170
171
172
173
use super::*;
/// The AudioBuffer class.
/// [`AudioBuffer`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct AudioBuffer {
inner: Any,
}
impl FromVal for AudioBuffer {
fn from_val(v: &Any) -> Self {
AudioBuffer {
inner: Any::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for AudioBuffer {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for AudioBuffer {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for AudioBuffer {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for AudioBuffer {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<AudioBuffer> for Any {
fn from(s: AudioBuffer) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&AudioBuffer> for Any {
fn from(s: &AudioBuffer) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(AudioBuffer);
impl AudioBuffer {
/// Getter of the `sampleRate` attribute.
/// [`AudioBuffer.sampleRate`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/sampleRate)
pub fn sample_rate(&self) -> f32 {
self.inner.get("sampleRate").as_::<f32>()
}
}
impl AudioBuffer {
/// Getter of the `length` attribute.
/// [`AudioBuffer.length`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/length)
pub fn length(&self) -> u32 {
self.inner.get("length").as_::<u32>()
}
}
impl AudioBuffer {
/// Getter of the `duration` attribute.
/// [`AudioBuffer.duration`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/duration)
pub fn duration(&self) -> f64 {
self.inner.get("duration").as_::<f64>()
}
}
impl AudioBuffer {
/// Getter of the `numberOfChannels` attribute.
/// [`AudioBuffer.numberOfChannels`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/numberOfChannels)
pub fn number_of_channels(&self) -> u32 {
self.inner.get("numberOfChannels").as_::<u32>()
}
}
impl AudioBuffer {
/// The `new AudioBuffer(..)` constructor, creating a new AudioBuffer instance
pub fn new(options: &AudioBufferOptions) -> AudioBuffer {
Self {
inner: Any::global("AudioBuffer")
.new(&[options.into()])
.as_::<Any>(),
}
}
}
impl AudioBuffer {
/// The getChannelData method.
/// [`AudioBuffer.getChannelData`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/getChannelData)
pub fn get_channel_data(&self, channel: u32) -> Float32Array {
self.inner
.call("getChannelData", &[channel.into()])
.as_::<Float32Array>()
}
}
impl AudioBuffer {
/// The copyFromChannel method.
/// [`AudioBuffer.copyFromChannel`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyFromChannel)
pub fn copy_from_channel(&self, destination: &Float32Array, channel_number: u32) -> Undefined {
self.inner
.call(
"copyFromChannel",
&[destination.into(), channel_number.into()],
)
.as_::<Undefined>()
}
}
impl AudioBuffer {
/// The copyFromChannel method.
/// [`AudioBuffer.copyFromChannel`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyFromChannel)
pub fn copy_from_channel_with_buffer_offset(
&self,
destination: &Float32Array,
channel_number: u32,
buffer_offset: u32,
) -> Undefined {
self.inner
.call(
"copyFromChannel",
&[
destination.into(),
channel_number.into(),
buffer_offset.into(),
],
)
.as_::<Undefined>()
}
}
impl AudioBuffer {
/// The copyToChannel method.
/// [`AudioBuffer.copyToChannel`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyToChannel)
pub fn copy_to_channel(&self, source: &Float32Array, channel_number: u32) -> Undefined {
self.inner
.call("copyToChannel", &[source.into(), channel_number.into()])
.as_::<Undefined>()
}
}
impl AudioBuffer {
/// The copyToChannel method.
/// [`AudioBuffer.copyToChannel`](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyToChannel)
pub fn copy_to_channel_with_buffer_offset(
&self,
source: &Float32Array,
channel_number: u32,
buffer_offset: u32,
) -> Undefined {
self.inner
.call(
"copyToChannel",
&[source.into(), channel_number.into(), buffer_offset.into()],
)
.as_::<Undefined>()
}
}