jogramming / dca

Go implementation for the DCA audio format
BSD 3-Clause "New" or "Revised" License
75 stars 60 forks source link

Sound plays 2x as fast if set 40 as FrameDuration #11

Closed acomagu closed 5 years ago

acomagu commented 5 years ago

I tried play sound with Discord VC.

Code:

option := &dca.EncodeOptions{
    Volume:           256,
    Channels:         2,
    FrameRate:        48000,
    FrameDuration:    40,
    Bitrate:          96,
    Application:      dca.AudioApplicationAudio,
    CompressionLevel: 10,
    PacketLoss:       1,
    BufferedFrames:   1024,
    VBR:              true,
}
encoder, err := dca.EncodeMem(r, option)
if err != nil {
    return err
}

for {
    frame, err := encoder.OpusFrame()
    if err == io.EOF {
        break
    }
    if err != nil {
        return err
    }

    conn.OpusSend <- frame
}

This plays it 2x as fast. Setting FrameDuration: 20 fix it. It's expected behavior?

Or maybe Discord side problem?(Sorry, but really I'm not familiar with DCA or Opus.)

acomagu commented 5 years ago

I increased the return value of PCMFrameLen(https://github.com/jonas747/dca/blob/10e959e9d3e808cd961308760de0c1c36285fed7/encode.go#L61) experimentally but didn't affect...

acomagu commented 5 years ago

I found the reason in discordgo. https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L411 The 960 is hard coded as the length of frame. I close this issue because it's discordgo problem. Sorry.