Example #1
0
 def test_miditofreq(self):
     a = list(range(-30, 200)) + [-100000, 10000]
     b = miditofreq(a)
     #print zip(a, b)
     assert_equal ( isnan(b), False )
     assert_equal ( isinf(b), False )
     assert_equal ( b < 0, False )
Example #2
0
def sample(samples):
    


    pitch = pitch_o(samples)[0]
    is_beat= T.tempo(samples)
    # print(pitch)
    if is_beat:
        # print "\nBPMS",is_beat,"\n"
        tb=T.tempo.get_last_s()
        T.beats.append(tb)
        if(len(T.beats)>T.median_win_s):
            bpms = 60./ diff(T.beats)
            T.bpms = median(bpms[-T.median_win_s:])
            print "\nBPMS",bpms,"\n"
        
    pitch = int(round(pitch))
    confidence = pitch_o.get_confidence()
    print confidence
    if confidence < 0.8: pitch = 0.
    if confidence > 0.8:
        n=midi2note(min(pitch,127))
        print confidence,pitch,miditofreq(min(pitch,127)),midi2note(min(pitch,127))
        # st+=' '+midi2note(int(pitch))
        if(n[-1]!='1'):noter(n)
Example #3
0
 def test_miditofreq(self):
     a = range(-30, 200) + [-100000, 10000]
     b = miditofreq(a)
     #print zip(a, b)
     assert_equal(isnan(b), False)
     assert_equal(isinf(b), False)
     assert_equal(b < 0, False)
Example #4
0
def play_taam(seq):
    for taam in seq:
        # print(taam)
        if taam != np.nan:
            freq = miditofreq(taam)
            sine(frequency=freq, duration=.3)
        else:
            time.sleep(.3)
Example #5
0
    def GuessNominalFreqFromFileName(self):
        '''tries to guess note frequency from the file name
        '''

        import aubio
        import re

        tokens = re.findall('([A-Ga-g][sS#bB+-]*\d+)', self.name)

        try:
            notename = re.sub('s', '#', tokens[0])
            f = aubio.miditofreq(aubio.note2midi(notename))
        except (ValueError, IndexError):
            f = np.NaN

        return f
    def run_analysis(self):
        print("Starting to listen, press Ctrl+C to stop")
        while True:
            try:
                # read data from audio input
                _, data = self._mic.read()
                # convert data to aubio float samples
                samples = numpy.fromstring(data, dtype=aubio.float_type)
                # get the note from the sample data
                new_note = self._note_analyzer(samples)

                if (new_note[0] != 0):
                    #note_str = ' '.join(["%.2f" % i for i in new_note])
                    print str(new_note)
                    frequency = int(miditofreq(new_note[0]))
                    print "To frequency: {0}".format(frequency)
                    self._serial_proxy.send(frequency)

            except KeyboardInterrupt:
                print("Ctrl+C pressed, exiting")
                break
Example #7
0
# For posting to ly-server
# st='{"commands":[{"command":"musicxml"},{"command":"mode"}],"data":"relative c {'


st='relative c {'
while True:
    samples, read = s()
    print samples[0], len(samples)
    pitch = pitch_o(samples)[0]
    # print(pitch)
    pitch = int(round(pitch))
    confidence = pitch_o.get_confidence()
    if confidence < 0.8: pitch = 0.
    if confidence > 0.8:
        print len(pitches) * hop_s,miditofreq(pitch),midi2note(int(pitch))
        st+=' '+midi2note(int(pitch))
        noter(midi2note(int(pitch)))

    
    #print "%f %f %f" % (total_frames / float(samplerate), pitch, confidence)
    
    pitches += [pitch]
    confidences += [confidence]
    total_frames += read
    if read < hop_s: break
# st+=' }"}'
st+=' }'
st=st.replace('#','').lower()
print st
# post(st)
Example #8
0
#! /usr/bin/env python

from aubio import miditofreq
from numpy import arange

upsampling = 100.
midi = arange(-10, 148 * upsampling)
midi /= upsampling
freq = miditofreq(midi)

from matplotlib import pyplot as plt

ax = plt.axes()
ax.semilogy(midi, freq, '.')
ax.set_xlabel('midi note')
ax.set_ylabel('frequency (Hz)')
plt.show()