Fixed loading of pre-made analyses

This commit is contained in:
2016-04-13 17:39:06 +01:00
parent cc67314751
commit 54f9a1044b
18 changed files with 105 additions and 60 deletions
+6 -6
View File
@@ -27,7 +27,7 @@ class Analysis(object):
through the currently implemented descriptors.
"""
def __init__(self, AnalysedAudioFile, analysis_group, name, config=None):
def __init__(self, AnalysedAudioFile, frames, analysis_group, name, config=None):
# Create object logger
self.logger = logging.getLogger(__name__ + '.{0}Analysis'.format(name))
# Store AnalysedAudioFile object to be analysed.
@@ -44,10 +44,10 @@ class Analysis(object):
"""
try:
self.analysis = self.analysis_group.create_group(self.name)
except ValueError:
self.logger.info("{0} analysis group already exists".format(self.name))
self.analysis = self.analysis_group[self.name]
except KeyError:
self.logger.info("{0} analysis group already exists".format(self.name))
self.analysis = self.analysis_group.create_group(self.name)
# If forcing new analysis creation then delete old analysis and create
# a new one
@@ -61,12 +61,12 @@ class Analysis(object):
# be saved in the HDF5 file
data_dict, attrs_dict = self.hdf5_dataset_formatter(*args, **kwargs)
for key, value in data_dict.iteritems():
self.analysis.create_dataset(key, data=value)
self.analysis.create_dataset(key, data=value, chunks=True)
for key, value in attrs_dict.iteritems():
self.analysis.attrs[key] = value
else:
if self.analysis.items():
if self.analysis.keys():
self.logger.info("Analysis already exists. Reading from: "
"{0}".format(self.analysis.name))
else:
+7 -3
View File
@@ -34,14 +34,13 @@ class CentroidAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(CentroidAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'Centroid')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(CentroidAnalysis, self).__init__(AnalysedAudioFile, frames, analysis_group, 'Centroid')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
self.analysis_group = analysis_group
frames = self.AnalysedAudioFile.read_grain()
self.logger.info("Creating Centroid analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(frames)
@@ -53,6 +52,9 @@ class CentroidAnalysis(Analysis):
Calculate the Centroid values of windowed segments of the audio file and
save to disk.
"""
if hasattr(frames, '__call__'):
frames = frames()
# Calculate the period of the window in hz
# lowest_freq = 1.0 / window_size
# Filter frequencies lower than the period of the window
@@ -100,6 +102,8 @@ class CentroidAnalysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = centroidframes.shape[0]
# Create array ranging from 0 to number of time frames
+11 -5
View File
@@ -30,8 +30,8 @@ class F0Analysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(F0Analysis, self).__init__(AnalysedAudioFile, analysis_group, 'F0')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(F0Analysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'F0')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
@@ -41,12 +41,13 @@ class F0Analysis(Analysis):
if config:
self.window_size = config.f0["window_size"]
self.overlap = 1. / config.f0["overlap"]
self.threshold = config.f0["ratio_threshold"]
else:
self.window_size=512
self.overlap = 0.5
self.threshold = 0.
self.analysis_group = analysis_group
frames = self.AnalysedAudioFile.read_grain()
self.logger.info("Creating F0 analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(
@@ -69,6 +70,9 @@ class F0Analysis(Analysis):
start = start / 1000
end = end / 1000
vtimes = times.reshape(-1, 1)
nan_inds = hr < self.threshold
hr[nan_inds] = np.nan
frames[nan_inds] = np.nan
selection = np.transpose((vtimes >= start) & (vtimes <= end))
if not selection.any():
@@ -94,6 +98,8 @@ class F0Analysis(Analysis):
Calculate the frequency and harmonic ratio values of windowed segments
of the audio file and save to disk.
"""
if hasattr(frames, '__call__'):
frames = frames()
if not M:
M=int(round(0.016*samplerate))
@@ -202,8 +208,6 @@ class F0Analysis(Analysis):
samplerate/2))
if HR >= 1:
HR = 1
if HR < threshold:
HR = np.nan
return (f0, HR)
output = np.apply_along_axis(per_frame_f0, 1, frames, m0, M)
@@ -232,6 +236,8 @@ class F0Analysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = f0frames.shape[0]
# Create array ranging from 0 to number of time frames
+12 -2
View File
@@ -24,12 +24,17 @@ class F0HarmRatioAnalysis(Analysis):
this object.
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(F0HarmRatioAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'F0HarmRatio')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(F0HarmRatioAnalysis, self).__init__(AnalysedAudioFile, frames, analysis_group, 'F0HarmRatio')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
if config:
self.threshold = config.f0["ratio_threshold"]
else:
self.threshold = 0.
self.analysis_group = analysis_group
self.logger.info("Initialising F0HarmRatio analysis for {0}".format(self.AnalysedAudioFile.name))
@@ -45,6 +50,9 @@ class F0HarmRatioAnalysis(Analysis):
end = end / 1000
vtimes = times.reshape(-1, 1)
nan_inds = hr < self.threshold
hr[nan_inds] = np.nan
selection = np.transpose((vtimes >= start) & (vtimes <= end))
if not selection.any():
frame_center = start + (end-start)/2.
@@ -59,6 +67,8 @@ class F0HarmRatioAnalysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
samplerate *= 1
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = F0HarmRatioframes.shape[0]
# Create array ranging from 0 to number of time frames
+8 -5
View File
@@ -33,8 +33,8 @@ class FFTAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(FFTAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'FFT')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(FFTAnalysis, self).__init__(AnalysedAudioFile, frames, analysis_group, 'FFT')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
@@ -45,21 +45,22 @@ class FFTAnalysis(Analysis):
window_size = 2048
self.analysis_group = analysis_group
self.logger.info("Creating FFT analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(window_size=window_size)
self.create_analysis(frames, window_size=window_size)
self.fft_window_count = None
def create_fft_analysis(self, window_size=512, window_overlap=2,
def create_fft_analysis(self, frames, window_size=512, window_overlap=2,
window_type='hanning'):
"""Create a spectral analysis for overlapping frames of audio."""
if hasattr(frames, '__call__'):
frames = frames()
# Calculate the period of the window in hz
lowest_freq = 1.0 / window_size
# Filter frequencies lower than the period of the window
# filter = ButterFilter()
# filter.design_butter(lowest_freq, self.AnalysedAudioFile.samplerate)
frames = self.AnalysedAudioFile.read_grain()
# frames = filter.filter_butter(frames)
stft = self.stft(frames, window_size, overlapFac=1/window_overlap)
frame_times = self.calc_fft_frame_times(
@@ -219,6 +220,8 @@ class FFTAnalysis(Analysis):
def calc_fft_frame_times(self, fftframes, sample_frames, samplerate):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins, freqbins = np.shape(fftframes)
# Create array ranging from 0 to number of time frames
+6 -3
View File
@@ -30,8 +30,8 @@ class KurtosisAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(KurtosisAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'kurtosis')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(KurtosisAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'kurtosis')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
@@ -47,7 +47,6 @@ class KurtosisAnalysis(Analysis):
"analysis.")
self.analysis_group = analysis_group
frames = self.AnalysedAudioFile.read_grain()
self.logger.info("Creating kurtosis analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(frames, variance.analysis['frames'][:], self.window_size, overlapFac=self.overlap)
@@ -63,6 +62,8 @@ class KurtosisAnalysis(Analysis):
Calculate the Kurtosis values of windowed segments of the audio file and
save to disk.
"""
if hasattr(frames, '__call__'):
frames = frames()
# Calculate the period of the window in hz
# lowest_freq = 1.0 / window_size
# Filter frequencies lower than the period of the window
@@ -115,6 +116,8 @@ class KurtosisAnalysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = kurtosisframes.shape[0]
# Create array ranging from 0 to number of time frames
+6 -3
View File
@@ -31,14 +31,13 @@ class PeakAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(PeakAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'Peak')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(PeakAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'Peak')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
self.analysis_group = analysis_group
frames = self.AnalysedAudioFile.read_grain()
self.logger.info("Creating Peak analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(frames)
@@ -50,6 +49,8 @@ class PeakAnalysis(Analysis):
Calculate the Peak values of windowed segments of the audio file and
save to disk.
"""
if hasattr(frames, '__call__'):
frames = frames()
# Calculate the period of the window in hz
# lowest_freq = 1.0 / window_size
# Filter frequencies lower than the period of the window
@@ -93,6 +94,8 @@ class PeakAnalysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = peakframes.shape[0]
# Create array ranging from 0 to number of time frames
+6 -3
View File
@@ -33,8 +33,8 @@ class RMSAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(RMSAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'RMS')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(RMSAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'RMS')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
@@ -47,7 +47,6 @@ class RMSAnalysis(Analysis):
self.overlap = 0.5
self.analysis_group = analysis_group
frames = self.AnalysedAudioFile.read_grain()
self.logger.info("Creating RMS analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(frames, self.AnalysedAudioFile.samplerate, window_size=self.window_size, overlapFac=self.overlap, )
@@ -65,6 +64,8 @@ class RMSAnalysis(Analysis):
Calculate the RMS values of windowed segments of the audio file and
save to disk.
"""
if hasattr(frames, '__call__'):
frames = frames()
def butter_lowpass(cutoff, fs, order=5):
# red: taken from http://stackoverflow.com/questions/25191620/creating-lowpass-filter-in-scipy-understanding-methods-and-units
nyq = 0.5 * fs
@@ -122,6 +123,8 @@ class RMSAnalysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = rmsframes.shape[0]
# Create array ranging from 0 to number of time frames
+6 -3
View File
@@ -30,8 +30,8 @@ class SkewnessAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(SkewnessAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'skewness')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(SkewnessAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'skewness')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
@@ -47,7 +47,6 @@ class SkewnessAnalysis(Analysis):
"analysis.")
self.analysis_group = analysis_group
frames = self.AnalysedAudioFile.read_grain()
self.logger.info("Creating skewness analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(frames, variance.analysis['frames'][:], self.window_size, overlapFac=self.overlap)
@@ -63,6 +62,8 @@ class SkewnessAnalysis(Analysis):
Calculate the skewness values of windowed segments of the audio file and
save to disk.
"""
if hasattr(frames, '__call__'):
frames = frames()
# Calculate the period of the window in hz
# lowest_freq = 1.0 / window_size
# Filter frequencies lower than the period of the window
@@ -114,6 +115,8 @@ class SkewnessAnalysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = skewnessframes.shape[0]
# Create array ranging from 0 to number of time frames
@@ -22,8 +22,8 @@ class SpectralCentroidAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(SpectralCentroidAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'SpcCntr')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(SpectralCentroidAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'SpcCntr')
# Create logger for module
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
@@ -39,7 +39,7 @@ class SpectralCentroidAnalysis(Analysis):
self.logger.info("Creating Spectral Centroid analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(
self.create_spccntr_analysis,
fft.analysis['frames'][:],
fft.analysis['frames'],
self.AnalysedAudioFile.samplerate
)
self.spccntr_window_count = None
@@ -62,6 +62,7 @@ class SpectralCentroidAnalysis(Analysis):
output_format = Choose either "freq" for output in Hz or "ind" for bin
index output
'''
fft = fft[:]
# Get the positive magnitudes of each bin.
magnitudes = np.abs(fft)
# Get the highest magnitude.
@@ -23,8 +23,8 @@ class SpectralCrestFactorAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(SpectralCrestFactorAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'SpcCrestFactor')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(SpectralCrestFactorAnalysis, self).__init__(AnalysedAudioFile, frames, analysis_group, 'SpcCrestFactor')
# Create logger for module
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
@@ -40,7 +40,7 @@ class SpectralCrestFactorAnalysis(Analysis):
self.logger.info("Creating Spectral CrestFactor analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(
self.create_spccf_analysis,
fft.analysis['frames'][:],
fft.analysis['frames'],
)
self.spccf_window_count = None
@@ -58,6 +58,7 @@ class SpectralCrestFactorAnalysis(Analysis):
'''
Calculate the spectral crest factor of the fft frames.
'''
fft = fft[:]
# Get the positive magnitudes of each bin.
magnitudes = np.abs(fft)
# Get highest magnitude
@@ -24,8 +24,8 @@ class SpectralFlatnessAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(SpectralFlatnessAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'SpcFlatness')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(SpectralFlatnessAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'SpcFlatness')
# Create logger for module
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
@@ -41,7 +41,7 @@ class SpectralFlatnessAnalysis(Analysis):
self.logger.info("Creating Spectral Flatness analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(
self.create_spcflatness_analysis,
fft.analysis['frames'][:],
fft.analysis['frames'],
)
self.spcflatness_window_count = None
@@ -59,6 +59,7 @@ class SpectralFlatnessAnalysis(Analysis):
'''
Calculate the spectral flatness of the fft frames.
'''
fft = fft[:]
# Get the positive magnitudes of each bin.
magnitudes = np.abs(fft)
if not np.nonzero(magnitudes)[0].size:
@@ -22,8 +22,8 @@ class SpectralFluxAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(SpectralFluxAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'SpcFlux')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(SpectralFluxAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'SpcFlux')
# Create logger for module
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
@@ -39,7 +39,7 @@ class SpectralFluxAnalysis(Analysis):
self.logger.info("Creating Spectral Flux analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(
self.create_spcflux_analysis,
fft.analysis['frames'][:],
fft.analysis['frames'],
)
self.spcflux_window_count = None
@@ -61,6 +61,7 @@ class SpectralFluxAnalysis(Analysis):
output_format = Choose either "freq" for output in Hz or "ind" for bin
index output
'''
fft = fft[:]
# Get the positive magnitudes of each bin.
magnitudes = np.abs(fft)
if not np.nonzero(magnitudes)[0].size:
@@ -22,8 +22,8 @@ class SpectralSpreadAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(SpectralSpreadAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'SpcSprd')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(SpectralSpreadAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'SpcSprd')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
@@ -42,8 +42,8 @@ class SpectralSpreadAnalysis(Analysis):
self.analysis_group = analysis_group
self.logger.info("Creating Spectral Spread analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(
fft.analysis['frames'][:],
spccntr.analysis['frames'][:],
fft.analysis['frames'],
spccntr.analysis['frames'],
self.AnalysedAudioFile.samplerate
)
self.spccntr_window_count = None
@@ -67,6 +67,8 @@ class SpectralSpreadAnalysis(Analysis):
length: the length of the window used to calculate the FFT.
samplerate: the samplerate of the audio analysed.
'''
fft = fft[:]
spectral_centroid = spectral_centroid[:]
# Get the positive magnitudes of each bin.
magnitudes = np.abs(fft)
mag_max = np.max(magnitudes)
+6 -3
View File
@@ -32,8 +32,8 @@ class VarianceAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(VarianceAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'variance')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(VarianceAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'variance')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
# Store reference to the file to be analysed
self.AnalysedAudioFile = AnalysedAudioFile
@@ -43,7 +43,6 @@ class VarianceAnalysis(Analysis):
self.overlap = 1. / config.variance["overlap"]
self.analysis_group = analysis_group
frames = self.AnalysedAudioFile.read_grain()
self.logger.info("Creating variance analysis for {0}".format(self.AnalysedAudioFile.name))
self.create_analysis(frames, self.window_size, overlapFac=self.overlap)
@@ -64,6 +63,8 @@ class VarianceAnalysis(Analysis):
# TODO: Fix filter
# frames = filter.filter_butter(frames)
if hasattr(frames, '__call__'):
frames = frames()
hopSize = int(window_size - np.floor(overlapFac * window_size))
# zeros at beginning (thus center of 1st window should be for sample nr. 0)
@@ -99,6 +100,8 @@ class VarianceAnalysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = varianceframes.shape[0]
# Create array ranging from 0 to number of time frames
+6 -3
View File
@@ -26,12 +26,11 @@ class ZeroXAnalysis(Analysis):
- config: The configuration module used to configure the analysis
"""
def __init__(self, AnalysedAudioFile, analysis_group, config=None):
super(ZeroXAnalysis, self).__init__(AnalysedAudioFile, analysis_group, 'ZeroCrossing')
def __init__(self, AnalysedAudioFile, frames, analysis_group, config=None):
super(ZeroXAnalysis, self).__init__(AnalysedAudioFile,frames, analysis_group, 'ZeroCrossing')
self.logger = logging.getLogger(__name__+'.{0}Analysis'.format(self.name))
self.analysis_group = analysis_group
self.logger.info("Creating zero crossing analysis for {0}".format(self.AnalysedAudioFile.name))
frames = self.AnalysedAudioFile.read_grain()
self.create_analysis(frames)
@staticmethod
@@ -43,6 +42,8 @@ class ZeroXAnalysis(Analysis):
**kwargs
):
"""Generate zero crossing value for window of the signal"""
if hasattr(frames, '__call__'):
frames = frames()
hopSize = int(window_size - np.floor(overlapFac * window_size))
# zeros at beginning (thus center of 1st window should be for sample nr. 0)
@@ -71,6 +72,8 @@ class ZeroXAnalysis(Analysis):
"""Calculate times for frames using sample size and samplerate."""
if hasattr(sample_frames, '__call__'):
sample_frames = sample_frames()
# Get number of frames for time and frequency
timebins = zerox_frames.shape[0]
# Create array ranging from 0 to number of time frames
+2 -4
View File
@@ -891,15 +891,13 @@ class AnalysedAudioFile(AudioFile):
]
self.analyses = defaultdict(None)
frames = self.read_grain
# Create the analysis objects for analyses that have been specified in
# the analyses member variable.
for analysis in analysis_object_list:
if analysis.name in self.available_analyses:
self.analyses[analysis.name] = analysis.analysis_object(self, self.analysis_storage, config=self.config)
self.analysis_storage.file.flush()
gc.collect()
self.analyses[analysis.name] = analysis.analysis_object(self, frames, self.analysis_storage, config=self.config)
def create_analysis_group(self, analysis_file):
"""
+1 -1
View File
@@ -7,7 +7,7 @@ rms = {
f0 = {
"window_size": 2048,
"overlap": 8,
"ratio_threshold": 0.4
"ratio_threshold": 0.6
}
# Specify analysis parameters for variance analysis.