Encode encodes a frame of PCM int16 samples. It returns the number of bytes written to out, or a negative error code.
(pcm []int16, frameSize int, out []byte)
| 158 | // Encode encodes a frame of PCM int16 samples. It returns the number of bytes |
| 159 | // written to out, or a negative error code. |
| 160 | func (e *Encoder) Encode(pcm []int16, frameSize int, out []byte) (int, error) { |
| 161 | if len(pcm) == 0 || len(out) == 0 { |
| 162 | return 0, errors.New("opus encode: empty input or output buffer") |
| 163 | } |
| 164 | n := cEncode(e.st, &pcm[0], int32(frameSize), &out[0], int32(len(out))) |
| 165 | if n < 0 { |
| 166 | return 0, fmt.Errorf("opus_encode failed: error %d", n) |
| 167 | } |
| 168 | return int(n), nil |
| 169 | } |
| 170 | |
| 171 | func (e *Encoder) SetBitrate(bitrate int) error { |
| 172 | if ret := cSetBitrate(e.st, int32(bitrate)); ret != 0 { |
no outgoing calls