I've come up with an algorithm that determines a kind of 'average factor' for left and right in blocks of 1 minute of audio. Here's the result of Grawk's realistic sample of 4 minutes of a SPDR recorder:
=== Block 0 AvgAfterCleanupLeft= 7.78647 ( -17.8268 dB ) AvgAfterCleanupRight= 7.8069 ( -17.8496 dB)
=== Block 1 AvgAfterCleanupLeft= 7.78781 ( -17.8283 dB ) AvgAfterCleanupRight= 7.80856 ( -17.8514 dB)
=== Block 2 AvgAfterCleanupLeft= 7.79205 ( -17.833 dB ) AvgAfterCleanupRight= 7.80805 ( -17.8509 dB)
=== Block 3 AvgAfterCleanupLeft= 7.7921 ( -17.8331 dB ) AvgAfterCleanupRight= 7.80762 ( -17.8504 dB)
The algorithm works like this:
1. Read 1 minute of audio from main and safety track
2. Go through each 'frame' (= set of left/right main sample and left/right safety sample). Process left and right separately in the next steps
3. If both main & safety samples are positive or both are negative, and if both have 'substantial magnitude' (> -80dBFS, to prevent using very noisy samples) and if neither is 'too loud' (< -3dBFS, to prevent using clipping samples and damaged samples from analog overloading):
- Calculate factor main/safety. This is 'the factor' for this single set of samples
- Truncate the factor to 4 digits behind the decimal separator.
- Put the value in a map, counting the number of occurences per value
4. Then, using the value that occured most in the minute of audio:
- Calculate a weighted average of all values in the map that are within 1% of the value that occured most. (Using 'value * times of occurence' of all map entries within that 1% window) This will be 'the factor' for this channel for this minute!
5. Process next minute of audio
I'm sure there will be better and more efficient ways to achieve this, but I think this should result in a reasonably accurate factor between main and safety track for that minute of audio.
Next, I can calculate 'the factor' for any position within the file by doing linear interpolation of the 'factor per minute'. I'm curious what the results will be of this, but first I need to mow the lawn, hopefully for the last time this year before the winter kicks in
