Пример #1
0
 def test_fail_not_fvec(self):
     try:
         db_spl("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:
         db_spl("default")
     except ValueError as e:
         pass
     else:
         self.fail('non-number input phase does not raise a TypeError')
Пример #3
0
    def pre_process_audio(self):
        """
        Pre-processing stage that will run on every sample, only
        core functionality that will be used for every audio effect
        should be done here. Everything else should be deferred until
        queried by an effect.
        """

        # Calculate the current volume for silence detection
        self._volume = aubio.db_spl(self._raw_audio_sample)
        self._volume_filter.update(self._volume)

        # Calculate the frequency domain from the filtered data and
        # force all zeros when below the volume threshold
        if self._volume_filter.value > self._config['min_volume']:
            self._processed_audio_sample = self._raw_audio_sample

            # Perform a pre-emphasis to balance the highs and lows
            if self.pre_emphasis:
                self._processed_audio_sample = self.pre_emphasis(
                    self._raw_audio_sample)

            # Pass into the phase vocoder to get a windowed FFT
            self._frequency_domain = self._phase_vocoder(
                self._processed_audio_sample)
        else:
            self._frequency_domain = self._frequency_domain_null

        # Light up some notifications for developer mode
        if self._ledfx.dev_enabled():
            self._ledfx.events.fire_event(
                GraphUpdateEvent('fft', self._frequency_domain.norm,
                                 self._frequency_domain_x))
    def _process_samples(self, samples: aubio.fvec,
                         sample_count: int) -> Tuple[float, bool]:
        db = aubio.db_spl(samples)

        if self._previous_value is None:
            self._previous_value = db
            return float("NaN"), False

        output = db - self._previous_value
        self._previous_value = db

        return output, abs(output) < self._threshold
Пример #5
0
 def collectBeats(
     self
 ):  # collectBeats basic idea from https://github.com/aubio/aubio/tree/master/python/demos, tempo demo
     self.music_source = aubio.source(self.fileName, self.samplingRate,
                                      self.hop_size)
     self.music_tempo = aubio.tempo("default", self.fft_size, self.hop_size,
                                    self.samplingRate)
     while True:  # collect location of beats in the song, in terms of the time in the song
         samples, read = self.music_source()
         is_beat = self.music_tempo(samples)
         if (is_beat):
             this_beat = int(self.total_frames - self.delay +
                             is_beat[0] * self.hop_size)
             time = (this_beat / float(self.samplingRate))
             time = round(time, 3)
             volume = aubio.db_spl(
                 aubio.fvec(is_beat)
             )  # added volume component, sound pressure level in db
             self.beats.append(time)
             self.volumes.append(volume)
         self.total_frames += read
         if (read < self.hop_size):
             break
     return self.beats, self.volumes
Пример #6
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)
Пример #7
0
 def test_minus_ones_is_zero(self):
     assert_equal(db_spl(-np.ones(1024, dtype = float_type)), 0.)
Пример #8
0
 def test_zeros_is_inf(self):
     assert np.isinf(db_spl(fvec(1024)))
Пример #9
0
 def test_fail_not_fvec(self):
     try:
         db_spl("default")
     except ValueError, e:
         pass
 def test_zeros_is_inf(self):
     from math import isinf
     assert isinf(db_spl(fvec(1024)))
Пример #11
0
 def test_zeros_is_inf(self):
     assert np.isinf(db_spl(fvec(1024)))
Пример #12
0
 def test_fail_not_fvec(self):
     with self.assertRaises(ValueError):
         db_spl("default")
Пример #13
0
 def test_accept_fvec(self):
     db_spl(fvec(1024))
Пример #14
0
 def test_minus_ones_is_zero(self):
     from numpy import ones
     assert_equal(db_spl(-ones(1024, dtype="float32")), 0.)
Пример #15
0
 def test_zeros_is_inf(self):
     from math import isinf
     assert isinf(db_spl(fvec(1024)))
 def test_accept_fvec(self):
     db_spl(fvec(1024))
 def test_fail_not_fvec(self):
     try:
         db_spl("default")
     except ValueError, e:
         pass
Пример #18
0
 def test_minus_ones_is_zero(self):
     assert_equal(db_spl(-np.ones(1024, dtype=float_type)), 0.)
 def test_minus_ones_is_zero(self):
     from numpy import ones
     assert_equal(db_spl(-ones(1024, dtype="float32")), 0.)
Пример #20
0
 def test_fail_not_fvec(self):
     with self.assertRaises(ValueError):
         db_spl("default")