File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
"encoding/binary"
6
7
"io"
@@ -78,6 +79,19 @@ func play(client *bot.Client, closeChan chan os.Signal) {
78
79
closeChan <- syscall .SIGTERM
79
80
}
80
81
82
+ // Test if the header is 4 bytes in size for some obscure and unknown reason.
83
+ func has4BitHeaders (file * os.File ) (bool , error ) {
84
+ var pad [2 ]byte
85
+ _ , err := file .ReadAt (pad [:], 2 )
86
+ if err != nil {
87
+ return false , err
88
+ }
89
+ if bytes .Equal (pad [:], []byte {0 , 0 }) {
90
+ return true , nil
91
+ }
92
+ return false , nil
93
+ }
94
+
81
95
func writeOpus (w io.Writer ) {
82
96
file , err := os .Open ("nico.dca" )
83
97
if err != nil {
@@ -86,10 +100,21 @@ func writeOpus(w io.Writer) {
86
100
ticker := time .NewTicker (time .Millisecond * 20 )
87
101
defer ticker .Stop ()
88
102
103
+ // support flag for skipping 2 bytes after each header
104
+ h4 , err := has4BitHeaders (file )
105
+ if err != nil {
106
+ panic ("error reading file: " + err .Error ())
107
+ }
108
+
89
109
var frameLen int16
90
110
// Don't wait for the first tick, run immediately.
91
111
for ; true ; <- ticker .C {
92
112
err = binary .Read (file , binary .LittleEndian , & frameLen )
113
+
114
+ if err == nil && h4 {
115
+ _ , err = file .Seek (2 , io .SeekCurrent )
116
+ }
117
+
93
118
if err != nil {
94
119
if err == io .EOF {
95
120
_ = file .Close ()
You can’t perform that action at this time.
0 commit comments