Ejemplo n.º 1
0
    def run(self, musicbrainzid, fname):
        pitch = util.docserver_get_json(musicbrainzid,
                                        "pitch",
                                        "pitch",
                                        version="noguessunv")
        tonic = util.docserver_get_contents(musicbrainzid,
                                            self.tonicname,
                                            "tonic",
                                            version=self.tonicversion)
        tonic = float(tonic)

        nppitch = np.array(pitch)
        bpo = 64  # 256 pixel high image spanning 4 octaves = 64px/octave
        height = 255  # Height of the image
        drawpitch = self.normalise_pitch(nppitch[:, 1], tonic, bpo, height)
        packed_pitch = StringIO.StringIO()
        for p in drawpitch:
            packed_pitch.write(struct.pack("B", p))
        drawhist = self.get_histogram(drawpitch, 256, 1)

        bpo = 120  # 10 cents per bin (original resolution in melody calculation)
        max_value = bpo * 4  # 4 octaves
        simpitch = self.normalise_pitch(nppitch[:, 1], tonic, bpo, max_value)
        simhist = self.get_histogram(simpitch, max_value, 7)

        return {
            "packedpitch": packed_pitch.getvalue(),
            "normalisedpitch": drawpitch,
            "drawhistogram": drawhist,
            "normalisedhistogram": simhist
        }
Ejemplo n.º 2
0
def obtainPitchTonicForRaga(raganame, outputfolder):


        if not os.path.exists(outputfolder):
            os.makedirs(outputfolder)
        
        #get raga recording mapping
        ragaRecordings = obtainRagaRecordingMapping()
        print len(ragaRecordings.keys())
        
        for mbid in ragaRecordings[raganame]:
            pitchData = util.docserver_get_json(mbid,'pitch','pitch')
            tonic = float(util.docserver_get_contents(mbid,'ctonic','tonic'))
            HopSize = 196
            
            filename =util.docserver_get_filename(mbid,'mp3')
            
            shutil.copyfile(filename, outputfolder+ '/'+filename.split('/')[-1])
            
            filename = filename.split('/')[-1].split('.')[0]
            
            #TStamps = np.array(range(0,len(pitchData)))*np.float(HopSize)/44100.0
            
            #dump = np.array([TStamps, pitchData]).transpose()
            
            np.savetxt(outputfolder+ '/'+filename+'.pitch', pitchData, delimiter = "\t")
            
            np.savetxt(outputfolder+ '/'+filename+'.tonic', np.array([tonic]), delimiter = "\t")
Ejemplo n.º 3
0
    def calc_profile(self, raag, recordings, style):
        average = compmusic.extractors.similaritylib.raaga.Raaga(raag.name, "")
        pitches = []
        tonics = []
        for r in recordings:
            mbid = r.mbid
            try:
                pitch = util.docserver_get_json(mbid, "pitch", "pitch")
                tonic = util.docserver_get_contents(mbid, "votedtonic", "tonic")
                tonic = float(tonic)
                npp = np.array(pitch)
                pitches.append(npp)
                tonics.append(tonic)
            except util.NoFileException:
                pass

        average.compute_average_hist_data(pitches, tonics)

        if style == "carnatic":
            entityname = "raaga"
        elif style == "hindustani":
            entityname = "raag"
        fname = "%s-%s-%s.png" % (style, entityname, raag.common_name.lower().replace(" ", ""))
        average.generate_image(fname)
        im = data.models.Image()
        raag.images.remove()
        im.image.save(fname, ContentFile(open(fname, "rb").read()))
        raag.images.add(im)
        os.unlink(fname)
Ejemplo n.º 4
0
    def calc_profile(self, raag, recordings, style):
        average = compmusic.extractors.similaritylib.raaga.Raaga(raag.name, "")
        pitches = []
        tonics = []
        for r in recordings:
            mbid = r.mbid
            try:
                pitch = util.docserver_get_json(mbid, "pitch", "pitch")
                tonic = util.docserver_get_contents(mbid, "votedtonic",
                                                    "tonic")
                tonic = float(tonic)
                npp = np.array(pitch)
                pitches.append(npp)
                tonics.append(tonic)
            except util.NoFileException:
                pass

        average.compute_average_hist_data(pitches, tonics)

        if style == "carnatic":
            entityname = "raaga"
        elif style == "hindustani":
            entityname = "raag"
        fname = "%s-%s-%s.png" % (style, entityname,
                                  raag.common_name.lower().replace(" ", ""))
        average.generate_image(fname)
        im = data.models.Image()
        im.image.save(fname, ContentFile(open(fname, "rb").read()))
        raag.image = im
        raag.save()
        os.unlink(fname)
Ejemplo n.º 5
0
    def calc_profile(self, raag, recordings):
        average = raaga.Raaga(raag.name, "")
        pitches = []
        tonics = []
        for r in recordings:
            mbid = r.mbid
            try:
                pitch = util.docserver_get_json(mbid, "pitch", "pitch")
                tonic = util.docserver_get_contents(mbid, "votedtonic", "tonic")
                tonic = float(tonic)
                npp = np.array(pitch)
                pitches.append(npp)
                tonics.append(tonic)
            except util.NoFileException:
                pass


        average.compute_average_hist_data(pitches, tonics)

        fname = "hindustani-raag-%s.png" % raag.common_name.lower().replace(" ", "")
        average.generate_image(fname)
        im = data.models.Image()
        raag.images.remove()
        im.image.save(fname, ContentFile(open(fname, "rb").read()))
        raag.images.add(im)
        os.unlink(fname)
Ejemplo n.º 6
0
    def run(self, fname):
        pitch = util.docserver_get_json(self.musicbrainz_id, "pitch", "pitch", version="noguessunv")
        tonic = util.docserver_get_contents(self.musicbrainz_id, "votedtonic", "tonic", version="0.2")
        tonic = float(tonic)

        nppitch = np.array(pitch)
        bpo = 64 # 256 pixel high image spanning 4 octaves = 64px/octave
        height = 255 # Height of the image
        drawpitch = self.normalise_pitch(nppitch[:,1], tonic, bpo, height)
        packed_pitch = StringIO.StringIO()
        for p in drawpitch:
            packed_pitch.write(struct.pack("B", p))
        drawhist = self.get_histogram(drawpitch, 256, 1)

        bpo = 120 # 10 cents per bin (original resolution in melody calculation)
        max_value = bpo * 4 # 4 octaves
        simpitch = self.normalise_pitch(nppitch[:,1], tonic, bpo, max_value)
        simhist = self.get_histogram(simpitch, max_value, 7)

        return {"packedpitch": packed_pitch.getvalue(),
                "normalisedpitch": drawpitch,
                "drawhistogram": drawhist,
                "normalisedhistogram": simhist}
Ejemplo n.º 7
0
 def calc_profile(self, raag, recordings):
     average = compmusic.extractors.similaritylib.raaga.Raaga(raag.name, "")
     pitches = []
     tonics = []
     for r in recordings:
         mbid = r.mbid
         try:
             pitch = util.docserver_get_json(mbid, "pitch", "pitch")
             tonic = util.docserver_get_contents(mbid, "votedtonic", "tonic")
             try:
                 tonic = float(tonic)
                 npp = np.array(pitch)
                 pitches.append(npp)
                 tonics.append(tonic)
             except ValueError:
                 pass
         except util.NoFileException:
             pass
     average.compute_average_hist_data(pitches, tonics)
     profile = average.average_hist[:, 0]
     y = np.concatenate((profile[-50:], profile[:-50]))
     y = gaussian_filter(y, 7)
     return y.tolist()