mirror of
https://github.com/aler9/gortsplib
synced 2025-10-30 10:06:28 +08:00
improve examples (#708)
This commit is contained in:
24
examples/client-record-format-opus/dummy_audio.go
Normal file
24
examples/client-record-format-opus/dummy_audio.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import "math"
|
||||
|
||||
const (
|
||||
sampleRate = 48000
|
||||
frequency = 400
|
||||
amplitude = (1 << 14) - 1
|
||||
)
|
||||
|
||||
func createDummyAudio(pts int64, prevPTS int64) []byte {
|
||||
sampleCount := (pts - prevPTS)
|
||||
n := 0
|
||||
ret := make([]byte, sampleCount*2)
|
||||
|
||||
for i := int64(0); i < sampleCount; i++ {
|
||||
v := int16(amplitude * math.Sin((float64(prevPTS+i)*frequency*math.Pi*2)/sampleRate))
|
||||
ret[n] = byte(v >> 8)
|
||||
ret[n+1] = byte(v)
|
||||
n += 2
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
Reference in New Issue
Block a user