Beispiel #1
0
func NewPianoKey(idx int) Key {
	const phasefac float64 = 0.5063999999999971

	k := &PianoKey{}

	k.freq = notes[idx]
	k.mod = snd.NewOscil(sqsine, k.freq/2, nil)
	k.osc = snd.NewOscil(sawtooth, k.freq, k.mod)
	k.phs = snd.NewOscil(square, k.freq*phasefac, nil)
	k.osc.SetPhase(k.phs)

	freql := k.freq * math.Pow(2, -10.0/1200)
	k.modl = snd.NewOscil(sqsine, freql/2, nil)
	k.oscl = snd.NewOscil(sawtooth, freql, k.modl)
	k.phsl = snd.NewOscil(square, freql*phasefac, nil)
	k.oscl.SetPhase(k.phsl)

	freqr := k.freq * math.Pow(2, 10.0/1200)
	k.modr = snd.NewOscil(sqsine, freqr/2, nil)
	k.oscr = snd.NewOscil(sawtooth, freqr, k.modr)
	k.phsr = snd.NewOscil(square, freqr*phasefac, nil)
	k.oscr.SetPhase(k.phsr)

	oscmix := snd.NewMixer(k.osc, k.oscl, k.oscr)

	k.reldur = 1050 * ms
	k.dur = 280*ms + k.reldur
	k.adsr0 = snd.NewADSR(30*ms, 50*ms, 200*ms, k.reldur, 0.4, 1, oscmix)
	k.adsr1 = snd.NewADSR(1*ms, 278*ms, 1*ms, k.reldur, 0.4, 1, oscmix)
	adsrmix := snd.NewMixer(k.adsr0, k.adsr1)

	k.gain = snd.NewGain(snd.Decibel(-10).Amp(), adsrmix)

	k.Instrument = snd.NewInstrument(k.gain)
	k.Off()

	return k
}
Beispiel #2
0
func NewBeatsKey(idx int) Key {
	osc := snd.NewOscil(sawsine, notes[idx], snd.NewOscil(triangle, 4, nil))
	dmp := snd.NewDamp(bpm.Dur(), osc)
	d := snd.BPM(float64(bpm) * 1.25).Dur()
	dmp1 := snd.NewDamp(d, osc)
	drv := snd.NewDrive(d, osc)
	mix := snd.NewMixer(dmp, dmp1, drv)

	frz := snd.NewFreeze(bpm.Dur()*4, mix)

	adsr := snd.NewADSR(250*ms, 500*ms, 300*ms, 400*ms, 0.85, 1.0, frz)
	key := &BeatsKey{snd.NewInstrument(adsr), adsr}
	key.Off()
	return key
}
Beispiel #3
0
func onStart(ctx gl.Context) {
	ctx.Enable(gl.BLEND)
	ctx.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	if err := al.OpenDevice(buffers); err != nil {
		log.Fatal(err)
	}

	var err error

	keymix = snd.NewMixer()
	go makekeys()
	lowpass = snd.NewLowPass(773, keymix)
	keygain = snd.NewGain(snd.Decibel(-3).Amp(), lowpass)

	dly := snd.NewDelay(29*time.Millisecond, keygain)
	tap0 := snd.NewTap(19*time.Millisecond, dly)
	tap1 := snd.NewTap(13*time.Millisecond, dly)
	tap2 := snd.NewTap(7*time.Millisecond, dly)
	cmb := snd.NewComb(snd.Decibel(-3).Amp(), 11*time.Millisecond, snd.NewMixer(dly, tap0, tap1, tap2))
	reverb = snd.NewLowPass(2000, cmb)
	dlymix := snd.NewMixer(reverb, keygain)

	loop = snd.NewLoopFrames(loopdur, dlymix)
	loop.SetBPM(bpm)
	loopmix := snd.NewMixer(dlymix, loop)

	master = snd.NewMixer(loopmix)
	mastergain = snd.NewGain(snd.Decibel(-6).Amp(), master)
	mixwf, err = snd.NewWaveform(ctx, 2, mastergain)
	if err != nil {
		log.Fatal(err)
	}
	pan := snd.NewPan(0, mixwf)

	mtrosc := snd.NewOscil(sine, 440, nil)
	mtrdmp := snd.NewDamp(bpm.Dur(), mtrosc)
	metronome = snd.NewMixer(mtrdmp)
	metronome.Off()
	master.Append(metronome)

	piano = NewPiano()
	pianowf, err = snd.NewWaveform(ctx, 1, piano)
	if err != nil {
		log.Fatal(err)
	}

	al.AddSource(pan)

	yoff := float32(-0) //.12)

	btnreverb = snd.NewButton(ctx, -0.98, 0.96+yoff, 0.2, -0.2)
	btnreverb.SetActiveColor(0, 1, 0, 0.5)
	btnreverb.SetActive(true)

	btnlowpass = snd.NewButton(ctx, -0.76, 0.96+yoff, 0.2, -0.2)
	btnlowpass.SetActiveColor(0, 1, 1, 0.5)
	btnlowpass.SetActive(true)

	btnmetronome = snd.NewButton(ctx, -0.54, 0.96+yoff, 0.2, -0.2)
	btnmetronome.SetActiveColor(0, 0, 1, 0.5)

	btnloop = snd.NewLoopButton(snd.NewButton(ctx, -0.32, 0.96+yoff, 0.2, -0.2), loop)
	btnloop.SetActiveColor(1, 0, 0, 0.5)

	btnsndbank = snd.NewButton(ctx, 0.78, 0.96+yoff, 0.2, -0.2)
	btnsndbank.SetActive(true)
	btnsndbank.SetActiveColor(sndbankcolor())
}