Exemplo n.º 1
0
        animated_plots.append(
            plt.plot(xAxis,
                     bin_history[x],
                     '-',
                     label=labels[x],
                     marker='o',
                     markersize=12,
                     markevery=[])[0])

    plt.legend(loc='upper left')

    # beat_detect.lastbeat = time.time()

    while True:
        data = audio.sample_and_send()
        fft.run_fft(data)
        fft.getDominantF()
        fft.splitLevels()
        # fft.set_freq_bins_max()
        fft.normalize_bin_values()

        for x in xrange(7):
            bin_history[x].pop(0)
            bin_history[x].append(fft.stats['bin_values_normalized'][x])
            beat_detectors[x].detect((bin_history[x][:]))

        for x in xrange(7):
            animated_plots[x].set_ydata(bin_history[x])

            animated_plots[x].set_markevery(beat_detectors[x].history)
Exemplo n.º 2
0
    def run(self):

        print 'create client'
        client = UdpClient(udp_ip=self.udp_ip,
                           udp_port_rec=self.udp_port_rec,
                           udp_port_send=self.udp_port_send)
        client.connect()

        if client.connected:
            print 'client connected'
            ''' 1 - get source '''
            datasize = 2048
            frate = 44100

            self.mode = 'mic'
            if self.mode == 'wav':
                audio = Audio(source={
                    'input': 'wav',
                    'path': 'resources/DaftPunk.wav',
                    'datasize': self.datasize
                },
                              output=True)
            if self.mode == 'mic':
                audio = AudioStream(source={
                    'input': 'mic',
                    'datasize': self.datasize,
                    'rate': self.frate
                },
                                    output=False)
            ''' create fft '''
            fft = Fft(datasize=datasize,
                      frate=frate,
                      gain=10e-4,
                      saturation_point=1024)
            data = audio.sample_and_send()
            fft.configure_fft(data)
            fft.getDominantF()
            fft.splitLevels()
            fft.normalize_bin_values()

            last_tick = time.time()

            while True:
                ''' wait until next cycle '''
                if (time.time() - last_tick) > self.process_period:
                    last_tick = time.time()

                    data = audio.sample_and_send()
                    fft.run_fft(data)
                    fft.getDominantF()
                    fft.splitLevels()
                    # fft.set_freq_bins_max()
                    fft.normalize_bin_values()

                    msg = ','.join(
                        [str(i) for i in fft.stats['bin_values_normalized']])
                    print msg
                    if not client.send(msg):
                        ''' wait for reconnect '''
                else:
                    time.sleep(.0001)

        else:
            print 'client not connected'

        client.disconnect()