Skip to content

Commit

Permalink
Allow 2.5ms Opus frame
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Dec 6, 2024
1 parent d77d69a commit 6bb82b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/config/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Encoder struct {
}

type Audio struct {
Frame int
Frame float32
}

type Video struct {
Expand Down
9 changes: 6 additions & 3 deletions pkg/worker/media/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package media

import (
"fmt"
"math"
"sync"
"time"
"unsafe"
Expand Down Expand Up @@ -81,7 +82,9 @@ func DefaultOpus() (*opus.Encoder, error) {
}

// frame calculates an audio stereo frame size, i.e. 48k*frame/1000*2
func frame(hz int, frame int) int { return hz * frame / 1000 * 2 }
func frame(hz int, frame float32) int {
return int(math.Round(float64(hz) * float64(frame) / 1000 * 2))
}

// stretch does a simple stretching of audio samples.
// something like: [1,2,3,4,5,6] -> [1,2,x,x,3,4,x,x,5,6,x,x] -> [1,2,1,2,3,4,3,4,5,6,5,6]
Expand Down Expand Up @@ -114,7 +117,7 @@ type WebrtcMediaPipe struct {
vConf config.Video

AudioSrcHz int
AudioFrame int
AudioFrame float32
VideoW, VideoH int
VideoScale float64

Expand Down Expand Up @@ -162,7 +165,7 @@ func (wmp *WebrtcMediaPipe) Init() error {
return nil
}

func (wmp *WebrtcMediaPipe) initAudio(srcHz int, frameSize int) error {
func (wmp *WebrtcMediaPipe) initAudio(srcHz int, frameSize float32) error {
au, err := DefaultOpus()
if err != nil {
return fmt.Errorf("opus fail: %w", err)
Expand Down

0 comments on commit 6bb82b2

Please sign in to comment.