You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: channel.go
    path of file: ./repos/goboy/pkg/apu
    
    the code of the file until where you have to start completion: package apu

import "math"

// NewChannel returns a new sound channel using a sampling function.
func NewChannel() *Channel {
	return &Channel{}
}

// Channel represents one of four Gameboy sound channels.
type Channel struct {
	frequency float64
	generator WaveGenerator
	time      float64
	amplitude float64

	// Duration in samples
	duration int
	length   int

	envelopeVolume     int
	envelopeTime       int
	envelopeSteps      int

    
func (chn *Channel) Sample() (outputL, outputR uint16) {
	var output uint16
	step := chn.frequency * twoPi / float64(sampleRate)
	chn.time += step
	if chn.shouldPlay() {
		// Take the sample value from the generator
		if !chn.debugOff {
			output = uint16(float64(chn.generator(chn.time)) * chn.amplitude)
		}
		if chn.duration > 0 {
			chn.duration--
		}
	}
	chn.updateEnvelope()
	chn.updateSweep()
	if chn.onL {
		outputL = output
	}
	if chn.onR {
		outputR = output
	}
	return
}