コード例 #1
0
ファイル: gui.py プロジェクト: sebdiem/hypnopy
def create_window():
    win = QtGui.QMainWindow()
    win.resize(1000,600)
    win.setWindowTitle('HypnoPy')

    pg.setConfigOptions(antialias=True) # Enable antialiasing for prettier plots

    plot_widget = create_plot_widget('Spiral')
    sidebar_width = 200
    slider_widget1 = create_slider_widget(label='SPL threshold',
                                          unit='dB',
                                          min_value=-50,
                                          max_value=50,
                                          init_value=0,
                                          step=1,
                                          connect=_update_SPL_THRESHOLD,
                                          max_width=sidebar_width)
    slider_widget2 = create_slider_widget(label='Window size',
                                          unit='',
                                          min_value=256,
                                          max_value=len(get_buffer()),
                                          init_value=len(get_buffer()),
                                          step=2,
                                          connect=_update_WINDOW_SIZE,
                                          max_width=sidebar_width)
    sidebar = create_sidebar(sidebar_width, slider_widget1, slider_widget2) 
    layout = pg.LayoutWidget()
    layout.addWidget(plot_widget)
    layout.addWidget(sidebar)
    layout.show()
    return layout, plot_widget
コード例 #2
0
ファイル: recap.py プロジェクト: DavidChouinard/recap-client
def button_released():
    global time_marker_start, time_marker_size

    button_press_start = time.time()
    print("* saving buffer")

    snapshot = audio.get_buffer()

    time_marker_start = 1
    time_marker_size = 6

    threading.Thread(target=theaterChaseAnimation).start()
    threading.Thread(target=do_button_press_actions, args=(snapshot,)).start()
コード例 #3
0
ファイル: gui.py プロジェクト: sebdiem/hypnopy
def update(blobs, buf=None):
    if buf is None:
        buf = get_buffer()
    buf = list(buf)[-get_WINDOW_SIZE():]
    densities = sound_power_densities(buf)
    ranking = sorted([(spd, i) for i, spd in enumerate(densities)],
                     reverse=True)[:len(blobs)]
    frequencies = np.fft.rfftfreq(len(buf), 1./RATE)
    for j, el in enumerate(ranking):
        spd, i = el
        if display(spd):
            freq = frequencies[i]
            blob = blob_coordinates(freq, spd, min_intensity=_SPL_THRESHOLD, max_intensity=96.)
            blobs[j].setLine(*blob)
        else:
            blobs[j].setLine(0, 0, 0, 0)
コード例 #4
0
ファイル: gui.py プロジェクト: sebdiem/hypnopy
def launch_gui(blob_count=100, freq_test=None):
    # pyqtgraph initialization
    app = QtGui.QApplication([])
    layout, plot_widget = create_window()

    blobs = [QtGui.QGraphicsLineItem() for _ in xrange(blob_count)]
    for blob in blobs:
        plot_widget.addItem(blob)
        blob.setPen(pg.mkPen(color=(255, 255, 128)))
    draw_spiral(plot_widget)

    if freq_test is None:
        update_fun = lambda : update(blobs)
    else:
        buf = make_pure_tone(freq_test, len(get_buffer()), RATE)
        update_fun = lambda : update(blobs, buf)

    timer = QtCore.QTimer()
    timer.timeout.connect(update_fun)
    timer.start(20)

    QtGui.QApplication.instance().exec_()
コード例 #5
0
ファイル: gui.py プロジェクト: sebdiem/hypnopy
import numpy as np

from audio import RATE, get_buffer
from fourier import sound_power_densities, make_pure_tone
from note_utils import BASE_FREQUENCIES, get_base_frequency_and_power_of_two, get_frequency

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg

_SPL_THRESHOLD = 0. # we do not display frequencies whose SPL is below this limit
_WINDOW_SIZE = len(get_buffer())

def _update_SPL_THRESHOLD(i):
    global _SPL_THRESHOLD
    _SPL_THRESHOLD = i

def display(intensity):
    return intensity > _SPL_THRESHOLD

def _update_WINDOW_SIZE(i):
    global _WINDOW_SIZE
    _WINDOW_SIZE = i

def get_WINDOW_SIZE():
    return _WINDOW_SIZE

def get_polar_coordinates(freq, r_scale=1.):
    """Returns a tuple (r, theta) representing polar coordinates of a frequency `freq`.
    The twelve notes of the Pythagorician scale can be displayed on a 2D spiral, with
    differences in angles proportional to the differences in frequencies.
    Higher octaves of a fundamental note N are represented with the same angle theta and a
コード例 #6
0
ファイル: recap.py プロジェクト: DavidChouinard/recap-client
def main():
    global time_marker_start

    if os.geteuid() != 0:
        exit("You need to have root privileges to run this script: rerun it using 'sudo'. Exiting.")

    if "BASE_ID" not in os.environ:
        sys.stderr.write("Error: unknown base station ID\n")
        sys.exit(1)

    setproctitle("recap")

    GPIO.output(UNDO_LED_PIN, False)

    # Startup animation
    strip.begin()
    theaterChaseAnimation()
    #threading.Thread(target=bootupAnimation).start()

    th = threading.Thread(target=networking.start_device_discovery)
    th.daemon = True
    th.start()

    th = threading.Thread(target=server.start_server)
    th.daemon = True
    th.start()

    th = threading.Thread(target=audio.start_recording)
    th.daemon = True
    th.start()

    encoder = gaugette.rotary_encoder.RotaryEncoder.Worker(ROTARY_A_PIN, ROTARY_B_PIN)
    encoder.start()

    start = time.time()
    last_button_press = 0

    try:
        while True:
            if not GPIO.input(MAIN_BUTTON_PIN) and time.time() - last_button_press > 0.2:
                print("* button pressed")

                last_button_press = time.time()
                snapshot = audio.get_buffer()

                threading.Thread(target=theaterChaseAnimation).start()
                threading.Thread(target=do_button_press_actions, args=(snapshot,)).start()

            time.sleep(0.1)

            #delta = encoder.get_delta()
            #if delta != 0 and GPIO.input(MAIN_BUTTON_PIN):
            #    if time_marker_start + time_marker_size + delta > LED_COUNT:
            #        time_marker_start = LED_COUNT - time_marker_size
            #    elif time_marker_start + delta < 0:
            #        time_marker_start = 0
            #    else:
            #        time_marker_start += delta
            #    updateStrip()
    except (KeyboardInterrupt, SystemExit):
        raise
    except Exception as e:
        sys.stderr.write(str(e))

    stream.stop_stream()
    stream.close()