Exemplo n.º 1
0
class VUmetertwo(object):
    def __init__(self):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.controller = AudioController(channel=1, rate=256000, period=64)
        self.color = BLUE
        self.inputlength = matrix_height
        self.inputs = []
        self.offset = 13
        self.max = 1250
        self.lim = self.max
        self.rate = 10

    def getaverageof(self, number):
        averages = []
        for i in range(0, number):
            data = self.controller.getinput()
            while(data is None):
                data = self.controller.getinput()
            averages.append(data)
        sums = 0
        for num in averages:
            sums += num
        return int(sums / len(averages))

    def getinputs(self):
        self.inputs = []
        sums = 0
        for input in range(0, self.inputlength):
            data = self.getaverageof(3)
            self.inputs.append(data)
            sums += data
        return sums / len(self.inputs)

    def generate(self):
        average = self.getinputs()
        self.graphics.fill(BLACK)
        for i, line in enumerate(self.inputs):
            if line > self.max:
                self.max = line
            else:
                if self.max <= self.lim:
                    self.max = self.lim
                else:
                    self.max -= int((self.max - self.lim) / self.rate)
            length = int(translate(average, 0, self.max, 0, matrix_height))
            data = int(translate(line, 0, average, 0, length))
            if data > 0xff:
                self.data = 0xff
            if data > self.max:
                self.max = data
            self.graphics.drawLine(0, i, data - self.offset, i, self.color)
        return self.graphics.getSurface()
Exemplo n.º 2
0
import alsaaudio
import time
import audioop
from Controllers.Controllers import AudioController

controller = AudioController(channel=1, rate=16000)

inputs = []

while(True):
    input = controller.getinput()
    if(input):
        inputs.append(input)
        sum = 0
        for i in inputs:
            sum += i
        average = sum / len(inputs)
        if len(inputs) > 10:
            inputs = []
        print(" " * int(input / 5) + "*")
    # time.sleep(0.001)


# inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK)

# inp.setchannels(1)
# inp.setrate(16000)
# inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)

# inp.setperiodsize(160)