예제 #1
0
class MonoNote(object):
    def __init__(self):
        self.hmm = MonoNoteHMM()

    def process(self, pitchProb):
        obsProb = [
            self.hmm.calculatedObsProb(pitchProb[0]),
        ]
        for iFrame in range(1, len(pitchProb)):
            obsProb += [self.hmm.calculatedObsProb(pitchProb[iFrame])]
        out = []

        path, scale = self.hmm.decodeViterbi(obsProb)

        for iFrame in range(len(path)):
            currPitch = -1.0
            stateKind = 0

            currPitch = self.hmm.par.minPitch + (
                path[iFrame] / self.hmm.par.nSPP) * 1.0 / self.hmm.par.nPPS
            stateKind = (path[iFrame]) % self.hmm.par.nSPP + 1

            out.append(FrameOutput(iFrame, currPitch, stateKind))

        return out
예제 #2
0
파일: MonoNote.py 프로젝트: xrick/pypYIN
    def __init__(self, STEPS_PER_SEMITONE, NUM_SEMITONES,
                 with_bar_dependent_probs, hopTime, usul_type):
        '''
        create hmm and build its transition matrix
        '''
        self.with_bar_dependent_probs = with_bar_dependent_probs
        self.hmm = MonoNoteHMM(STEPS_PER_SEMITONE, NUM_SEMITONES,
                               with_bar_dependent_probs, hopTime, usul_type)

        self.hmm.build_trans_probs(with_bar_dependent_probs)
        self.hmm.build_obs_model()
예제 #3
0
파일: MonoNote.py 프로젝트: gburlet/pypYIN
class MonoNote(object):

    def __init__(self):
        self.hmm = MonoNoteHMM()

    def process(self, pitchProb):
        obsProb = [self.hmm.calculatedObsProb(pitchProb[0]), ]
        for iFrame in range(1, len(pitchProb)):
            obsProb += [self.hmm.calculatedObsProb(pitchProb[iFrame])]
        out = []

        path, scale = self.hmm.decodeViterbi(obsProb)

        for iFrame in range(len(path)):
            currPitch = -1.0
            stateKind = 0

            currPitch = self.hmm.par.minPitch + (path[iFrame]/self.hmm.par.nSPP) * 1.0/self.hmm.par.nPPS
            stateKind = (path[iFrame]) % self.hmm.par.nSPP + 1

            out.append(FrameOutput(iFrame, currPitch, stateKind))

        return out
예제 #4
0
 def __init__(self):
     self.hmm = MonoNoteHMM()
예제 #5
0
파일: MonoNote.py 프로젝트: gburlet/pypYIN
 def __init__(self):
     self.hmm = MonoNoteHMM()
예제 #6
0
파일: MonoNote.py 프로젝트: xrick/pypYIN
class MonoNote(object):
    def __init__(self, STEPS_PER_SEMITONE, NUM_SEMITONES,
                 with_bar_dependent_probs, hopTime, usul_type):
        '''
        create hmm and build its transition matrix
        '''
        self.with_bar_dependent_probs = with_bar_dependent_probs
        self.hmm = MonoNoteHMM(STEPS_PER_SEMITONE, NUM_SEMITONES,
                               with_bar_dependent_probs, hopTime, usul_type)

        self.hmm.build_trans_probs(with_bar_dependent_probs)
        self.hmm.build_obs_model()

    def path_to_stepstates(self, path):
        '''
        convert path to a list of FrameOutput with 3 states : 1: attack, 2: sustain, 3: silence 
        '''
        out = []
        for iFrame in range(len(path)):
            currPitch = -1.0
            stateKind = 0
            currPitch = self.hmm.par.minPitch + (
                path[iFrame] / self.hmm.par.nSPP) * 1.0 / self.hmm.par.nPPS
            stateKind = (
                path[iFrame]
            ) % self.hmm.par.nSPP + 1  # 1: attack, 2: sustain, 3: silence
            out.append(FrameOutput(iFrame, currPitch, stateKind))

        return out

    def process(self, pitch_contour_and_prob, bar_position_ts, bar_labels,
                hop_time):
        '''
        compute obs. probabilities and decode with Viterbi
         
        Parameters
        ----------------------
        pitch_contour_and_prob
            pitch observation feature
        bar_position_ts: list
            timestamps of bar positions
        bar_labels: list
            labels of bar types corresponding to timestamps 
        '''

        obs_probs = self.hmm.calculatedObsProb(pitch_contour_and_prob)
        obs_probs = self.hmm.normalize_obs_probs(obs_probs,
                                                 pitch_contour_and_prob)
        obs_probs_T = obs_probs.T

        self.create_beatPositions(obs_probs_T, bar_position_ts, bar_labels,
                                  hop_time)
        path, _ = self.hmm.decodeViterbi(
            obs_probs_T)  # transpose to have time t as first dimension

        out = self.path_to_stepstates(path)

        return out

    def create_beatPositions(self, obs_probs_T, beat_position_ts, beat_labels,
                             hop_time):
        '''
        load beat annotaiton. and create beat position markers at frames  
        creates MonoNoteHMM.beatPositions: shape(time, 2); 
            dimension 0: one if no bar pos, else zero; 
            dimension 1: bar pos label (form 0 to num_beats in usul)
        '''
        nFrames = obs_probs_T.shape[0]
        self.hmm.beatPositions = np.zeros((nFrames, 2))  # create output
        for beat_pos_ts, beat_label in zip(beat_position_ts, beat_labels):
            iFrame = ts_to_frame(beat_pos_ts, hop_time)
            if iFrame >= nFrames - 1:
                logging.warning(
                    'bar position ts beyond duration of audio... ignoring')
                break
            self.hmm.beatPositions[iFrame, 0] = 1
            self.hmm.beatPositions[iFrame, 1] = int(beat_label) - 1