Decode decodes an Opus packet into pcm. frameSize is the max number of samples per channel that pcm can hold. Returns the number of decoded samples per channel.
(data []byte, pcm []int16, frameSize int, fec bool)
| 211 | // samples per channel that pcm can hold. Returns the number of decoded samples |
| 212 | // per channel. |
| 213 | func (d *Decoder) Decode(data []byte, pcm []int16, frameSize int, fec bool) (int, error) { |
| 214 | if len(pcm) == 0 { |
| 215 | return 0, errors.New("opus decode: empty output buffer") |
| 216 | } |
| 217 | |
| 218 | var dataPtr *byte |
| 219 | var dataLen int32 |
| 220 | if len(data) > 0 { |
| 221 | dataPtr = &data[0] |
| 222 | dataLen = int32(len(data)) |
| 223 | } |
| 224 | |
| 225 | decodeFec := int32(0) |
| 226 | if fec { |
| 227 | decodeFec = 1 |
| 228 | } |
| 229 | |
| 230 | n := cDecode(d.st, dataPtr, dataLen, &pcm[0], int32(frameSize), decodeFec) |
| 231 | if n < 0 { |
| 232 | return 0, fmt.Errorf("opus_decode failed: error %d", n) |
| 233 | } |
| 234 | return int(n), nil |
| 235 | } |
| 236 | |
| 237 | func (d *Decoder) Close() { |
| 238 | if d.st != 0 { |
no outgoing calls