Skip to content

Commit ee7d1cf

Browse files
committed
fix: conflicts
2 parents 46d8434 + 5709760 commit ee7d1cf

File tree

8 files changed

+365
-51
lines changed

8 files changed

+365
-51
lines changed

examples/multichannel.maxpat

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
{
2+
"patcher" : {
3+
"fileversion" : 1,
4+
"appversion" : {
5+
"major" : 8,
6+
"minor" : 5,
7+
"revision" : 3,
8+
"architecture" : "x64",
9+
"modernui" : 1
10+
}
11+
,
12+
"classnamespace" : "box",
13+
"rect" : [ 309.0, 671.0, 1188.0, 539.0 ],
14+
"bglocked" : 0,
15+
"openinpresentation" : 0,
16+
"default_fontsize" : 12.0,
17+
"default_fontface" : 0,
18+
"default_fontname" : "Arial",
19+
"gridonopen" : 1,
20+
"gridsize" : [ 15.0, 15.0 ],
21+
"gridsnaponopen" : 1,
22+
"objectsnaponopen" : 1,
23+
"statusbarvisible" : 2,
24+
"toolbarvisible" : 1,
25+
"lefttoolbarpinned" : 0,
26+
"toptoolbarpinned" : 0,
27+
"righttoolbarpinned" : 0,
28+
"bottomtoolbarpinned" : 0,
29+
"toolbars_unpinned_last_save" : 0,
30+
"tallnewobj" : 0,
31+
"boxanimatetime" : 200,
32+
"enablehscroll" : 1,
33+
"enablevscroll" : 1,
34+
"devicewidth" : 0.0,
35+
"description" : "",
36+
"digest" : "",
37+
"tags" : "",
38+
"style" : "",
39+
"subpatcher_template" : "",
40+
"assistshowspatchername" : 0,
41+
"boxes" : [ {
42+
"box" : {
43+
"id" : "obj-5",
44+
"maxclass" : "meter~",
45+
"numinlets" : 1,
46+
"numoutlets" : 1,
47+
"outlettype" : [ "float" ],
48+
"patching_rect" : [ 606.428571428571445, 189.0, 19.0, 65.0 ]
49+
}
50+
51+
}
52+
, {
53+
"box" : {
54+
"id" : "obj-6",
55+
"maxclass" : "meter~",
56+
"numinlets" : 1,
57+
"numoutlets" : 1,
58+
"outlettype" : [ "float" ],
59+
"patching_rect" : [ 575.428571428571445, 189.0, 19.0, 65.0 ]
60+
}
61+
62+
}
63+
, {
64+
"box" : {
65+
"id" : "obj-7",
66+
"maxclass" : "meter~",
67+
"numinlets" : 1,
68+
"numoutlets" : 1,
69+
"outlettype" : [ "float" ],
70+
"patching_rect" : [ 548.0, 189.0, 19.0, 65.0 ]
71+
}
72+
73+
}
74+
, {
75+
"box" : {
76+
"id" : "obj-8",
77+
"maxclass" : "meter~",
78+
"numinlets" : 1,
79+
"numoutlets" : 1,
80+
"outlettype" : [ "float" ],
81+
"patching_rect" : [ 519.0, 189.0, 19.0, 65.0 ]
82+
}
83+
84+
}
85+
, {
86+
"box" : {
87+
"id" : "obj-4",
88+
"maxclass" : "meter~",
89+
"numinlets" : 1,
90+
"numoutlets" : 1,
91+
"outlettype" : [ "float" ],
92+
"patching_rect" : [ 488.428571428571445, 189.0, 19.0, 65.0 ]
93+
}
94+
95+
}
96+
, {
97+
"box" : {
98+
"id" : "obj-27",
99+
"maxclass" : "meter~",
100+
"numinlets" : 1,
101+
"numoutlets" : 1,
102+
"outlettype" : [ "float" ],
103+
"patching_rect" : [ 457.428571428571445, 189.0, 19.0, 65.0 ]
104+
}
105+
106+
}
107+
, {
108+
"box" : {
109+
"id" : "obj-26",
110+
"maxclass" : "meter~",
111+
"numinlets" : 1,
112+
"numoutlets" : 1,
113+
"outlettype" : [ "float" ],
114+
"patching_rect" : [ 430.0, 189.0, 19.0, 65.0 ]
115+
}
116+
117+
}
118+
, {
119+
"box" : {
120+
"id" : "obj-25",
121+
"maxclass" : "meter~",
122+
"numinlets" : 1,
123+
"numoutlets" : 1,
124+
"outlettype" : [ "float" ],
125+
"patching_rect" : [ 401.0, 189.0, 19.0, 65.0 ]
126+
}
127+
128+
}
129+
, {
130+
"box" : {
131+
"id" : "obj-3",
132+
"maxclass" : "toggle",
133+
"numinlets" : 1,
134+
"numoutlets" : 1,
135+
"outlettype" : [ "int" ],
136+
"parameter_enable" : 0,
137+
"patching_rect" : [ 430.0, 75.0, 24.0, 24.0 ]
138+
}
139+
140+
}
141+
, {
142+
"box" : {
143+
"id" : "obj-1",
144+
"maxclass" : "newobj",
145+
"numinlets" : 1,
146+
"numoutlets" : 8,
147+
"outlettype" : [ "signal", "signal", "signal", "signal", "signal", "signal", "signal", "signal" ],
148+
"patching_rect" : [ 430.0, 124.0, 115.0, 22.0 ],
149+
"text" : "adc~ 1 2 3 4 5 6 7 8"
150+
}
151+
152+
}
153+
],
154+
"lines" : [ {
155+
"patchline" : {
156+
"destination" : [ "obj-25", 0 ],
157+
"source" : [ "obj-1", 0 ]
158+
}
159+
160+
}
161+
, {
162+
"patchline" : {
163+
"destination" : [ "obj-26", 0 ],
164+
"source" : [ "obj-1", 1 ]
165+
}
166+
167+
}
168+
, {
169+
"patchline" : {
170+
"destination" : [ "obj-27", 0 ],
171+
"source" : [ "obj-1", 2 ]
172+
}
173+
174+
}
175+
, {
176+
"patchline" : {
177+
"destination" : [ "obj-4", 0 ],
178+
"source" : [ "obj-1", 3 ]
179+
}
180+
181+
}
182+
, {
183+
"patchline" : {
184+
"destination" : [ "obj-5", 0 ],
185+
"source" : [ "obj-1", 7 ]
186+
}
187+
188+
}
189+
, {
190+
"patchline" : {
191+
"destination" : [ "obj-6", 0 ],
192+
"source" : [ "obj-1", 6 ]
193+
}
194+
195+
}
196+
, {
197+
"patchline" : {
198+
"destination" : [ "obj-7", 0 ],
199+
"source" : [ "obj-1", 5 ]
200+
}
201+
202+
}
203+
, {
204+
"patchline" : {
205+
"destination" : [ "obj-8", 0 ],
206+
"source" : [ "obj-1", 4 ]
207+
}
208+
209+
}
210+
, {
211+
"patchline" : {
212+
"destination" : [ "obj-1", 0 ],
213+
"source" : [ "obj-3", 0 ]
214+
}
215+
216+
}
217+
],
218+
"dependency_cache" : [ ],
219+
"autosave" : 0
220+
}
221+
222+
}

