README.md | 9 +++++++++ decoder.go | 6 ++++-- diff --git a/README.md b/README.md index 152737d8e06b3583ad958c95dfe9b6964a1d0d0b..28a67f8ef504ef24367cb04b9c48fc9cdb4f0187 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,15 @@ ch2 := pcm[(i*channels)+(channels-1)] } ``` +Note regarding Forward Error Correction (FEC): +> When a packet is considered "lost", `DecodeFEC` and `DecodeFECFloat32` methods +> can be called on the next packet in order to try and recover some of the lost +> data. The PCM needs to be exactly the duration of audio that is missing. +> `LastPacketDuration()` can be used on the decoder to get the length of the +> last packet. +> Note also that in order to use this feature the encoder needs to be configured +> with `SetInBandFEC(true)` and `SetPacketLossPerc(x)` options. + ### Streams (and files) To decode a .opus file (or .ogg with Opus data), or to decode a "Opus stream" diff --git a/decoder.go b/decoder.go index fe888ac1e323cabb5da65575f5725115662fc5d7..a3760ce2421a0fb333ec8fc01e75df66142bef7e 100644 --- a/decoder.go +++ b/decoder.go @@ -113,7 +113,8 @@ return n, nil } // DecodeFEC encoded Opus data into the supplied buffer with forward error -// correction. The supplied buffer will be entirely filled. +// correction. It is to be used on the packet directly following the lost one. +// The supplied buffer needs to be exactly the duration of audio that is missing func (dec *Decoder) DecodeFEC(data []byte, pcm []int16) error { if dec.p == nil { return errDecUninitialized @@ -139,7 +140,8 @@ return nil } // DecodeFECFloat32 encoded Opus data into the supplied buffer with forward error -// correction. The supplied buffer will be entirely filled. +// correction. It is to be used on the packet directly following the lost one. +// The supplied buffer needs to be exactly the duration of audio that is missing func (dec *Decoder) DecodeFECFloat32(data []byte, pcm []float32) error { if dec.p == nil { return errDecUninitialized