Example #1
0
File: al.go Project: dskinner/snd
func AddSource(in snd.Sound) error {
	switch in.Channels() {
	case 1:
		hwa.format = al.FormatMono16
	case 2:
		hwa.format = al.FormatStereo16
	default:
		return fmt.Errorf("snd/al: can't handle input with channels(%v)", in.Channels())
	}
	hwa.in = in
	hwa.out = make([]byte, in.BufferLen()*2)

	s := al.GenSources(1)
	if code := al.Error(); code != 0 {
		return fmt.Errorf("snd/al: generate source failed [err=%v]", code)
	}
	hwa.source = s[0]
	hwa.buf.src = s[0]

	log.Println("snd/al: software latency", SoftLatency())

	hwa.inputs = snd.GetInputs(in)

	return nil
}
Example #2
0
// TODO just how many samples do we want/need to display something useful?
func NewWaveform(ctx gl.Context, n int, in snd.Sound) (*Waveform, error) {
	wf := &Waveform{Material: env.NewMaterial(ctx), Sound: in}
	wf.Drawer = wf.Draw

	wf.outs = make([][]float64, n)
	for i := range wf.outs {
		wf.outs[i] = make([]float64, in.BufferLen()*in.Channels())
	}
	wf.samples = make([]float64, in.BufferLen()*in.Channels()*n)
	wf.verts = make([]float32, len(wf.samples)*2)

	wf.prg.CreateAndLink(ctx,
		glutil.ShaderAsset(gl.VERTEX_SHADER, "basic-vert.glsl"),
		glutil.ShaderAsset(gl.FRAGMENT_SHADER, "basic-frag.glsl"))

	wf.vbuf = glutil.NewFloatBuffer(ctx, wf.verts, gl.STREAM_DRAW)
	wf.uw = wf.prg.Uniform(ctx, "world")
	wf.uv = wf.prg.Uniform(ctx, "view")
	wf.up = wf.prg.Uniform(ctx, "proj")
	wf.uc = wf.prg.Uniform(ctx, "color")
	wf.ap = wf.prg.Attrib(ctx, "position")
	return wf, nil
}