examples/multichannel.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use web_audio_api::context::{
2+
AudioContext, AudioContextLatencyCategory, AudioContextOptions, BaseAudioContext,
3+
};
4+
use web_audio_api::node::{AudioNode, AudioScheduledSourceNode, ChannelInterpretation};
5+
6+
// Example of multichannel routing, for now the library can only handle up to
7+
// 32 channels.
8+
//
9+
// The example can be tested with a virtual soundcard such as Blackhole
10+
// https://github.com/ExistentialAudio/BlackHole
11+
// - select backhole as the default system output
12+
// - then use blackhole as input in another program to check the example output
13+
// (see `multichannel.maxpat` if you have Max installed, @todo make a Pd version)
14+
//
15+
// `cargo run --release --example multichannel`
16+
//
17+
// If you are on Linux and use ALSA as audio backend backend, you might want to run
18+
// the example with the `WEB_AUDIO_LATENCY=playback ` env variable which will
19+
// increase the buffer size to 1024
20+
//
21+
// `WEB_AUDIO_LATENCY=playback cargo run --release --example multichannel`
22+
fn main() {
23+
env_logger::init();
24+
25+
let latency_hint = match std::env::var("WEB_AUDIO_LATENCY").as_deref() {
26+
Ok("playback") => AudioContextLatencyCategory::Playback,
27+
_ => AudioContextLatencyCategory::default(),
28+
};
29+
30+
let context = AudioContext::new(AudioContextOptions {
31+
latency_hint,
32+
..AudioContextOptions::default()
33+
});
34+
35+
// this should be clamped to MAX_CHANNELS (32), even if the soundcard can provide more channels
36+
println!(
37+
"> Max channel count: {:?}",
38+
context.destination().max_channels_count()
39+
);
40+
41+
let num_channels = 8;
42+
43+
context.destination().set_channel_count(num_channels);
44+
context
45+
.destination()
46+
.set_channel_interpretation(ChannelInterpretation::Discrete);
47+
48+
let merger = context.create_channel_merger(num_channels);
49+
merger.set_channel_interpretation(ChannelInterpretation::Discrete);
50+
merger.connect(&context.destination());
51+
52+
let mut output_channel = 0;
53+
54+
loop {
55+
println!("- output sine in channel {:?}", output_channel);
56+
57+
let now = context.current_time();
58+
59+
let osc = context.create_oscillator();
60+
osc.connect_at(&merger, 0, output_channel);
61+
osc.frequency().set_value(200.);
62+
osc.start_at(now);
63+
osc.stop_at(now + 1.);
64+
65+
output_channel = (output_channel + 1) % num_channels;
66+
67+
std::thread::sleep(std::time::Duration::from_secs(1));
68+
}
69+
}

src/context/offline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod private {
3131
}
3232

3333
pub fn render_audiobuffer(self, buffer_size: usize) -> AudioBuffer {
34-
self.0.render_audiobuffer(buffer_size)
34+
self.0.render_audiobuffer_sync(buffer_size)
3535
}
3636
}
3737

src/context/online.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::media_devices::{enumerate_devices_sync, MediaDeviceInfoKind};
99
use crate::media_streams::{MediaStream, MediaStreamTrack};
1010
use crate::message::ControlMessage;
1111
use crate::node::{self, ChannelConfigOptions};
12+
use crate::render::graph::Graph;
1213
use crate::MediaElement;
1314
use crate::{AudioRenderCapacity, Event};
1415

@@ -172,8 +173,8 @@ impl AudioContext {
172173
event_recv,
173174
} = control_thread_init;
174175

175-
let graph = crate::render::graph::Graph::new();
176-
let message = crate::message::ControlMessage::Startup { graph };
176+
let graph = Graph::new();
177+
let message = ControlMessage::Startup { graph };
177178
ctrl_msg_send.send(message).unwrap();
178179

179180
let base = ConcreteBaseAudioContext::new(

0 commit comments

Comments
 (0)