Example #1
0
// drawSignal writes the input wave form(s) out to screen.
func (s *SpectrogramScreen) drawSignal() {
	s.eventBuffer.Each(func(index int, value interface{}) {
		if value != nil {
			e := value.(Event)
			gl.Color3f(e.R, e.G, e.B)
			x := float64(index) * s.pixelsPerSample
			gl.Begin(gl.LINE_STRIP)
			gl.Vertex2d(x, -1.0)
			gl.Vertex2d(x, 1.0)
			gl.End()
		}
	})

	spacing := 1

	gl.PointSize(1.0)
	gl.Begin(gl.POINTS)
	s.line.valueBuffer.Each(func(index int, value interface{}) {
		col := value.([]complex128)
		for i, v := range col {
			// p = log(|v|) = [-20, 5], so map to [0, 1]
			// p := math.Log(cmplx.Abs(v) + 1.e-8)
			// grey := (p + 20.0) / 25.0
			p := cmplx.Abs(v)
			grey := p / 15.0
			if grey > 1.0 {
				grey = 1.0
			} else if grey < 0.0 {
				grey = 0.0
			}

			// HACK: Stretch to make the darks darker and the whites whiter.
			// grey = grey * grey * grey * grey // more space at the top, [0, 1]
			// grey = 2.0 * grey - 1.0 // [-1, 1]
			// grey = math.Tanh(2.0 * grey) // streched, still [-1, 1]
			// grey = (grey + 1.0) / 2.0

			gl.Color3d(grey, grey, grey)
			// gl.Vertex2d(float64(index)*s.pixelsPerSample, float64(s.height - 1 - (3 * i + 0)))
			gl.Vertex2d(float64(index)*s.pixelsPerSample, float64(s.height-1-(spacing*i)))
			// gl.Vertex2d(float64(index)*s.pixelsPerSample, float64(s.height - 1 - (3 * i + 2)))
		}

		gl.Color3ub(255, 0, 0)
		for i := 1; i < 7; i++ {
			gl.Vertex2d(float64(index)*s.pixelsPerSample, float64(i*spacing*s.bpo))
		}
	})
	gl.End()
}
Example #2
0
// drawSignal writes the input wave form(s) out to screen.
func (s *Screen) drawSignal() {
	s.eventBuffer.Each(func(index int, value interface{}) {
		if value != nil {
			e := value.(Event)
			gl.Color3f(e.R, e.G, e.B)
			x := float64(index) * s.pixelsPerSample
			gl.Begin(gl.LINE_STRIP)
			gl.Vertex2d(x, -1.0)
			gl.Vertex2d(x, 1.0)
			gl.End()
		}
	})

	for _, l := range s.lines {
		gl.Color3f(l.R, l.G, l.B)
		gl.Begin(gl.LINE_STRIP)
		l.valueBuffer.Each(func(index int, value float64) {
			gl.Vertex2d(float64(index)*s.pixelsPerSample, value)
		})
		gl.End()
	}
}