pytimbre.spectral.timbral_model.timbral_models.TimbralFeatures¶
- class pytimbre.spectral.timbral_model.timbral_models.TimbralFeatures¶
Bases:
objectThis collection of code was extracted from the Timbral_model package. The code is refactored to use the PyTimbre classes to read/write the audio data. Rather than using a series of different files and individual functions, this will combine all required functions into a single file and class.
- __init__()¶
Methods
__init__()sharpness_Fastl(loudspec)Calculates the sharpness based on FASTL (1991) Expression for weighting function obtained by fitting an equation to data given in 'Psychoacoustics: Facts and Models' using MATLAB basic fitting function Original Matlab code by Claire Churchill Sep 2004 Transcoded by Andy Pearce 2018
timbral_brightness(fname[, fs, dev_output, ...])This function calculates the apparent Brightness of an audio file.
timbral_depth(fname[, fs, dev_output, ...])This function calculates the apparent Depth of an audio file.
timbral_hardness(fname[, fs, dev_output, ...])This function calculates the apparent hardness of an audio file.
timbral_warmth(fname[, dev_output, ...])This function estimates the perceptual Warmth of an audio file.
warm_region_cal(audio_samples, fs)Function for calculating various warmth parameters.
- static sharpness_Fastl(loudspec)¶
Calculates the sharpness based on FASTL (1991) Expression for weighting function obtained by fitting an equation to data given in ‘Psychoacoustics: Facts and Models’ using MATLAB basic fitting function Original Matlab code by Claire Churchill Sep 2004 Transcoded by Andy Pearce 2018
- static timbral_brightness(fname, fs=0, dev_output=False, clip_output=False, phase_correction=False, threshold=0, ratio_crossover=2000, centroid_crossover=100, stepSize=1024, blockSize=2048, minFreq=20)¶
This function calculates the apparent Brightness of an audio file. This version of timbral_brightness contains self loudness normalising methods and can accept arrays as an input instead of a string filename.
Version 0.4
- Required parameter
- param fname:
string or numpy array string, audio filename to be analysed, including full file path and extension. numpy array, array of audio samples, requires fs to be set to the sample rate.
- Optional parameters
- param fs:
int/float, when fname is a numpy array, this is a required to be the sample rate. Defaults to 0.
- param dev_output:
bool, when False return the brightness, when True return all extracted features.
- param clip_output:
bool, force the output to be between 0 and 100.
- param phase_correction:
bool, Perform phase checking before summing to mono.
- param threshold:
Threshold below which to ignore the energy in a time window, default to 0.
- param ratio_crossover:
Crossover frequency for calculating the HF energy ratio, default to 2000 Hz.
- param centroid_crossover:
Highpass frequency for calculating the spectral centroid, default to 100 Hz.
- param stepSize:
Step size for calculating spectrogram, default to 1024.
- param blockSize:
Block size (fft length) for calculating spectrogram, default to 2048.
- param minFreq:
Frequency for high-pass filtering audio prior to all analysis, default to 20 Hz.
- return:
Apparent brightness of audio file, float.
Copyright 2018 Andy Pearce, Institute of Sound Recording, University of Surrey, UK.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- static timbral_depth(fname, fs=0, dev_output=False, phase_correction=False, clip_output=False, threshold_db=-60, low_frequency_limit=20, centroid_crossover_frequency=2000, ratio_crossover_frequency=500, db_decay_threshold=-40)¶
This function calculates the apparent Depth of an audio file. This version of timbral_depth contains self loudness normalising methods and can accept arrays as an input instead of a string filename.
Version 0.4
- Required parameter
- param fname:
string or numpy array string, audio filename to be analysed, including full file path and extension. numpy array, array of audio samples, requires fs to be set to the sample rate.
- Optional parameters
- param fs:
int/float, when fname is a numpy array, this is a required to be the sample rate. Defaults to 0.
- param phase_correction:
bool, perform phase checking before summing to mono. Defaults to False.
- param dev_output:
bool, when False return the depth, when True return all extracted features. Default to False.
- param threshold_db:
float/int (negative), threshold, in dB, for calculating centroids. Should be negative. Defaults to -60.
- param low_frequency_limit:
float/int, low frequency limit at which to highpass filter the audio, in Hz. Defaults to 20.
- param centroid_crossover_frequency:
float/int, crossover frequency for calculating the spectral centroid, in Hz. Defaults to 2000
- param ratio_crossover_frequency:
float/int, crossover frequency for calculating the ratio, in Hz. Defaults to 500.
- param db_decay_threshold:
float/int (negative), threshold, in dB, for estimating duration. Should be negative. Defaults to -40.
- return:
float, aparent depth of audio file, float.
Copyright 2018 Andy Pearce, Institute of Sound Recording, University of Surrey, UK.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- static timbral_hardness(fname, fs=0, dev_output=False, phase_correction=False, clip_output=False, max_attack_time=0.1, bandwidth_thresh_db=-75)¶
This function calculates the apparent hardness of an audio file. This version of timbral_hardness contains self loudness normalising methods and can accept arrays as an input instead of a string filename.
Version 0.4
- Required parameter
- param fname:
string or numpy array string, audio filename to be analysed, including full file path and extension. numpy array, array of audio samples, requires fs to be set to the sample rate.
- Optional parameters
- param fs:
int/float, when fname is a numpy array, this is a required to be the sample rate. Defaults to 0.
- param phase_correction:
bool, perform phase checking before summing to mono. Defaults to False.
- param dev_output:
bool, when False return the depth, when True return all extracted features. Default to False.
- param clip_output:
bool, force the output to be between 0 and 100.
- param max_attack_time:
float, set the maximum attack time, in seconds. Defaults to 0.1.
- param bandwidth_thresh_db:
float, set the threshold for calculating the bandwidth, Defaults to -75dB.
- return:
float, Apparent hardness of audio file, float (dev_output = False/default). With dev_output set to True returns the weighted mean bandwidth, mean attack time, harmonic-percussive ratio, and unitless attack centroid.
Copyright 2018 Andy Pearce, Institute of Sound Recording, University of Surrey, UK.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- static timbral_warmth(fname, dev_output=False, phase_correction=False, clip_output=False, max_FFT_frame_size=8192, max_WR=12000, fs=0)¶
This function estimates the perceptual Warmth of an audio file.
This model of timbral_warmth contains self loudness normalising methods and can accept arrays as an input instead of a string filename.
Version 0.4
Required parameter
- Parameters:
fname – string, Audio filename to be analysed, including full file path and extension.
Optional parameters :param dev_output: bool, when False return the warmth, when True return all extracted features in a
list.
- Parameters:
phase_correction – bool, if the inter-channel phase should be estimated when performing a mono sum. Defaults to False.
max_FFT_frame_size – int, Frame size for calculating spectrogram, default to 8192.
max_WR – float, maximun allowable warmth region frequency, defaults to 12000.
- Returns:
Estimated warmth of audio file.
Copyright 2018 Andy Pearce, Institute of Sound Recording, University of Surrey, UK.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- static warm_region_cal(audio_samples, fs)¶
Function for calculating various warmth parameters.
- Parameters:
audio_samples – numpy.array, an array of the audio samples, reques only one dimension.
fs – int, the sample ratr of the audio file.
- Returns:
four outputs: mean warmth region, weighted-average warmth region, mean high frequency level, weighted-average high frequency level.