@@ -35,6 +35,7 @@ struct AudioController {
3535 b : f32 ,
3636 c : f32 ,
3737 audio : Vec < AudioPacket > ,
38+ repeat : bool
3839}
3940
4041impl AudioController {
@@ -96,7 +97,6 @@ struct App
9697{
9798 player : AudioPlayer ,
9899 controller : Arc < Mutex < AudioController > > ,
99- samples_per_second : u32 ,
100100 pipeline : PipelineKey ,
101101 buffer : Buffer ,
102102 frame_index : u32 ,
@@ -107,8 +107,10 @@ struct App
107107struct PushConstants {
108108 time : f32 ,
109109 samples : u32 ,
110- amplitude : f32 ,
111- frequency : f32
110+ frequency : f32 ,
111+ a : f32 ,
112+ b : f32 ,
113+ c : f32 ,
112114}
113115
114116impl App {
@@ -118,6 +120,7 @@ impl App {
118120 a : 1.0 ,
119121 b : 0.0 ,
120122 c : 1.0 ,
123+ repeat : false ,
121124 engine_start_time : SystemTime :: now ( ) ,
122125 play_start_time : SystemTime :: now ( ) ,
123126 frequency : 440. ,
@@ -158,7 +161,6 @@ impl App {
158161 ) ;
159162
160163 Self {
161- samples_per_second : 1000 ,
162164 player,
163165 controller,
164166 pipeline,
@@ -188,8 +190,10 @@ impl RenderComponent for App {
188190 let push_constants = PushConstants {
189191 time : 0.0 ,
190192 samples : BUFFER_SAMPLES as u32 ,
191- amplitude : lock. a ,
192- frequency : lock. frequency
193+ frequency : lock. frequency ,
194+ a : lock. a ,
195+ b : lock. b ,
196+ c : lock. c ,
193197 } ;
194198 ctx. command_buffer . push_constants (
195199 & pipeline,
@@ -226,23 +230,11 @@ impl GuiComponent for App {
226230 fn gui ( & mut self , _: & mut GuiHandler , ctx : & Context ) {
227231 let mut lock = self . controller . lock ( ) . unwrap ( ) ;
228232 egui:: CentralPanel :: default ( ) . show ( ctx, |ui| {
229- if ui. button ( "play" ) . clicked ( ) {
230- lock. play_start_time = SystemTime :: now ( ) + Duration :: new ( 0 , 5000000 ) ;
231- }
232- ui. add ( Slider :: new ( & mut lock. volume , 0.0 ..=1.0 ) ) ;
233- ui. add ( Slider :: new ( & mut lock. frequency , 0.0 ..=1000.0 ) ) ;
234- ui. add ( Slider :: new ( & mut lock. a , 0.0 ..=2.0 ) ) ;
235- ui. add ( Slider :: new ( & mut lock. b , -1.0 ..=1.0 ) ) ;
236- ui. add ( Slider :: new ( & mut lock. c , 0.0 ..=2.0 ) ) ;
237-
238- ui. label ( "Samples per second" ) ;
239- ui. add ( Slider :: new ( & mut self . samples_per_second , 100 ..=100000 ) ) ;
240233
241234 if let Some ( audio) = lock. audio . first ( ) {
242235 Plot :: new ( "audio_plot" )
243236 . view_aspect ( 2.0 )
244237 . show ( ui, |plot_ui| {
245- // let total_samples = (duration * self.samples_per_second as f32) as i32;
246238 let total_samples = BUFFER_SAMPLES ;
247239 // Convert audio samples to plot points
248240 let points = ( 0 ..total_samples)
@@ -255,6 +247,21 @@ impl GuiComponent for App {
255247 plot_ui. line ( Line :: new ( "audio" , plot_points) ) ;
256248 } ) ;
257249 }
250+
251+ if ui. button ( "play" ) . clicked ( ) {
252+ lock. play_start_time = SystemTime :: now ( ) + Duration :: new ( 0 , 5000000 ) ;
253+ }
254+ ui. checkbox ( & mut lock. repeat , "" ) ;
255+ if lock. repeat && SystemTime :: now ( ) . duration_since ( lock. play_start_time ) . unwrap ( ) . as_secs_f64 ( ) > 0.9 {
256+ lock. play_start_time = SystemTime :: now ( ) + Duration :: new ( 0 , 0 ) ;
257+ }
258+
259+ ui. style_mut ( ) . spacing . slider_width = 190. ;
260+ ui. add ( Slider :: new ( & mut lock. volume , 0.0 ..=1.0 ) . text ( "Volume" ) ) ;
261+ ui. add ( Slider :: new ( & mut lock. frequency , 0.0 ..=1000.0 ) . text ( "Frequency" ) ) ;
262+ ui. add ( Slider :: new ( & mut lock. a , 0.0 ..=2.0 ) . text ( "a" ) ) ;
263+ ui. add ( Slider :: new ( & mut lock. b , -1.0 ..=1.0 ) . text ( "b" ) ) ;
264+ ui. add ( Slider :: new ( & mut lock. c , 0.0 ..=2.0 ) . text ( "c" ) ) ;
258265 } ) ;
259266
260267 // The gui isn't the correct call for this, but there's no other place right now
0 commit comments