func RecordSampleRate(rate int) RecordOption {
	return func(r *RecordStream) {
		r.createRequest.Rate = uint32(rate)
	}
}
RecordSampleRate sets the stream's sample rate.
package pulse
import "github.com/jfreymuth/pulse/proto"
type RecordStream struct {
	c *Client
	index uint32
	state streamState
	err   error
	w Writer
	createRequest  proto.CreateRecordStream
	createReply    proto.CreateRecordStreamReply
	bytesPerSample int
}
func (c *Client) NewRecord(w Writer, opts ...RecordOption) (*RecordStream, error) {
	r := &RecordStream{
		c: c,
		createRequest: proto.CreateRecordStream{
			SourceIndex:        proto.Undefined,
			ChannelMap:         proto.ChannelMap{proto.ChannelMono},
			SampleSpec:         proto.SampleSpec{Format: w.Format(), Channels: 1, Rate: 44100},
			BufferMaxLength:    proto.Undefined,
			Corked:             true,
			BufferFragSize:     proto.Undefined,
			DirectOnInputIndex: proto.Undefined,
			Properties:         proto.PropList{},
		},
		bytesPerSample: bytes(w.Format()),
		w:              w,
	}
	for _, opt := range opts {
		opt(r)
	}
	if r.createRequest.ChannelVolumes == nil {
		cvol := make(proto.ChannelVolumes, len(r.createRequest.ChannelMap))
		for i := range cvol {
			cvol[i] = 0x100
		}
		r.createRequest.ChannelVolumes = cvol
	}
	err := c.c.Request(&r.createRequest, &r.createReply)
	if err != nil {
		return nil, err
	}
	r.index = r.createReply.StreamIndex
	c.mu.Lock()
	c.record[r.index] = r
	c.mu.Unlock()
	return r, nil
}
func (r *RecordStream) write(buf []byte) {
	if r.err != nil {
		return
	}
	_, err := r.w.Write(buf)
	if err != nil {
		r.err = err
		go r.Stop()
	}
}
func (r *RecordStream) Start() {
	if r.state == idle {
		r.err = nil
		r.c.c.Request(&proto.FlushRecordStream{StreamIndex: r.index}, nil)
		r.c.c.Request(&proto.CorkRecordStream{StreamIndex: r.index, Corked: false}, nil)
		r.state = running
	}
}
func (r *RecordStream) Stop() {
	if r.state == running {
		r.c.c.Request(&proto.CorkRecordStream{StreamIndex: r.index, Corked: true}, nil)
		r.state = idle
	}
}
func (r *RecordStream) Close() {
	if !r.Closed() {
		r.c.c.Request(&proto.DeleteRecordStream{StreamIndex: r.index}, nil)
		r.state = closed
		r.c.mu.Lock()
		delete(r.c.record, r.index)
		r.c.mu.Unlock()
	}
}
func (r *RecordStream) Closed() bool { return r.state == closed || r.state == serverLost }
func (r *RecordStream) Running() bool { return r.state == running }
func (r *RecordStream) Error() error { return r.err }
func (r *RecordStream) SampleRate() int {
	return int(r.createReply.Rate)
}
func (r *RecordStream) Channels() int {
	return int(r.createReply.Channels)
}
func (r *RecordStream) StreamIndex() uint32 {
	return r.index
}
type RecordOption func(*RecordStream)
var RecordMono RecordOption = func(r *RecordStream) {
	r.createRequest.ChannelMap = proto.ChannelMap{proto.ChannelMono}
	r.createRequest.Channels = 1
}
var RecordStereo RecordOption = func(r *RecordStream) {
	r.createRequest.ChannelMap = proto.ChannelMap{proto.ChannelLeft, proto.ChannelRight}
	r.createRequest.Channels = 2
}
func RecordChannels(m proto.ChannelMap) RecordOption {
	if len(m) == 0 {
		panic("pulse: invalid channel map")
	}
	return func(r *RecordStream) {
		r.createRequest.ChannelMap = m
		r.createRequest.Channels = byte(len(m))
	}
}