I'm doing some MIR related work with stereo audio and am a little unsure on how to proceed with some basic tasks. All my academic work prior to this has involved forcing audio to "mono" to perform analysis, and I'm trying to avoid that as much as possible here.
So, for example, I have a crest factor function in python that looks like this for an array of audio data (either mono, left, or right channel):
def get_cf(data, win_size):
"""
data: audio array in mono, left, or right channel only
win_size: size in samples for the block analysis (created in calc_crest_factor)
calc_crest_factor passes mono style data to this function to get the crest factor.
returns: the crest factor for each window"""
# Buffer the signal matrix-style (input, block-size, hop-size)
data_matrix = librosa.util.frame(data, win_size, win_size)
peaks = np.amax(np.absolute(data_matrix), axis=0)
# Get the mean-square over each window
RMS = np.sqrt(np.mean(np.square(data_matrix), axis=0))
# Get crest factor for each window
return np.divide(peaks, RMS)
In another function, I call the function above like so for stereo audio:
if len(data) == 2:
crest_factor_l = get_cf(data[0,:], win_size)
crest_factor_r = get_cf(data[1,:], win_size)
And here I now have a crest factor for the right channel and one for the left channel, but am unsure on how to proceed on getting a final "crest factor" value for the audio. Do I just choose the greater of the two values for each window? Or is it more correct to keep both values?
This same question goes for RMS too. I know in my pro audio applications, stereo audio gets passed to some RMS calculator and a single value gets pumped out. How do the two separate channels with two separate values for either Crest Factor or RMS become 1 value while honoring the "stereoness" of the data?