Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd87c9c9

Browse files
committed
add shuffle bag for audio
add radio groundwork from CorvusPrudens democleanup ui and comment out keybind editor for now
1 parenteb3ed08 commitd87c9c9

File tree

20 files changed

+1541
-893
lines changed

20 files changed

+1541
-893
lines changed

‎Cargo.lock‎

Lines changed: 839 additions & 394 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,23 @@ features = [
8181
bevy_fix_gltf_coordinate_system ="0.1"
8282
bevy_fix_cursor_unlock_web ="0.1"
8383
bevy-inspector-egui = {version ="0.31.0",optional =true }
84-
bevy_skein ="0.2.1"# blender integration
85-
iyes_perf_ui ="0.5"# diagnostics overlay
84+
bevy_skein ="0.2.1"# blender integration
85+
iyes_perf_ui ="0.5"# diagnostics overlay
8686

87-
avian3d = {version ="0.3",features = ["3d","parallel","collider-from-mesh"] }# physics
88-
bevy_seedling ="0.5"# audio engine
89-
bevy_third_person_camera = {version ="0.3",optional =true }# 3rd person camera
90-
bevy_top_down_camera = {version ="0.1",optional =true }# top down camera
91-
bevy-tnua ="0.24"# floating character control
92-
bevy-tnua-avian3d ="0.5"# tnua-avian interaction
93-
bevy_enhanced_input ="0.15"# keyboard/gamepad input
87+
avian3d = {version ="0.3",features = ["3d","parallel","collider-from-mesh"] }# physics
88+
bevy_seedling = {version ="0.5",features = ["hrtf","ogg"] }# audio plugin using firewheel
89+
bevy_shuffle_bag ="0.2"# random container for audio
90+
fundsp ="0.20.0"
91+
firewheel ="0.7"
92+
93+
bevy_third_person_camera = {version ="0.3",optional =true }# 3rd person camera
94+
bevy_top_down_camera = {version ="0.1",optional =true }# top down camera
95+
# bevy_third_person_camera = { path = "../../Documents/rust/bevy_third_person_camera", optional = true } # 3rd person camera
96+
# bevy_top_down_camera = { version = "0.1", git = "https://github.com/olekspickle/bevy_top_down_camera", optional = true } # top down camera
97+
98+
bevy-tnua ="0.24"# floating character control
99+
bevy-tnua-avian3d ="0.5"# tnua-avian interaction
100+
bevy_enhanced_input ="0.18"# keyboard/gamepad input
94101

95102
# misc
96103
# itertools = "0.14.0"
@@ -105,12 +112,14 @@ log = { version = "0.4", features = ["max_level_debug", "release_max_level_warn"
105112
winit = {version ="0.30",default-features =false }
106113

107114
[target.'cfg(target_arch="wasm32")'.dependencies]
108-
#firewheel-web-audio = { git = "https://github.com/CorvusPrudens/firewheel-web-audio" }
115+
firewheel-web-audio = {git ="https://github.com/CorvusPrudens/firewheel-web-audio" }
109116
# Leave only high-severity logs in web build
110117
tracing = {version ="0.1",features = ["max_level_debug","release_max_level_warn"] }
111118

112-
# LINT
119+
[patch.crates-io]
120+
# bevy_seedling = { git = "https://github.com/CorvusPrudens/bevy_seedling", rev = "78dde3b" }
113121

122+
# LINT
114123
[lints.clippy]
115124
# Bevy supplies arguments to systems via dependency injection, so it's natural for systems to
116125
# request more than 7 arguments, which would undesirably trigger this lint.

‎assets/models/scene.blend‎

80 Bytes
Binary file not shown.

‎assets/models/scene.glb‎

0 Bytes
Binary file not shown.

‎assets/settings.ron‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(
22
sound: (
33
general:1.0,
4-
music:1.0000001,
4+
music:0.8000001,
55
sfx:0.5,
66
),
77
fov:45.0,

‎src/asset_loading/mod.rs‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bevy_seedling::sample::AudioSample;
55
mod ron;
66
mod tracking;
77

8+
use bevy_shuffle_bag::ShuffleBag;
89
pubuse ron::*;
910
pubuse tracking::*;
1011

@@ -87,15 +88,15 @@ pub struct AudioSources {
8788
#[dependency]
8889
pubbtn_press:Handle<AudioSample>,
8990
#[dependency]
90-
pubsteps:Vec<Handle<AudioSample>>,
91+
pubsteps:ShuffleBag<Handle<AudioSample>>,
9192

9293
// music
9394
#[dependency]
94-
pubmenu:Vec<Handle<AudioSample>>,
95+
pubmenu:ShuffleBag<Handle<AudioSample>>,
9596
#[dependency]
96-
pubexplore:Vec<Handle<AudioSample>>,
97+
pubexplore:ShuffleBag<Handle<AudioSample>>,
9798
#[dependency]
98-
pubcombat:Vec<Handle<AudioSample>>,
99+
pubcombat:ShuffleBag<Handle<AudioSample>>,
99100
}
100101

101102
implAudioSources{
@@ -116,18 +117,21 @@ impl AudioSources {
116117

117118
implFromWorldforAudioSources{
118119
fnfrom_world(world:&mutWorld) ->Self{
119-
let assets = world.resource::<AssetServer>();
120-
let steps =Self::STEPS.iter().map(|p| assets.load(*p)).collect();
121-
let explore =Self::EXPLORE.iter().map(|p| assets.load(*p)).collect();
122-
let combat =Self::COMBAT.iter().map(|p| assets.load(*p)).collect();
123-
let menu =Self::MENU.iter().map(|p| assets.load(*p)).collect();
120+
letmut rng = rand::thread_rng();
121+
let a = world.resource::<AssetServer>();
122+
123+
let steps =Self::STEPS.iter().map(|p| a.load(*p)).collect::<Vec<_>>();
124+
let explore =Self::EXPLORE.iter().map(|p| a.load(*p)).collect::<Vec<_>>();
125+
let combat =Self::COMBAT.iter().map(|p| a.load(*p)).collect::<Vec<_>>();
126+
let menu =Self::MENU.iter().map(|p| a.load(*p)).collect::<Vec<_>>();
127+
124128
Self{
125-
menu,
126-
steps,
127-
combat,
128-
explore,
129-
btn_hover:assets.load(Self::BTN_HOVER),
130-
btn_press:assets.load(Self::BTN_PRESS),
129+
menu:ShuffleBag::try_new(menu,&mut rng).unwrap(),
130+
steps:ShuffleBag::try_new(steps,&mut rng).unwrap(),
131+
combat:ShuffleBag::try_new(combat,&mut rng).unwrap(),
132+
explore:ShuffleBag::try_new(explore,&mut rng).unwrap(),
133+
btn_hover:a.load(Self::BTN_HOVER),
134+
btn_press:a.load(Self::BTN_PRESS),
131135
}
132136
}
133137
}

‎src/audio/fdsp_host.rs‎

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
usesuper::*;
2+
use bevy_seedling::{
3+
firewheel::{
4+
channel_config::ChannelConfig,
5+
event::ProcEvents,
6+
node::{
7+
AudioNode,AudioNodeInfo,AudioNodeProcessor,ProcBuffers,ProcExtra,ProcInfo,
8+
ProcessStatus,
9+
},
10+
},
11+
node::RegisterNode,
12+
};
13+
use fundsp::prelude::*;
14+
15+
pubstructFundspPlugin;
16+
17+
implPluginforFundspPlugin{
18+
fnbuild(&self,app:&mutApp){
19+
app.register_simple_node::<FundspNode>()
20+
.add_observer(observe_config_add);
21+
}
22+
}
23+
24+
fnobserve_config_add(trigger:Trigger<OnAdd,FundspConfig>,mutcommands:Commands){
25+
commands.entity(trigger.target()).insert_if_new(FundspNode);
26+
}
27+
28+
#[derive(Debug,Clone,Component)]
29+
pubstructFundspNode;
30+
31+
#[derive(Clone,Component)]
32+
pubstructFundspConfig{
33+
pubskip_silence:bool,
34+
unit:Box<dynAudioUnit>,
35+
}
36+
37+
implFundspConfig{
38+
pubfnnew<U:AudioUnit +'static>(unit:U) ->Self{
39+
Self{
40+
skip_silence:true,
41+
unit:Box::new(unit),
42+
}
43+
}
44+
45+
/// Create a stereo node from a mono processing chain.
46+
///
47+
/// This simply downmixes the input and splits the output.
48+
pubfnnew_downmix<U: fundsp::audionode::AudioNode<Inputs =U1,Outputs =U1> +'static>(
49+
unit:An<U>,
50+
) ->Self{
51+
let graph =((pass() +pass())*0.5) >> unit >>split::<U2>();
52+
53+
Self{
54+
skip_silence:true,
55+
unit:Box::new(graph),
56+
}
57+
}
58+
59+
pubfnaudio_unit(&self) ->&dynAudioUnit{
60+
self.unit.as_ref()
61+
}
62+
63+
pubfnaudio_unit_mut(&mutself) ->&mutdynAudioUnit{
64+
self.unit.as_mut()
65+
}
66+
67+
pubfnwith_skip_silence(self,skip_silence:bool) ->Self{
68+
Self{
69+
skip_silence,
70+
unit:self.unit,
71+
}
72+
}
73+
}
74+
75+
implDefaultforFundspConfig{
76+
fndefault() ->Self{
77+
Self{
78+
skip_silence:true,
79+
unit:Box::new(pass()),
80+
}
81+
}
82+
}
83+
84+
implPartialEqforFundspConfig{
85+
fneq(&self,other:&Self) ->bool{
86+
self.unit.get_id() == other.unit.get_id() &&self.skip_silence == other.skip_silence
87+
}
88+
}
89+
90+
implAudioNodeforFundspNode{
91+
typeConfiguration =FundspConfig;
92+
93+
fninfo(&self,configuration:&Self::Configuration) ->AudioNodeInfo{
94+
AudioNodeInfo::new()
95+
.debug_name("Fun DSP")
96+
.channel_config(ChannelConfig::new(
97+
configuration.unit.inputs(),
98+
configuration.unit.outputs(),
99+
))
100+
}
101+
102+
fnconstruct_processor(
103+
&self,
104+
configuration:&Self::Configuration,
105+
cx: firewheel::node::ConstructProcessorContext,
106+
) ->implAudioNodeProcessor{
107+
letmut unit = configuration.clone();
108+
unit.unit
109+
.set_sample_rate(cx.stream_info.sample_rate.get()asf64);
110+
unit.unit.allocate();
111+
112+
let input_buffer =(0..unit.unit.inputs()).map(|_|0f32).collect();
113+
let output_buffer =(0..unit.unit.outputs()).map(|_|0f32).collect();
114+
115+
FundspProcessor{
116+
unit,
117+
input_buffer,
118+
output_buffer,
119+
}
120+
}
121+
}
122+
123+
structFundspProcessor{
124+
unit:FundspConfig,
125+
input_buffer:Box<[f32]>,
126+
output_buffer:Box<[f32]>,
127+
}
128+
129+
implAudioNodeProcessorforFundspProcessor{
130+
fnprocess(
131+
&mutself,
132+
info:&ProcInfo,
133+
ProcBuffers{ inputs, outputs}:ProcBuffers,
134+
_:&mutProcEvents,
135+
_:&mutProcExtra,
136+
) ->ProcessStatus{
137+
ifself.unit.skip_silence
138+
&& info
139+
.in_silence_mask
140+
.all_channels_silent(self.unit.unit.inputs())
141+
{
142+
returnProcessStatus::ClearAllOutputs;
143+
}
144+
145+
for framein0..info.frames{
146+
for(i, input)inself.input_buffer.iter_mut().enumerate(){
147+
*input = inputs[i][frame];
148+
}
149+
150+
self.unit
151+
.unit
152+
.tick(&self.input_buffer,&mutself.output_buffer);
153+
154+
for(i, output)inself.output_buffer.iter().enumerate(){
155+
outputs[i][frame] =*output;
156+
}
157+
}
158+
159+
ProcessStatus::outputs_not_silent()
160+
}
161+
162+
fnnew_stream(&mutself,stream_info:&firewheel::StreamInfo){
163+
if stream_info.sample_rate != stream_info.prev_sample_rate{
164+
self.unit
165+
.unit
166+
.set_sample_rate(stream_info.sample_rate.get()asf64);
167+
self.unit.unit.allocate();
168+
}
169+
}
170+
}

‎src/audio.rs‎renamed to ‎src/audio/mod.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
use bevy::prelude::*;
6262
use bevy_seedling::prelude::*;
6363

64+
pubmod fdsp_host;
65+
pubmod radio;
66+
6467
/// Utility for converting a simple `[0.0, 1.0]` range to [`Volume`].
6568
///
6669
///# Example

‎src/audio/radio.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
usesuper::fdsp_host::FundspConfig;
2+
use bevy::prelude::*;
3+
use fundsp::prelude::*;
4+
5+
pubfnradio() ->implBundle{
6+
let input =highpass_hz(400.0,2.0)
7+
>>bell_hz(1200.0,4.0,1.5)
8+
// poor signal quality simulation
9+
// >> shape(SoftCrush(2.0))
10+
>>shape(Tanh(16.0))
11+
>>lowpass_hz(2800.0,4.0)
12+
>>(limiter(0.005,0.250)*0.25);
13+
14+
let noise =(white()*0.1)
15+
>>highpass_hz(400.0,2.0)
16+
>>bell_hz(1200.0,4.0,1.5)
17+
>>shape(SoftCrush(2.0))
18+
>>(lowpass_hz(2800.0,4.0)*8.0);
19+
20+
let amp_adjustment =map(|i:&Frame<f32,U1>|(0.9 - i[0]*12.0).clamp(0.0,1.0));
21+
let branch =pass()&(meter(Meter::Rms(0.1)) >>(amp_adjustment* noise));
22+
23+
FundspConfig::new_downmix(input >> branch)
24+
}

‎src/main.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub mod screens;
1818
pubmod ui;
1919

2020
use asset_loading::{AudioSources,Models,ResourceHandles,Textures};
21-
use audio::*;
2221
use models::*;
2322
use scene::*;
2423
use ui::*;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp