Example #1
0
 def test_freqtomidi(self):
     a = array(list(range(-20, 50000, 100)) + [ -1e32, 1e32 ])
     b = freqtomidi(a)
     #print zip(a, b)
     assert_equal ( isnan(array(b)), False )
     assert_equal ( isinf(array(b)), False )
     assert_equal ( array(b) < 0, False )
Example #2
0
 def run_pitch(self, p, input_vec, freq):
     pitches, errors = [], []
     input_blocks = input_vec.reshape((-1, p.hop_size))
     for new_block in input_blocks:
         pitch = p(new_block)[0]
         pitches.append(pitch)
         errors.append(1. - freqtomidi(pitch) / freqtomidi(freq))
     assert_equal ( len(input_blocks), len(pitches) )
     assert_equal ( isnan(pitches), False )
     # cut the first candidates
     #cut = ( p.buf_size - p.hop_size ) / p.hop_size
     pitches = pitches[2:]
     errors = errors[2:]
     # check that the mean of all relative errors is less than 10%
     #assert abs (mean(errors) ) < 0.1, pitches
     assert abs (median(errors) ) < 0.06, "median of relative errors is bigger than 0.06 (%f)\n found %s\n errors %s" % (mean(errors), pitches, errors)
Example #3
0
 def test_freqtomidi(self):
     a = array(range(-20, 50000, 100) + [-1e32, 1e32])
     b = freqtomidi(a)
     #print zip(a, b)
     assert_equal(isnan(array(b)), False)
     assert_equal(isinf(array(b)), False)
     assert_equal(array(b) < 0, False)
def get_pitch_histogram(release):
    release = str(release)
    #pitches = check_output(["aubiopitch", "-i", "../anjuna_symlinks/"+release, "-u", "midi", "-p", "fcomb", "-B", "8192", "-H", "4048"])#orig 8k 4k, then 4k 1k, then 2k .5k.  4k 1k seemed best.
    pitches = check_output(["sonic-annotator", "-t", "./pitch.t", "../anjuna_symlinks/"+release, "-w", "csv", "--csv-stdout"])
    # pitches ( file ) --> pitches [ lines ]
    pitches = [x for x in pitches.split('\n')[1:] if x != ""]
    # --> float values (Hz)
    pitches = [float(x.split(',')[-1]) for x in pitches]
    # --> valid midi note numbers
    pitches = [round(freqtomidi(x)) for x in pitches if x >= 20.0]
    
    
    key = keys[release]
    # Subtract out the key's distance to C to force all to C
    # This is guaranteed to be positive since it is at least 15 - 11 = 4
    pitches = [x - key for x in pitches]
    
    histogram = np.array([0,0,0,0,0,0,0,0,0,0,0,0])
    sum = 0
    
    for p in pitches:
        # Scale pitches into 1 octave / fit into note name bins
        scaled_p = round(p) % 12.0
        histogram[scaled_p] += 1
        sum += 1
    
    return histogram * 1.0 / sum
Example #5
0
def get_pitch_histogram(release):
    release = str(release)
    #pitches = check_output(["aubiopitch", "-i", "../anjuna_symlinks/"+release, "-u", "midi", "-p", "fcomb", "-B", "8192", "-H", "4048"])#orig 8k 4k, then 4k 1k, then 2k .5k.  4k 1k seemed best.
    pitches = check_output([
        "sonic-annotator", "-t", "./pitch.t", "../anjuna_symlinks/" + release,
        "-w", "csv", "--csv-stdout"
    ])
    # pitches ( file ) --> pitches [ lines ]
    pitches = [x for x in pitches.split('\n')[1:] if x != ""]
    # --> float values (Hz)
    pitches = [float(x.split(',')[-1]) for x in pitches]
    # --> valid midi note numbers
    pitches = [round(freqtomidi(x)) for x in pitches if x >= 20.0]

    key = keys[release]
    # Subtract out the key's distance to C to force all to C
    # This is guaranteed to be positive since it is at least 15 - 11 = 4
    pitches = [x - key for x in pitches]

    histogram = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    sum = 0

    for p in pitches:
        # Scale pitches into 1 octave / fit into note name bins
        scaled_p = round(p) % 12.0
        histogram[scaled_p] += 1
        sum += 1

    return histogram * 1.0 / sum
Example #6
0
 def run_pitch(self, p, input_vec, freq):
     count = 0
     pitches, errors = [], []
     input_blocks = input_vec.reshape((-1, p.hop_size))
     for new_block in input_blocks:
         pitch = p(new_block)[0]
         pitches.append(pitch)
         errors.append(1. - freqtomidi(pitch) / freqtomidi(freq))
     assert_equal ( len(input_blocks), len(pitches) )
     assert_equal ( isnan(pitches), False )
     # cut the first candidates
     cut = ( p.buf_size - p.hop_size ) / p.hop_size
     pitches = pitches[2:]
     errors = errors[2:]
     # check that the mean of all relative errors is less than 10%
     #assert abs (mean(errors) ) < 0.1, pitches
     assert abs (median(errors) ) < 0.06, "median of relative errors is bigger than 0.06 (%f)\n found %s\n errors %s" % (mean(errors), pitches, errors)
def freq2note(freq):
    from aubio import freqtomidi
    return midi2note(int(freqtomidi(freq)))
Example #8
0
def freq2note(freq):
    " convert frequency in Hz to nearest note name, e.g. [0, 22050.] -> [C-1, G9] "
    from aubio import freqtomidi
    return midi2note(int(freqtomidi(freq)))
Example #9
0
def freq2note(freq):
    from aubio import freqtomidi
    return midi2note(int(freqtomidi(freq)))
Example #10
0
def freq2note(freq):
    " convert frequency in Hz to nearest note name, e.g. [0, 22050.] -> [C-1, G9] "
    from aubio import freqtomidi
    return midi2note(int(freqtomidi(freq)))