Skip to content

Commit

Permalink
docs: move PLC and FEC documentation to docstring
Browse files Browse the repository at this point in the history
People are more likely to read the API docs than the README.
  • Loading branch information
hraban committed Jul 10, 2020
1 parent 51473a1 commit 74001dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
24 changes: 4 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,10 @@ for i := 0; i < n; i++ {
}
```

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.
Note regarding Packet Loss Concealment (PLC):
> When a packet is considered "lost", `DecodePLC` and `DecodePLCFloat32` methods
> can be called in order to obtain something better sounding than just silence.
> 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.
> This option does not require any additional encoder options. Unlike FEC,
> PLC does not introduce additional latency. It is calculated from the previous
> packet, not from the next one.
> Note that `DecodeFEC` and `DecodeFECFloat32` automatically fall back to PLC
> when no FEC data is available in the provided packet.
To handle packet loss from an unreliable network, see the
[DecodePLC](https://godoc.org/gopkg.in/hraban/opus.v2#Decoder.DecodePLC) and
[DecodeFEC](https://godoc.org/gopkg.in/hraban/opus.v2#Decoder.DecodeFEC)
options.

### Streams (and Files)

Expand Down
26 changes: 24 additions & 2 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,20 @@ func (dec *Decoder) DecodeFloat32(data []byte, pcm []float32) (int, error) {
}

// DecodeFEC encoded Opus data into the supplied buffer with forward error
// 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
// 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
//
// When a packet is considered "lost", DecodeFEC 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.
//
// Note that DecodeFEC automatically falls back to PLC when no FEC data is
// available in the provided packet.
func (dec *Decoder) DecodeFEC(data []byte, pcm []int16) error {
if dec.p == nil {
return errDecUninitialized
Expand Down Expand Up @@ -179,7 +191,17 @@ func (dec *Decoder) DecodeFECFloat32(data []byte, pcm []float32) error {
}

// DecodePLC recovers a lost packet using Opus Packet Loss Concealment feature.
//
// The supplied buffer needs to be exactly the duration of audio that is missing.
// When a packet is considered "lost", `DecodePLC` and `DecodePLCFloat32` methods
// can be called in order to obtain something better sounding than just silence.
// 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.
//
// This option does not require any additional encoder options. Unlike FEC,
// PLC does not introduce additional latency. It is calculated from the previous
// packet, not from the next one.
func (dec *Decoder) DecodePLC(pcm []int16) error {
if dec.p == nil {
return errDecUninitialized
Expand Down

0 comments on commit 74001dc

Please sign in to comment.