Example #1
0
def test_noise_get_noise_profile(sounddevice, numpy):
    from enviroplus.noise import Noise

    numpy.mean.return_value = 10.0

    noise = Noise(sample_rate=16000, duration=0.1)
    amp_low, amp_mid, amp_high, amp_total = noise.get_noise_profile(
        noise_floor=100, low=0.12, mid=0.36, high=None)

    sounddevice.rec.assert_called_with(0.1 * 16000,
                                       samplerate=16000,
                                       blocking=True,
                                       channels=1,
                                       dtype='float64')

    assert amp_total == 10.0
import os
import time
import rrdtool

from enviroplus.noise import Noise
noise = Noise()

dir_path = os.path.dirname(os.path.realpath(__file__))

starttime = time.time()

# TODO XXX this data doesn't look great as 4 line plots overlapping, make better
# possibly use the other amplitude @ frequency API and use several RRDs

# rrdtool can only support 1 Hz data, so if this isn't the right tool for this particular job...

# run roughly 1 Hz every ~minute scheduled by cron
while time.time() - starttime < 55:
    amp = noise.get_noise_profile()
    print(amp)
    rrdtool.update(dir_path + "/rrd/noise.rrd", "N:{}:{}:{}:{}".format(*amp))
    time.sleep(1)

Example #3
0
Press Ctrl+C to exit!

""")

noise = Noise()

disp = ST7735.ST7735(port=0,
                     cs=ST7735.BG_SPI_CS_FRONT,
                     dc=9,
                     backlight=12,
                     rotation=90)

disp.begin()

img = Image.new('RGB', (disp.width, disp.height), color=(0, 0, 0))
draw = ImageDraw.Draw(img)

while True:
    low, mid, high, amp = noise.get_noise_profile()
    low *= 128
    mid *= 128
    high *= 128
    amp *= 64

    img2 = img.copy()
    draw.rectangle((0, 0, disp.width, disp.height), (0, 0, 0))
    img.paste(img2, (1, 0))
    draw.line((0, 0, 0, amp), fill=(int(low), int(mid), int(high)))

    disp.display(img)