# -*- coding:utf-8 -*-
"""
Sounds generated by neurons

Doesn't really work!
"""
from brian import *
from brian.hears import *
import time

eqs = '''
dv/dt = (ge+gi-(v+49*mV))/(20*ms) : volt
dge/dt = -ge/(5*ms) : volt
dgi/dt = -gi/(10*ms) : volt
'''

P = NeuronGroup(4000, model=eqs,
              threshold= -50 * mV, reset= -60 * mV)
P.v = -60 * mV + 10 * mV * rand(len(P))
Pe = P.subgroup(3200)
Pi = P.subgroup(800)

Ce = Connection(Pe, P, 'ge', weight=1.62 * mV, sparseness=0.02)
Ci = Connection(Pi, P, 'gi', weight= -9 * mV, sparseness=0.02)

def play(spikes):
    if len(spikes) > 0:
        click(0.1 * ms, clip(len(spikes) * .1, 0, 1)).extend(0.1 * ms).play()
        #time.sleep(1*ms)

M = SpikeMonitor(P, function=play)
#click(1*ms,.1).play()
#whitenoise(10*ms).play()

run(1 * second)
