Beispiel #1
0
def getSquareSound(freq,beat,subdivison, bpm=60):
    beat_in_mili = (60. / bpm) * 1000. /subdivison * beat
    square = Square(freq)
    sound = square.to_audio_segment(beat_in_mili)
    sound = sound.fade_in(int(beat_in_mili*.05))
    sound = sound.fade_out(int(beat_in_mili*.05))
    return sound
Beispiel #2
0
    def from_generator(self, freq, duration, wavetype):
        """
        Sets the Audio Object's audio segment to be the audio generated
        by a wave generator.
        
        Arguments
        freq -- the frequency of the wave to be generated (in Hz) (int)
        duration -- the duration of the wave to be generated (in milliseconds) (int)
        wavetype -- the type of wave to be generated. A string containing either
                    Sine, Square, Sawtooth, or Triangle (case insenstivie) (str)
        """
        _check_type(wavetype, "wavetype", str)
        _check_type(freq, "freq", int)
        _check_type(duration, "duration", int)
        self._duration = duration
        if wavetype.upper() == "SINE":
            wave = Sine(freq)
        elif wavetype.upper() == "SAWTOOTH":
            wave = Sawtooth(freq)
        elif wavetype.upper() == "SQUARE":
            wave = Square(freq)
        elif wavetype.upper() == "TRIANGLE":
            wave = Triangle(freq)
        else:
            raise ValueError("Error! Invalid Wavetype \"" + wavetype +
                             "\" passed to from_generator")

        self._audioseg = wave.to_audio_segment(duration)
Beispiel #3
0
 def make_tone(self, freq):
     if self.waveEntry.get() == "Sine":
         tone = (Sine(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     elif self.waveEntry.get() == "Square":
         tone = (Square(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     elif self.waveEntry.get() == "Triangle":
         tone = (Triangle(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     elif self.waveEntry.get() == "Sawtooth":
         tone = (Sawtooth(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     elif self.waveEntry.get() == "Pulse":
         tone = (Pulse(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     play(tone)
Beispiel #4
0
    def test_loudness(self):
        sine_dbfs = Sine(440).to_audio_segment().dBFS
        square_dbfs = Square(440).to_audio_segment().dBFS
        white_noise_dbfs = WhiteNoise().to_audio_segment().dBFS

        self.assertAlmostEqual(sine_dbfs, -3.0, places=1)
        self.assertAlmostEqual(square_dbfs, 0.0, places=1)
        self.assertAlmostEqual(white_noise_dbfs, -5, places=0)
Beispiel #5
0
    def test_with_smoke(self):
        Sine(440).to_audio_segment()
        Square(440).to_audio_segment()
        Triangle(440).to_audio_segment()

        Pulse(440, duty_cycle=0.75).to_audio_segment()
        Sawtooth(440, duty_cycle=0.75).to_audio_segment()

        WhiteNoise().to_audio_segment()
Beispiel #6
0
 def test_lowpass_filter_reduces_loudness(self):
     s = Square(200).to_audio_segment()
     less_treble = s.low_pass_filter(400)
     self.assertTrue(less_treble.dBFS < s.dBFS)
Beispiel #7
0
 def test_highpass_filter_reduces_loudness(self):
     s = Square(200).to_audio_segment()
     less_bass = s.high_pass_filter(400)
     self.assertTrue(less_bass.dBFS < s.dBFS)
Beispiel #8
0
 def test_lowpass_filter_reduces_loudness(self):
     s = Square(200).to_audio_segment()
     less_treble = s.low_pass_filter(400)
     self.assertTrue(less_treble.dBFS < s.dBFS)
Beispiel #9
0
 def test_highpass_filter_reduces_loudness(self):
     s = Square(200).to_audio_segment()
     less_bass = s.high_pass_filter(400)
     self.assertTrue(less_bass.dBFS < s.dBFS)