@@ -40,6 +40,13 @@ struct rematrix_data {
40
40
uint8_t * tmpbuffer [MAX_AV_PLANES ];
41
41
//ensure we can treat it as a dynamic array
42
42
size_t size ;
43
+
44
+ //initialize once, optimize for fast use
45
+ volatile long long _ch_count [MAX_AV_PLANES ];
46
+ volatile double _gain [MAX_AV_PLANES ];
47
+ volatile float _mix [MAX_AV_PLANES ][MAX_AV_PLANES ];
48
+ volatile double _true_gain [MAX_AV_PLANES ];
49
+ //static volatile uint32_t _options[MAX_AV_PLANES];
43
50
};
44
51
45
52
/*****************************************************************************/
@@ -96,7 +103,7 @@ static void rematrix_update(void *data, obs_data_t *settings) {
96
103
for (long long j = 0 ; j < MAX_AV_PLANES ; j ++ ) {
97
104
sprintf (mix_name , mix_name_format , i , j );
98
105
mix [i ][j ] = (float )obs_data_get_double (settings , mix_name ) / SCALE ;
99
-
106
+
100
107
if (rematrix -> mix [i ][j ] != mix [i ][j ]) {
101
108
rematrix -> mix [i ][j ] = mix [i ][j ];
102
109
mix_changed = true;
@@ -148,13 +155,6 @@ static void *rematrix_create(obs_data_t *settings, obs_source_t *filter) {
148
155
static struct obs_audio_data * rematrix_filter_audio (void * data ,
149
156
struct obs_audio_data * audio ) {
150
157
151
- //initialize once, optimize for fast use
152
- static volatile long long ch_count [MAX_AV_PLANES ];
153
- static volatile double gain [MAX_AV_PLANES ];
154
- static volatile float mix [MAX_AV_PLANES ][MAX_AV_PLANES ];
155
- static volatile double true_gain [MAX_AV_PLANES ];
156
- static volatile uint32_t options [MAX_AV_PLANES ];
157
-
158
158
struct rematrix_data * rematrix = data ;
159
159
const size_t channels = rematrix -> channels ;
160
160
float * * fmatrixed_data = (float * * )rematrix -> tmpbuffer ;
@@ -163,21 +163,21 @@ static struct obs_audio_data *rematrix_filter_audio(void *data,
163
163
164
164
//prevent race condition
165
165
for (size_t c = 0 ; c < channels ; c ++ ) {
166
- ch_count [c ] = 0 ;
167
- gain [c ] = rematrix -> gain [c ];
166
+ rematrix -> _ch_count [c ] = 0 ;
167
+ rematrix -> _gain [c ] = rematrix -> gain [c ];
168
168
for (size_t c2 = 0 ; c2 < channels ; c2 ++ ) {
169
- mix [c ][c2 ] = rematrix -> mix [c ][c2 ];
169
+ rematrix -> _mix [c ][c2 ] = rematrix -> mix [c ][c2 ];
170
170
//use ch_count to "count" how many chs are in use
171
171
//for normalization
172
- if (mix [c ][c2 ] > 0 )
173
- ch_count [c ]++ ;
172
+ if (rematrix -> _mix [c ][c2 ] > 0 )
173
+ rematrix -> _ch_count [c ]++ ;
174
174
}
175
175
//when ch_count == 0.0 float returns +inf, making this division by 0.0 actually safe
176
- if (ch_count [c ] == 0.0 ) {
177
- true_gain [c ] = 0.0 ;
176
+ if (rematrix -> _ch_count [c ] == 0.0 ) {
177
+ rematrix -> _true_gain [c ] = 0.0 ;
178
178
}
179
179
else {
180
- true_gain [c ] = gain [c ] / ch_count [c ];
180
+ rematrix -> _true_gain [c ] = rematrix -> _gain [c ] / rematrix -> _ch_count [c ];
181
181
}
182
182
}
183
183
@@ -207,80 +207,81 @@ static struct obs_audio_data *rematrix_filter_audio(void *data,
207
207
//reset to 0
208
208
size_t c2 = 0 ;
209
209
for (; c2 < 1 ; c2 ++ ) {
210
- if (fdata [c ] && mix [c ][c2 ]) {
210
+ if (fdata [c ] && rematrix -> _mix [c ][c2 ]) {
211
211
size_t s = 0 ;
212
212
size_t end ;
213
213
/*
214
214
end = unprocessed_samples - 8;
215
215
for(; s < end; s+=8) {
216
- s256 = _mm256_load_ps(&fdata[c2][chunk + s]);
217
- m256 = _mm256_set1_ps(mix[c][c2]);//_mm256_load_ps(&mix[c][c2]);
218
- _mm256_store_ps(&fmatrixed_data[c][s], _mm256_mul_ps(s256, m256));
216
+ s256 = _mm256_load_ps(&fdata[c2][chunk + s]);
217
+ m256 = _mm256_set1_ps(mix[c][c2]);//_mm256_load_ps(&mix[c][c2]);
218
+ _mm256_store_ps(&fmatrixed_data[c][s], _mm256_mul_ps(s256, m256));
219
219
}
220
220
*/
221
221
end = unprocessed_samples - 4 ;
222
- for (; s < end ; s += 4 ) {
222
+ for (; s < end ; s += 4 ) {
223
223
s128 = _mm_load_ps (& fdata [c2 ][chunk + s ]);
224
- m128 = _mm_set1_ps (mix [c ][c2 ]);//_mm256_load_ps(&mix[c][c2]);
224
+ m128 = _mm_set1_ps (rematrix -> _mix [c ][c2 ]);//_mm256_load_ps(&mix[c][c2]);
225
225
_mm_store_ps (& fmatrixed_data [c ][s ], _mm_mul_ps (s128 , m128 ));
226
226
}
227
227
for (; s < unprocessed_samples ; s ++ ) {
228
- fmatrixed_data [c ][s ] = fdata [c2 ][chunk + s ] * mix [c ][c2 ];
228
+ fmatrixed_data [c ][s ] = fdata [c2 ][chunk + s ] * rematrix -> _mix [c ][c2 ];
229
229
}
230
- } else {
230
+ }
231
+ else {
231
232
memset (fmatrixed_data [c ], 0 , copy_size );
232
233
}
233
234
}
234
235
//memset(fmatrixed_data[c], 0, copy_size);
235
236
//add contributions
236
237
for (; c2 < channels ; c2 ++ ) {
237
- if (fdata [c ] && mix [c ][c2 ]) {
238
+ if (fdata [c ] && rematrix -> _mix [c ][c2 ]) {
238
239
size_t s = 0 ;
239
240
size_t end ;
240
241
/*
241
242
end = unprocessed_samples - 8;
242
243
for(; s < end; s+=8) {
243
- s256 = _mm256_load_ps(&fdata[c2][chunk + s]);
244
- t256 = _mm256_load_ps(&fmatrixed_data[c][s]);
245
- m256 = _mm256_set1_ps(mix[c][c2]);//_mm256_load_ps(&mix[c][c2]);
246
- _mm256_store_ps(&fmatrixed_data[c][s], _mm256_add_ps(t256, _mm256_mul_ps(s256, m256)));
244
+ s256 = _mm256_load_ps(&fdata[c2][chunk + s]);
245
+ t256 = _mm256_load_ps(&fmatrixed_data[c][s]);
246
+ m256 = _mm256_set1_ps(mix[c][c2]);//_mm256_load_ps(&mix[c][c2]);
247
+ _mm256_store_ps(&fmatrixed_data[c][s], _mm256_add_ps(t256, _mm256_mul_ps(s256, m256)));
247
248
}
248
249
*/
249
250
end = unprocessed_samples - 4 ;
250
- for (; s < end ; s += 4 ) {
251
+ for (; s < end ; s += 4 ) {
251
252
s128 = _mm_load_ps (& fdata [c2 ][chunk + s ]);
252
253
t128 = _mm_load_ps (& fmatrixed_data [c ][s ]);
253
- m128 = _mm_set1_ps (mix [c ][c2 ]);//_mm256_load_ps(&mix[c][c2]);
254
+ m128 = _mm_set1_ps (rematrix -> _mix [c ][c2 ]);//_mm256_load_ps(&mix[c][c2]);
254
255
_mm_store_ps (& fmatrixed_data [c ][s ], _mm_add_ps (t128 , _mm_mul_ps (s128 , m128 )));
255
256
}
256
257
for (; s < unprocessed_samples ; s ++ ) {
257
- fmatrixed_data [c ][s ] += fdata [c2 ][chunk + s ] * mix [c ][c2 ];
258
+ fmatrixed_data [c ][s ] += fdata [c2 ][chunk + s ] * rematrix -> _mix [c ][c2 ];
258
259
}
259
260
}
260
261
}
261
262
}
262
263
//move data into place and process gain
263
264
for (size_t c = 0 ; c < channels ; c ++ ) {
264
- if (!fdata [c ])
265
+ if (!fdata [c ])
265
266
continue ;
266
267
size_t s = 0 ;
267
268
size_t end ;
268
269
/*
269
270
end = unprocessed_samples - 8;
270
271
for(; s < end; s+=8){
271
- s256 = _mm256_load_ps(&(fmatrixed_data[c][s]));
272
- m256 = _mm256_set1_ps(true_gain[c]);
273
- _mm256_store_ps(&fdata[c][chunk + s], _mm256_mul_ps(s256, m256));
272
+ s256 = _mm256_load_ps(&(fmatrixed_data[c][s]));
273
+ m256 = _mm256_set1_ps(true_gain[c]);
274
+ _mm256_store_ps(&fdata[c][chunk + s], _mm256_mul_ps(s256, m256));
274
275
}
275
276
*/
276
277
end = unprocessed_samples - 4 ;
277
- for (; s < end ; s += 4 ) {
278
+ for (; s < end ; s += 4 ) {
278
279
s128 = _mm_load_ps (& (fmatrixed_data [c ][s ]));
279
- m128 = _mm_set1_ps (true_gain [c ]);
280
+ m128 = _mm_set1_ps (rematrix -> _true_gain [c ]);
280
281
_mm_store_ps (& fdata [c ][chunk + s ], _mm_mul_ps (s128 , m128 ));
281
282
}
282
283
for (; s < unprocessed_samples ; s ++ ) {
283
- fdata [c ][chunk + s ] = fmatrixed_data [c ][s ] * true_gain [c ];
284
+ fdata [c ][chunk + s ] = fmatrixed_data [c ][s ] * rematrix -> _true_gain [c ];
284
285
}
285
286
}
286
287
//move to next chunk of unprocessed data
@@ -370,11 +371,11 @@ static bool update_visible(obs_properties_t *props, obs_property_t *prop,
370
371
371
372
for (i = 0 ; i < channels ; i ++ ) {
372
373
sprintf (gain_name , gain_name_format , i );
373
-
374
+
374
375
visible = i == selected_ch ;
375
376
376
377
gain = obs_properties_get (props , gain_name );
377
- obs_property_set_visible (gain ,visible );
378
+ obs_property_set_visible (gain , visible );
378
379
379
380
for (j = 0 ; j < channels ; j ++ ) {
380
381
sprintf (mix_name , mix_name_format , i , j );
0 commit comments