Ignore:
Timestamp:
Aug 28, 2005, 7:58:31 PM (19 years ago)
Author:
Paul Brossier <piem@altern.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
3c86eb1
Parents:
4cc9fe5
Message:

massive changes from cam

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/aubio/gnuplot.py

    r4cc9fe5 r5e491b3b  
    151151        from aubio.onsetcompare import onset_roc
    152152
    153         if len(onsets) == 0: onsets = [0.];
    154 
    155         # onset detection function
    156         downtime = (hopsize/samplerate)*numarray.arange(len(ofunc))
    157         d = Gnuplot.Data(downtime,ofunc,with='lines')
    158 
    159         # detected onsets
    160         x1 = (hopsize/samplerate)*numarray.array(onsets)
    161         y1 = max(ofunc)*numarray.ones(len(onsets))
    162         e = Gnuplot.Data(x1,-y1,with='impulses')
    163         e2= Gnuplot.Data(x1,y1,with='impulses')
     153        d,d2 = [],[]
     154        maxofunc = 0
     155        for i in range(len(onsets)):
     156                if len(onsets[i]) == 0: onsets[i] = [0.];
     157
     158                # onset detection function
     159                downtime = (hopsize/samplerate)*numarray.arange(len(ofunc[i]))
     160                d.append(Gnuplot.Data(downtime,ofunc[i],with='lines'))
     161                maxofunc = max(max(ofunc[i]), maxofunc)
     162
     163        for i in range(len(onsets)):
     164                # detected onsets
     165                x1 = (hopsize/samplerate)*numarray.array(onsets[i])
     166                y1 = maxofunc*numarray.ones(len(onsets[i]))
     167                d.append(Gnuplot.Data(x1,y1,with='impulses'))
     168                d2.append(Gnuplot.Data(x1,-y1,with='impulses'))
    164169
    165170        # check if datafile exists truth
     
    170175        else:
    171176                t_onsets = aubio.txtfile.read_datafile(datafile)
    172                 y2 = max(ofunc)*numarray.ones(len(t_onsets))
     177                y2 = maxofunc*numarray.ones(len(t_onsets))
    173178                x2 = numarray.array(t_onsets).resize(len(t_onsets))
    174                 t = Gnuplot.Data(x2,y2,with='impulses')
     179                d2.append(Gnuplot.Data(x2,y2,with='impulses'))
    175180               
    176181                tol = 0.050
     
    189194        # audio data
    190195        time,data = audio_to_array(filename)
    191         f = make_audio_plot(time,data)
     196        d2.append(make_audio_plot(time,data))
    192197
    193198        # prepare the plot
     
    212217        g('set yrange [-1:1]')
    213218        g.ylabel('amplitude')
    214         g.plot(f,e,t)
     219        g.plot(*d2)
    215220       
    216221        g('unset title')
     
    219224        g('set size 1,0.7')
    220225        g('set origin 0,0')
    221         g('set xrange [0:%f]' % (hopsize/samplerate*len(ofunc)))
    222         g('set yrange [0:%f]' % (max(ofunc)*1.01))
     226        g('set xrange [0:%f]' % (hopsize/samplerate*len(ofunc[0])))
     227        g('set yrange [0:%f]' % (maxofunc*1.01))
    223228        g.xlabel('time')
    224229        g.ylabel('onset detection value')
    225         g.plot(d,e2)
     230        g.plot(*d)
    226231
    227232        g('unset multiplot')
     
    233238        import numarray
    234239
    235         # onset detection function
    236         downtime = (hopsize/samplerate)*numarray.arange(len(pitch))
    237         d = Gnuplot.Data(downtime,pitch,with='lines')
     240        d = []
     241        maxpitch = 100
     242        for i in range(len(pitch)):
     243                downtime = (hopsize/samplerate)*numarray.arange(len(pitch[i]))
     244                d.append(Gnuplot.Data(downtime,pitch[i],with='lines'))
     245                maxpitch = max(maxpitch,max(pitch[i][:])*1.1)
    238246
    239247        # check if datafile exists truth
     
    291299        g('set size 1,0.7')
    292300        g('set origin 0,0')
    293         g('set xrange [0:%f]' % (hopsize/samplerate*len(pitch)))
    294         g('set yrange [0:%f]' % (max(pitch)*1.01))
     301        g('set xrange [0:%f]' % max(time))
     302        g('set yrange [40:%f]' % maxpitch)
    295303        g.xlabel('time')
    296304        g.ylabel('frequency (Hz)')
    297         g.plot(d,t)
     305        g.plot(*d)
    298306
    299307        g('unset multiplot')
Note: See TracChangeset for help on using the changeset viewer.