예제 #1
0
 def test_fail_not_fvec(self):
     try:
         level_lin("default")
     except ValueError as e:
         pass
     else:
         self.fail('non-number input phase does not raise a TypeError')
예제 #2
0
 def test_fail_not_fvec(self):
     try:
         level_lin("default")
     except ValueError as e:
         pass
     else:
         self.fail('non-number input phase does not raise a TypeError')
예제 #3
0
def blob(image, data: Tuple[List, List], opts: Opts):
    height, width, _ = image.shape

    cx = width // 2
    cy = height // 2

    d1, d2 = data

    f = fft(len(d1))
    s1 = f.rdo(f(fvec(d1)))
    s2 = f.rdo(f(fvec(d2)))

    level = level_lin(fvec(d1 + d2))

    for i, j, k, n, rk, rn in zip(d1, d2, s1, s2, reversed(s1), reversed(s2)):

        x = cx + int(j * width) - int(i * width)
        y = cy + int(height * k) - int(rk * height)

        radius = level * opts.radius
        r1 = int(k * radius)
        r2 = int(n * radius)

        blur_x = 5
        blur_y = 5

        if r1 > 0 and r2 > 0:
            cv2.ellipse(image, (x, y), (r1, r2), 0, 0, 360, (255, 255, 255))
            image = cv2.GaussianBlur(image, (blur_x, blur_y), 0)

    return image
 def test_minus_ones_is_one(self):
     from numpy import ones
     assert_equal(level_lin(-ones(1024, dtype="float32")), 1.)
 def test_zeros_is_zeros(self):
     assert_equal(level_lin(fvec(1024)), 0.)
 def test_fail_not_fvec(self):
     try:
         level_lin("default")
     except ValueError, e:
         pass
 def test_accept_fvec(self):
     level_lin(fvec(1024))
예제 #8
0
def getFreq(stream, CHUNK, fDetection, outputsink):
    staff = ""
    prev_note = ""
    my_notes = []
    while True:
        try:
            data = stream.read(CHUNK)

            samples = np.fromstring(data, dtype=aubio.float_type)

            freq = fDetection(samples)[0]
            confidence = fDetection.get_confidence()
            fConfidence = '{:.2f}'.format(confidence)

            # if confidence < 0.5:
            #     freq = 0

            #IT IS ALSO CONVERTED INTO DECIBEL
            #I commented it out originally because the outputs didn't make sense
            #Maybe you can make some sense out of it

            #decibel = 20 * np.log10(rms) #dB = 20 * log10(Amp)
            #print(decibel)

            #MAX THE linear VARIABLE HAS THE SOUND PRESSURE LEVELS
            #aubio:
            linear = '{:.4f}'.format(
                aubio.level_lin(samples))  #seems to make more sense
            linear = float(linear)
            decibels = '{:.4f}'.format(aubio.db_spl(samples))
            #Ive been testing it and it seems like
            #it's outputting negative decibels
            #the closer to 0, the louder

            #uncomment to print original stuff
            #print("{} / {}".format(freq, confidence))

            if outputsink:
                outputsink(samples, len(samples))

            # if note is too low, don't print
            if (freq > 25.0):
                #call KeyChart
                idx = KeyChart.findNote(freq)
                #note name
                (nn, regular) = KeyChart.alternate(idx)
                print("all :", nn, "| confidence", fConfidence)

                #if new note
                if (nn != prev_note):
                    prev_note = nn

                    #create new note
                    newNote = Note(nn, 1, 'TBD', linear)
                    #append to list of notes
                    my_notes.append(newNote)
                    #note name formated (added space)
                    nnf = nn + " "
                    # Adding the notes to the string
                    staff += nnf
                    #print(nn)

                #else if same note
                else:
                    #increment current note's duration
                    my_notes[len(my_notes) - 1].duration += 1

            #else it's a rest
            elif linear < 0.001:
                #if last note was not a rest
                if prev_note != "REST":
                    prev_note = "REST"
                    print("REST")
                    newRest = Note("r", 1, 'TBD', linear)
                    my_notes.append(newRest)
                #else last note was a rest
                else:
                    #print('asdnasdjnasjdnj')
                    my_notes[len(my_notes) - 1].duration += 1
                    #my_notes[len(my_notes)-1].printNote()
            #else freq < 25 but still sound, just extend last note
            else:
                if prev_note != "":
                    print('REST')
                    my_notes[len(my_notes) - 1].duration += 1

        except KeyboardInterrupt:
            print("User Ctrl+C. Exiting...")
            return (staff, my_notes)
예제 #9
0
 def test_minus_ones_is_one(self):
     assert_equal(level_lin(-np.ones(1024, dtype = float_type)), 1.)
예제 #10
0
 def test_fail_not_fvec(self):
     with self.assertRaises(ValueError):
         level_lin("default")
예제 #11
0
 def test_minus_ones_is_one(self):
     assert_equal(level_lin(-np.ones(1024, dtype=float_type)), 1.)
예제 #12
0
 def test_zeros_is_zeros(self):
     assert_equal(level_lin(fvec(1024)), 0.)
예제 #13
0
 def test_fail_not_fvec(self):
     with self.assertRaises(ValueError):
         level_lin("default")
예제 #14
0
 def test_accept_fvec(self):
     level_lin(fvec(1024))
예제 #15
0
 def test_minus_ones_is_one(self):
     from numpy import ones
     assert_equal(level_lin(-ones(1024, dtype="float32")), 1.)
예제 #16
0
 def test_fail_not_fvec(self):
     try:
         level_lin("default")
     except ValueError, e:
         pass