Ejemplo n.º 1
0
            'datasize': datasize
        },
                      output=True)

    if mode == 'mic':
        audio = Audio(source={
            'input': 'mic',
            'datasize': datasize,
            'rate': frate
        },
                      output=False)

    fft = Fft(datasize=datasize, frate=frate)

    data = audio.sample_and_send()
    fft.configure_fft(data)
    fft.getDominantF()
    fft.splitLevels()
    fft.normalize_bin_values()

    # bin_history.append(fft.stats['bin_values_normalized'][chan])

    # print len(bin_history)

    while (len(bin_history[0]) < history_length):
        data = audio.sample_and_send()
        fft.configure_fft(data)
        fft.getDominantF()
        fft.splitLevels()
        fft.normalize_bin_values()
        for x in xrange(7):
Ejemplo 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()