Пример #1
0
    def __init__(self,file_path,transpose='No',freqref=300):
        """Create the melodia object.

        Args:
            A path to a list of frequencies (f0) in a .txt file.

        Attributes:
            All attributes from music22.core.f0file.
            clean_freqs (numpy.ndarray): The list of frequencies without Zeros neither NaNs.
            pdf (numpy.ndarray): The Probability Density Function on the range 0-500 Hz.
            xpeaks, xpeaks (numpy.ndarray): the Peaks of the PDF and their values.
            ordredpeaks (pandas.core.frame.DataFrame): The Peaks ordered by their probability.
            dominante (numpy.float64): the dominant frequency.
            intervals (pandas.core.series.Series): the list of intervals in the choosen Unit (default is `savarts`).
            scale (list): the Scale from the Dominant, compared to reference epimoric intervals.
            pdf_show (matplotlibfigure): the PDF plot with peaks.

        Example:
            >>> import music22.modalis
            >>> file = '/Users/anas/AUDIO/Barraq/P1.wav'
            >>> Barraq = music22.modalis.melodia(file)
            Instance created with the txt file : P1.wav
            Instance created with the txt file : P1.txt
            The detected tonic is 167.696 Hz.
            >>> Barraq.file.basename
            'P1.txt'
            >>> Barraq.freqs
            array([ nan,  nan,  nan, ...,  nan,  nan,  nan])
            >>> Barraq.clean_freqs
            array([ 155.564,  157.372,  160.123, ...,  159.201,  158.284,  156.466])
            >>> Barraq.tonique
            167.696
            >>> Barraq.pdf
            array([  1.55304474e-33,   5.65209492e-33,   2.03065388e-32,
                     7.20217980e-32,   2.52170476e-31,   8.71620406e-31,
                     [...]
                     8.53621504e-26,   2.80105445e-26,   9.07308675e-27,
                     2.90111852e-27,   9.15698236e-28])
            >>> Barraq.pdf_show
            <bound method melodia.pdf_show of <music22.modalis.melodia object at 0x102a32910>>
            >>> Barraq.ordredpeaks
                   xpeaks    ypeaks
            1  243.486974  0.012244
            0  201.402806  0.007772
            3  324.649299  0.003007
            2  278.557114  0.002709
            4  375.751503  0.000785
        """
        file = core.file(file_path)
        if file.extension == 'wav':
            self.file = core.wavfile(file_path)
            txt_file = self.file.dirname+'/f0/'+self.file.name+'.txt'
            if not os.path.isfile(txt_file):
                self.file.pitch_extract()
            self.file = core.f0file(txt_file)
        elif file.extension == 'txt':
            self.file = core.f0file(file_path)

        self.name = self.file.name
        self.file.get_data()
        self.file.clean_data()

        if transpose=="No":
            self.freqs = self.file.data
            self.clean_freqs = self.file.clean_data
        if transpose=="Yes":
            self.freqs = transmode(self.file.data,freqref)
            self.clean_freqs = transmode(self.file.clean_data,freqref)

        self.xmin = numpy.min(self.clean_freqs)
        self.xmax = numpy.max(self.clean_freqs)

        self.mode = mode(self.clean_freqs)[0]

        self.get_tonique()

        self.pdf = scale.kde(self.clean_freqs)
        self.xpeaks, self.ypeaks = scale.peaks(self.pdf)
        self.ordredpeaks = scale.order_peaks(self.xpeaks,self.ypeaks)
        self.dominante = self.ordredpeaks['xpeaks'].iloc[0]

        self.get_scale()
Пример #2
0
 def pdf_show(self):
     """Show the pdf."""
     self.pdf = scale.kde(self.clean_freqs)
     scale.pdf_show(self.pdf,self.xpeaks,self.ypeaks,label=self.name)