@@ -70,6 +70,8 @@ pub struct Sender<T> {
70
70
output_patch : Arc < AtomicUsize > ,
71
71
/// The playback volume (rw)
72
72
volume : Arc < AtomicPtr < Parameter < f32 > > > ,
73
+ /// The master playback volume (rw)
74
+ master_vol : Arc < AtomicPtr < Parameter < f32 > > > ,
73
75
/// The buffer to write to (or not) - will be a `bounded_spsc_queue::Producer<f32>` or `()`.
74
76
pub buf : T ,
75
77
/// The sample rate of this sender. Can differ from the output sample rate.
@@ -104,20 +106,39 @@ impl<T> Sender<T> {
104
106
self . set_start_time ( time) ;
105
107
self . set_active ( true ) ;
106
108
}
109
+ pub fn set_master_volume ( & mut self , vol : Box < Parameter < f32 > > ) {
110
+ let val = Box :: into_raw ( vol) ;
111
+ let old_ptr = self . master_vol . swap ( val, AcqRel ) ;
112
+ unsafe {
113
+ let _: Box < Parameter < f32 > > = Box :: from_raw ( old_ptr) ;
114
+ }
115
+ }
116
+ pub fn master_volume ( & self ) -> Parameter < f32 > {
117
+ let ret;
118
+ unsafe {
119
+ let val = self . master_vol . load ( Acquire ) ;
120
+ ret = ( * val) . clone ( ) ;
121
+ self . master_vol . store ( val, Release ) ;
122
+ }
123
+ ret
124
+ }
107
125
/// Set the volume of this stream.
108
126
pub fn set_volume ( & mut self , vol : Box < Parameter < f32 > > ) {
109
127
let val = Box :: into_raw ( vol) ;
110
- let old_ptr = self . volume . swap ( val, Relaxed ) ;
128
+ let old_ptr = self . volume . swap ( val, AcqRel ) ;
111
129
unsafe {
112
130
let _: Box < Parameter < f32 > > = Box :: from_raw ( old_ptr) ;
113
131
}
114
132
}
115
133
/// Get the volume of this stream.
116
- pub fn volume ( & self ) -> & Parameter < f32 > {
117
- let val = self . volume . load ( Relaxed ) ;
134
+ pub fn volume ( & self ) -> Parameter < f32 > {
135
+ let ret ;
118
136
unsafe {
119
- & * val
137
+ let val = self . volume . load ( Acquire ) ;
138
+ ret = ( * val) . clone ( ) ;
139
+ self . volume . store ( val, Release ) ;
120
140
}
141
+ ret
121
142
}
122
143
/// Get whether this stream will play samples or not.
123
144
pub fn active ( & self ) -> bool {
@@ -174,6 +195,7 @@ impl<T> Sender<T> {
174
195
start_time : self . start_time . clone ( ) ,
175
196
output_patch : self . output_patch . clone ( ) ,
176
197
volume : self . volume . clone ( ) ,
198
+ master_vol : self . master_vol . clone ( ) ,
177
199
buf : ( ) ,
178
200
sample_rate : self . sample_rate ,
179
201
original : false ,
@@ -289,7 +311,9 @@ impl EngineContext {
289
311
let position = Arc :: new ( AtomicU64 :: new ( 0 ) ) ;
290
312
let start_time = Arc :: new ( AtomicU64 :: new ( 0 ) ) ;
291
313
let default_volume = Box :: new ( Parameter :: Raw ( 1.0 ) ) ;
314
+ let default_master_vol = default_volume. clone ( ) ;
292
315
let volume = Arc :: new ( AtomicPtr :: new ( Box :: into_raw ( default_volume) ) ) ;
316
+ let master_vol = Arc :: new ( AtomicPtr :: new ( Box :: into_raw ( default_master_vol) ) ) ;
293
317
let output_patch = Arc :: new ( AtomicUsize :: new ( :: std:: usize:: MAX ) ) ;
294
318
let uu = Uuid :: new_v4 ( ) ;
295
319
@@ -302,6 +326,7 @@ impl EngineContext {
302
326
alive : alive. clone ( ) ,
303
327
output_patch : output_patch. clone ( ) ,
304
328
volume : volume. clone ( ) ,
329
+ master_vol : master_vol. clone ( ) ,
305
330
uuid : uu,
306
331
half_sent : false ,
307
332
empty_sent : false
@@ -316,6 +341,7 @@ impl EngineContext {
316
341
start_time : start_time,
317
342
sample_rate : sample_rate,
318
343
volume : volume. clone ( ) ,
344
+ master_vol : master_vol. clone ( ) ,
319
345
original : true ,
320
346
uuid : uu
321
347
}
0 commit comments