@@ -47,19 +47,28 @@ bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, Audi
47
47
// And for muted we need to fill the buffer with zeroes otherwise it repeats the last frame
48
48
memset (outputData , 0 , totalSamples * sizeof (float ));
49
49
}
50
- // Grab the mix level parameter (with either a length of 1 or the samples
51
- // per channel) and add any other inputs
52
- const AudioParamFrame * mixLevel = & params [0 ];
50
+ // Grab the mix level parameter and expand it to have one entry per output
51
+ // sample. This simplifies the mixer and smooths out browser differences.
52
+ // Output and input buffers are stereo planar, so the mix data just repeats.
53
+ float * const mixLevel = alloca (totalSamples * sizeof (float ));
54
+ if (params [0 ].length > 1 ) {
55
+ // This is the regular path, one entry per sample by number of channels
56
+ for (int ch = outputs [0 ].numberOfChannels - 1 ; ch >= 0 ; ch -- ) {
57
+ memcpy (mixLevel + ch * outSamplesPerChannel , params [0 ].data , outSamplesPerChannel * sizeof (float ));
58
+ }
59
+ } else {
60
+ // Chrome will take this path when the k-rate parameter doesn't change
61
+ float singleLevel = params [0 ].data [0 ];
62
+ for (int n = totalSamples - 1 ; n >= 0 ; n -- ) {
63
+ mixLevel [n ] = singleLevel ;
64
+ }
65
+ }
66
+ // Now add another inputs with the mix level
53
67
for (int n = 1 ; n < numInputs ; n ++ ) {
54
68
if (inputs [n ].numberOfChannels > 0 ) {
55
69
float * inputData = inputs [n ].data ;
56
70
for (int i = totalSamples - 1 ; i >= 0 ; i -- ) {
57
- // Output and input buffers are stereo planar in this example so we
58
- // need to get a mixLevel->data[] per channel, hence the quick % (and
59
- // as noticed in the wild, implementations have either one or all
60
- // entries, regardless of the param spec we passed in)
61
- float mixLevelValue = mixLevel -> data [(mixLevel -> length > 1 ) ? (i % outSamplesPerChannel ) : 0 ];
62
- outputData [i ] += inputData [i ] * mixLevelValue ;
71
+ outputData [i ] += inputData [i ] * mixLevel [i ];
63
72
}
64
73
}
65
74
}
0 commit comments