Add support two channel PCM family audio #580

This commit is contained in:
Alexey Khit
2023-08-21 15:34:53 +03:00
parent 69a3a30a0e
commit bf248c49c3
3 changed files with 14 additions and 9 deletions
+4 -8
View File
@@ -48,13 +48,9 @@ func FLACHeader(magic bool, sampleRate uint32) []byte {
var table8 *crc8.Table
var table16 *crc16.Table
func FLACEncoder(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
if codec.Channels >= 2 {
return nil
}
func FLACEncoder(codecName string, clockRate uint32, handler core.HandlerFunc) core.HandlerFunc {
var sr byte
switch codec.ClockRate {
switch clockRate {
case 8000:
sr = 0b0100
case 16000:
@@ -87,7 +83,7 @@ func FLACEncoder(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
return func(packet *rtp.Packet) {
samples := uint16(len(packet.Payload))
if codec.Name == core.CodecPCM || codec.Name == core.CodecPCML {
if codecName == core.CodecPCM || codecName == core.CodecPCML {
samples /= 2
}
@@ -115,7 +111,7 @@ func FLACEncoder(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
n += 1
// 3. Subframe
switch codec.Name {
switch codecName {
case core.CodecPCMA:
for _, b := range packet.Payload {
s16 := PCMAtoPCM(b)
+4
View File
@@ -11,6 +11,10 @@ import (
func ResampleToG711(codec *core.Codec, sampleRate uint32, handler core.HandlerFunc) core.HandlerFunc {
n := float32(codec.ClockRate) / float32(sampleRate)
if codec.Channels == 2 {
n *= 2 // hacky way for support two channels audio
}
switch codec.Name {
case core.CodecPCMA:
return DownsampleByte(PCMAtoPCM, PCMtoPCMA, n, handler)