コード例 #1
0
    def pitch2midiPyinMonoNoteOut(self, monoNoteOut_filename,monoNoteOutMidi_filename):

        '''
        read note pitch and convert to midi note
        :param monoNoteOut_filename:
        :return: noteStartingTime, noteDurationTime
        '''

        monoNoteOut = np.loadtxt(monoNoteOut_filename,delimiter=',',usecols=[1,2,3])
        noteStartingTime = monoNoteOut[:,0]
        noteDurTime = monoNoteOut[:,1]
        notePitch = monoNoteOut[:,2]
        notePitchMidi = pitch2midi(notePitch)

        with open(monoNoteOutMidi_filename, 'w+') as outfile:
            outfile.write('startTime'+','
                            +'pitch'+','
                            +'freq'+','
                            +'duration'+','
                            +'noteStr'+'\n')
            for ii in range(len(noteStartingTime)):
                noteCents = hz2cents(float(notePitch[ii]))
                noteStr = cents2pitch(noteCents)
                outfile.write(str(noteStartingTime[ii])+','
                            +str(notePitchMidi[ii])+','
                            +str(notePitch[ii])+','
                            +str(noteDurTime[ii])+','
                            +noteStr+'\n')

        return noteStartingTime, noteDurTime, notePitch, notePitchMidi
コード例 #2
0
 def writeRegressionPitchtrack(self,originalPitchtrackFilename,regressionPitchtrackFilename,representation):
     '''
     write regression pitch track
     :param originalPitchtrackFilename:
     :param regressionPitchtrackFilename:
     :param representation:
     :return:
     '''
     if regressionPitchtrackFilename:
         with open(regressionPitchtrackFilename, 'w+') as outfile:
             #  non-voice insertion
             representationNpArray = np.array(representation)
             # maxIndexRepresentation = max(representationNpArray[:,0])
             frameStartingTime, originalPitchtrack = self.ptSeg1.readPyinPitchtrack(originalPitchtrackFilename)
             lenFrame = len(frameStartingTime)
             wholeIndex = range(2,int(lenFrame)+1)                               #  sonicVisualizer Index start from 2
             outfile.write('frame'+','+'time'+','+'pitch'+','+'freq'+','+'noteStr'+'\n')
             for wi in wholeIndex:
                 if wi in representationNpArray[:,0]:
                     wiIndex = np.where(representationNpArray[:,0]==wi)[0][0]
                     value = representationNpArray[wiIndex,1]                    #  if value is in regression pitchtrack
                     freq = uf.midi2pitch(value)
                     noteStr = uf.cents2pitch(uf.hz2cents(float(freq)))
                 else:
                     value = -100.0                                              #  if value is NOT in regression pitchtrack
                     freq = -100.0
                     noteStr = 'null'
                 outfile.write(str(wi)+','
                             +str(wi*float(self.nc1.hopsize)/self.nc1.samplerate)+','
                             +str(value)+','
                             +str(freq)+','
                             +noteStr+'\n')
コード例 #3
0
    def writeRegressionPitchtrack(self,originalPitchtrackFilename,regressionPitchtrackFilename,representation):
        '''
        write regression pitch track
        :param originalPitchtrackFilename:
        :param regressionPitchtrackFilename:
        :param representation:
        :return:
        '''
        if regressionPitchtrackFilename:
            with open(regressionPitchtrackFilename, 'w+') as outfile:
                #  non-voice insertion
                representationNpArray = np.array(representation)
                # maxIndexRepresentation = max(representationNpArray[:,0])
                frameStartingTime, originalPitchtrack = self.ptSeg1.readPyinPitchtrack(originalPitchtrackFilename)
                lenFrame = len(frameStartingTime)
                wholeIndex = range(2,int(lenFrame)+1)
                outfile.write('frame'+','+'time'+','+'pitch'+','+'freq'+','+'noteStr'+'\n') 
                for wi in wholeIndex:
                    if wi in representationNpArray[:,0]:
                        wiIndex = np.where(representationNpArray[:,0]==wi)[0][0]
                        value = representationNpArray[wiIndex,1]                    #  if value is in regression pitchtrack
                   	freq = uf.midi2pitch(value)
			noteStr = uf.cents2pitch(uf.hz2cents(float(freq)))
		    else:
                        value = -100.0                                              #  if value is NOT in regression pitchtrack
                    	freq = -100.0
			noteStr = 'null'
		    outfile.write(str(wi)+','
                                +str(wi*float(self.nc1.hopsize)/self.nc1.samplerate)+','
                                +str(value)+','
				+str(freq)+','
				+noteStr+'\n')
コード例 #4
0
ファイル: pitchtrackSegByNotes.py プロジェクト: MTG/smc-2016
    def pitch2midiPyinMonoNoteOut(self, monoNoteOut_filename, monoNoteOutMidi_filename):

        """
        read note pitch and convert to midi note
        :param monoNoteOut_filename:
        :return: noteStartingTime, noteDurationTime
        """

        monoNoteOut = np.loadtxt(monoNoteOut_filename, delimiter=",", usecols=[1, 2, 3])
        noteStartingTime = monoNoteOut[:, 0]
        noteDurTime = monoNoteOut[:, 1]
        notePitch = monoNoteOut[:, 2]
        notePitchMidi = pitch2midi(notePitch)

        with open(monoNoteOutMidi_filename, "w+") as outfile:
            outfile.write("startTime" + "," + "pitch" + "," + "freq" + "," + "duration" + "," + "noteStr" + "\n")
            for ii in range(len(noteStartingTime)):
                noteCents = hz2cents(float(notePitch[ii]))
                noteStr = cents2pitch(noteCents)
                outfile.write(
                    str(noteStartingTime[ii])
                    + ","
                    + str(notePitchMidi[ii])
                    + ","
                    + str(notePitch[ii])
                    + ","
                    + str(noteDurTime[ii])
                    + ","
                    + noteStr
                    + "\n"
                )

        return noteStartingTime, noteDurTime, notePitch, notePitchMidi