-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudio.go
844 lines (648 loc) · 17.8 KB
/
audio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
package fnf
import (
"bytes"
"errors"
"fmt"
"io"
"strings"
"sync"
"time"
"github.com/hajimehoshi/ebiten/v2/audio/mp3"
"github.com/hajimehoshi/ebiten/v2/audio/vorbis"
"github.com/hajimehoshi/ebiten/v2/audio/wav"
"github.com/ebitengine/oto/v3"
)
const SampleRate = 44100
const BytesPerSample = 4
var TheContext *oto.Context
var TheAudioManager struct {
globalVolume float64
players []*VaryingSpeedPlayer
}
func InitAudio() error {
TheAudioManager.globalVolume = 1.0
contextOp := oto.NewContextOptions{
SampleRate: SampleRate,
ChannelCount: 2,
Format: oto.FormatSignedInt16LE,
BufferSize: 0,
}
var contextReady chan struct{}
var err error
TheContext, contextReady, err = oto.NewContext(&contextOp)
if err != nil {
return err
}
<-contextReady
return nil
}
func UpdateAudio() {
volume := Clamp(TheOptions.Volume, 0, 1)
if volume != TheAudioManager.globalVolume {
TheAudioManager.globalVolume = volume
for _, p := range TheAudioManager.players {
p.SetVolume(p.Volume())
}
}
}
type AudioDecoder interface {
io.ReadSeeker
Length() int64
}
func NewAudioDeocoder(rawFile []byte, fileType string) (AudioDecoder, error) {
bReader := bytes.NewReader(rawFile)
if strings.HasSuffix(strings.ToLower(fileType), "mp3") {
if decoder, err := mp3.DecodeWithSampleRate(SampleRate, bReader); err != nil {
return nil, err
} else {
return decoder, nil
}
} else if strings.HasSuffix(strings.ToLower(fileType), "ogg") {
if decoder, err := vorbis.DecodeWithSampleRate(SampleRate, bReader); err != nil {
return nil, err
} else {
return decoder, nil
}
} else if strings.HasSuffix(strings.ToLower(fileType), "wav") {
if decoder, err := wav.DecodeWithSampleRate(SampleRate, bReader); err != nil {
return nil, err
} else {
return decoder, nil
}
} else {
return nil, fmt.Errorf("can't decode audio format %v", fileType)
}
}
type VaryingSpeedPlayer struct {
stream *VaryingSpeedStream
player *oto.Player
padStart time.Duration
padEnd time.Duration
volume float64
isPlaying bool
}
func NewVaryingSpeedPlayer(padStart, padEnd time.Duration) *VaryingSpeedPlayer {
vp := new(VaryingSpeedPlayer)
vp.padStart = padStart
vp.padEnd = padEnd
vp.volume = 1.0
TheAudioManager.players = append(TheAudioManager.players, vp)
return vp
}
func (vp *VaryingSpeedPlayer) IsReady() bool {
return vp.player != nil && vp.stream != nil
}
// If you want to decode the audio, pass raw file bytes, filetype and whether to decode audio in background or not.
//
// If your audio bytes are already decoded, just pass in bytes.
func (vp *VaryingSpeedPlayer) loadAudioImpl(audioBytes []byte, isAudioDecoded bool, fileType string, decodeAudioInBackground bool) error {
if vp.player != nil {
vp.player.Close()
vp.player = nil
}
if vp.stream != nil {
vp.stream.QuitBackgroundDecoding()
vp.stream = nil
}
// NOTE : this isn't a seperate function because I have a strong feeling that
// this is not an exact inverse to ByteLengthToTimeDuration
// nor it needs to be
timeToBytes := func(t time.Duration) int64 {
var b int64
b = int64(t) * SampleRate / int64(time.Second) * BytesPerSample
b = (b / BytesPerSample) * BytesPerSample
b += BytesPerSample
return b
}
padStartBytes := timeToBytes(vp.padStart)
padEndBytes := timeToBytes(vp.padEnd)
var stream *VaryingSpeedStream
if !isAudioDecoded {
var err error
stream, err = NewVaryingSpeedStream(
audioBytes, fileType, padStartBytes, padEndBytes, decodeAudioInBackground)
if err != nil {
return err
}
} else {
stream = NewVaryingSpeedStreamFromDecodedAudio(audioBytes, padStartBytes, padEndBytes)
}
player := TheContext.NewPlayer(stream)
// we need the ability to change the playback speed in real time
// so we need to make the buffer size smaller
// TODO : is this really the right size?
//const buffSizeTime = time.Second / 20
const buffSizeTime = time.Second / 5
buffSizeBytes := int(buffSizeTime) * SampleRate / int(time.Second) * BytesPerSample
player.SetBufferSize(int(buffSizeBytes))
vp.player = player
vp.stream = stream
vp.SetVolume(vp.Volume())
return nil
}
func (vp *VaryingSpeedPlayer) LoadAudio(rawFile []byte, fileType string, decodeAudioInBackground bool) error {
if err := vp.loadAudioImpl(rawFile, false, fileType, decodeAudioInBackground); err != nil {
return err
}
return nil
}
func (vp *VaryingSpeedPlayer) LoadDecodedAudio(decodedAudio []byte) {
vp.loadAudioImpl(decodedAudio, true, "", false)
}
// TODO : Position and SetPosition is fucked
//
// if you do something like
// for i:=0; i<1000; i++{
// pos := vp.Positon()
// vp.SetPosition(pos)
// }
//
// position will change
func (vp *VaryingSpeedPlayer) Position() time.Duration {
if !vp.IsReady() {
return 0
}
streamPos := vp.stream.BytePosition()
buffSize := vp.player.BufferedSize()
pos := float64(streamPos) - float64(buffSize)*vp.Speed()
return ByteLengthToTimeDuration(int64(pos))
}
func (vp *VaryingSpeedPlayer) SetPosition(offset time.Duration) {
if !vp.IsReady() {
return
}
duration := vp.AudioDuration()
if offset >= duration {
offset = duration
} else if offset < 0 {
offset = 0
}
bytePos := vp.stream.TimeDurationToPos(offset)
vp.player.Seek(bytePos, io.SeekStart)
}
func (vp *VaryingSpeedPlayer) IsPlaying() bool {
if !vp.IsReady() {
return false
}
return vp.player.IsPlaying()
}
func (vp *VaryingSpeedPlayer) Pause() {
if vp.IsReady() && vp.player.IsPlaying() {
vp.player.Pause()
}
}
func (vp *VaryingSpeedPlayer) Play() {
if vp.IsReady() && !vp.player.IsPlaying() {
vp.player.Play()
}
}
func (vp *VaryingSpeedPlayer) Rewind() {
if vp.IsReady() {
vp.player.Seek(0, io.SeekStart)
}
}
func (vp *VaryingSpeedPlayer) SetVolume(volume float64) {
volume = Clamp(volume, 0, 1)
vp.volume = volume
if vp.IsReady() {
vp.player.SetVolume(TheAudioManager.globalVolume * volume)
}
}
func (vp *VaryingSpeedPlayer) Volume() float64 {
return vp.volume
}
func (vp *VaryingSpeedPlayer) Speed() float64 {
return vp.stream.Speed()
}
func (vp *VaryingSpeedPlayer) SetSpeed(speed float64) {
if speed <= 0 {
panic("VaryingSpeedStream: speed should be bigger than 0")
}
// if we don't do this, changing speed changes the audio position
// by doing this, we empty the buffer of internal player while maintaining position
if !vp.IsPlaying() {
vp.SetPosition(vp.Position())
}
vp.stream.SetSpeed(speed)
}
func (vp *VaryingSpeedPlayer) AudioDuration() time.Duration {
if !vp.IsReady() {
return 0
}
return vp.stream.AudioDuration()
}
func (vp *VaryingSpeedPlayer) AudioBytesSize() int64 {
if !vp.IsReady() {
return 0
}
return vp.stream.AudioBytesSize()
}
func (vp *VaryingSpeedPlayer) DecodedBytesSize() int64 {
if !vp.IsReady() {
return 0
}
return vp.stream.DecodedBytesSize()
}
func (vp *VaryingSpeedPlayer) DecodedDuration() time.Duration {
if !vp.IsReady() {
return 0
}
return vp.stream.DecodedDuration()
}
func (vp *VaryingSpeedPlayer) QuitBackgroundDecoding() {
if vp.IsReady() {
vp.stream.QuitBackgroundDecoding()
}
}
type VaryingSpeedStream struct {
io.ReadSeeker
speed float64
length int64
padStart int64
padEnd int64
buffer []byte
bytePosition int64
usingBgDecoding bool
bgDecoderQueue chan byte
bgDecoderQuit bool
bgDecoderMu sync.Mutex
decodedBytesSize int64
mu sync.Mutex
}
func NewVaryingSpeedStream(
rawFile []byte, fileType string, padStart, padEnd int64, decodeAudioInBackground bool,
) (*VaryingSpeedStream, error) {
vs := new(VaryingSpeedStream)
vs.speed = 1.0
if padStart%BytesPerSample != 0 {
ErrorLogger.Fatal("padStart is not divisible by BytesPerSample")
}
if padEnd%BytesPerSample != 0 {
ErrorLogger.Fatal("padEnd is not divisible by BytesPerSample")
}
vs.padStart = padStart
vs.padEnd = padEnd
var err error
if decodeAudioInBackground {
goto DECODE_BG
} else {
goto DECODE_EVERYTHING
}
DECODE_BG:
FnfLogger.Println("decoding audio in background")
if err = vs.startBgDecoding(rawFile, fileType); err == nil {
return vs, nil
}
if errors.Is(err, errUndeterminedAudioLength) {
FnfLogger.Println("couldn't get known audio length, decoding the whole audio")
goto DECODE_EVERYTHING
} else {
return nil, err
}
DECODE_EVERYTHING:
FnfLogger.Println("decoding the whole audio")
if err = vs.decodeWholeAudio(rawFile, fileType); err != nil {
return nil, err
}
return vs, nil
}
var errUndeterminedAudioLength = errors.New("could not determine audio length before decoding")
func (vs *VaryingSpeedStream) startBgDecoding(rawFile []byte, fileType string) error {
decoder, decoderErr := NewAudioDeocoder(rawFile, fileType)
if decoderErr != nil {
return decoderErr
}
length := decoder.Length()
if length <= 0 {
return errUndeterminedAudioLength
}
vs.usingBgDecoding = true
vs.length = length
vs.bgDecoderQueue = make(chan byte, length)
vs.buffer = make([]byte, 0, length)
go func() {
buffer := make([]byte, 0, BytesPerSample*16)
sent := int64(0)
for {
buff := buffer[:cap(buffer)]
n, err := decoder.Read(buff)
sent += int64(n)
buff = buff[:n]
for _, b := range buff {
vs.bgDecoderQueue <- b
}
doBreak := false
if err != nil {
doBreak = true
}
vs.bgDecoderMu.Lock()
vs.decodedBytesSize = sent
if vs.bgDecoderQuit {
doBreak = true
}
vs.bgDecoderMu.Unlock()
if doBreak {
break
}
}
// fill the rest with zeros
// we don't care if we stopped midway cause of an error
toSend := length - sent
for i := int64(0); i < toSend; i++ {
vs.bgDecoderQueue <- 0
}
vs.bgDecoderMu.Lock()
vs.decodedBytesSize = length
vs.bgDecoderMu.Unlock()
}()
return nil
}
func (vs *VaryingSpeedStream) decodeWholeAudio(rawFile []byte, fileType string) error {
if buffer, err := DecodeWholeAudio(rawFile, fileType); err == nil {
vs.usingBgDecoding = false
vs.buffer = buffer
vs.length = int64(len(buffer))
vs.decodedBytesSize = int64(len(buffer))
return nil
} else {
return err
}
}
func NewVaryingSpeedStreamFromDecodedAudio(decodedAudio []byte, padStart, padEnd int64) *VaryingSpeedStream {
vs := new(VaryingSpeedStream)
vs.speed = 1.0
if padStart%BytesPerSample != 0 {
ErrorLogger.Fatal("padStart is not divisible by BytesPerSample")
}
if padEnd%BytesPerSample != 0 {
ErrorLogger.Fatal("padEnd is not divisible by BytesPerSample")
}
vs.padStart = padStart
vs.padEnd = padEnd
vs.usingBgDecoding = false
vs.buffer = decodedAudio
vs.length = int64(len(decodedAudio))
vs.decodedBytesSize = int64(len(decodedAudio))
return vs
}
func (vs *VaryingSpeedStream) readSrc(at int64) byte {
if at < vs.padStart {
return 0
}
if at >= vs.padStart+vs.length {
return 0
}
at -= vs.padStart
if at < int64(len(vs.buffer)) {
return vs.buffer[at]
}
if vs.usingBgDecoding {
for at >= int64(len(vs.buffer)) {
b := <-vs.bgDecoderQueue
vs.buffer = append(vs.buffer, b)
}
}
return vs.buffer[at]
}
func (vs *VaryingSpeedStream) Read(p []byte) (int, error) {
vs.mu.Lock()
defer vs.mu.Unlock()
wCursor := 0
wCursorLimit := (len(p) / BytesPerSample) * BytesPerSample
floatPosition := float64(vs.bytePosition)
for {
if vs.bytePosition+BytesPerSample >= vs.audioBytesSize() {
return wCursor, io.EOF
}
if wCursor+BytesPerSample >= wCursorLimit {
return wCursor, nil
}
p[wCursor+0] = vs.readSrc(vs.bytePosition + 0)
p[wCursor+1] = vs.readSrc(vs.bytePosition + 1)
p[wCursor+2] = vs.readSrc(vs.bytePosition + 2)
p[wCursor+3] = vs.readSrc(vs.bytePosition + 3)
wCursor += BytesPerSample
floatPosition += vs.speed * BytesPerSample
vs.bytePosition = (int64(floatPosition) / BytesPerSample) * BytesPerSample
}
}
func (vs *VaryingSpeedStream) Seek(offset int64, whence int) (int64, error) {
vs.mu.Lock()
defer vs.mu.Unlock()
var abs int64
switch whence {
case io.SeekStart:
abs = offset
case io.SeekCurrent:
abs = vs.bytePosition + offset
case io.SeekEnd:
var totalLen int64 = vs.audioBytesSize()
abs = totalLen + offset
default:
return 0, errors.New("VaryingSpeedStream.Seek: invalid whence")
}
if abs < 0 {
return 0, errors.New("VaryingSpeedStream.Seek: negative position")
}
vs.bytePosition = abs
return vs.bytePosition, nil
}
func (vs *VaryingSpeedStream) Speed() float64 {
vs.mu.Lock()
defer vs.mu.Unlock()
return vs.speed
}
func (vs *VaryingSpeedStream) SetSpeed(speed float64) {
vs.mu.Lock()
defer vs.mu.Unlock()
vs.speed = speed
}
func (vs *VaryingSpeedStream) BytePosition() int64 {
vs.mu.Lock()
defer vs.mu.Unlock()
return vs.bytePosition
}
func (vs *VaryingSpeedStream) audioBytesSize() int64 {
total := vs.padStart + vs.length + vs.padEnd
return total
}
func (vs *VaryingSpeedStream) AudioBytesSize() int64 {
vs.mu.Lock()
defer vs.mu.Unlock()
return vs.audioBytesSize()
}
func (vs *VaryingSpeedStream) AudioDuration() time.Duration {
vs.mu.Lock()
defer vs.mu.Unlock()
return ByteLengthToTimeDuration(vs.audioBytesSize())
}
func (vs *VaryingSpeedStream) DecodedBytesSize() int64 {
vs.bgDecoderMu.Lock()
defer vs.bgDecoderMu.Unlock()
return vs.padStart + vs.decodedBytesSize + vs.padEnd
}
func (vs *VaryingSpeedStream) DecodedDuration() time.Duration {
duration := vs.DecodedBytesSize()
return ByteLengthToTimeDuration(duration)
}
func (vs *VaryingSpeedStream) QuitBackgroundDecoding() {
vs.bgDecoderMu.Lock()
defer vs.bgDecoderMu.Unlock()
vs.bgDecoderQuit = true
}
// This is directly copied from ebiten's Time stream struct
// at github.com/hajimehoshi/ebiten/[email protected]/audio/player.go
func (vs *VaryingSpeedStream) TimeDurationToPos(offset time.Duration) int64 {
vs.mu.Lock()
defer vs.mu.Unlock()
o := int64(offset) * BytesPerSample * int64(SampleRate) / int64(time.Second)
// Align the byte position with the samples.
o -= o % BytesPerSample
o += vs.bytePosition % BytesPerSample
return o
}
func ByteLengthToTimeDuration(byteLength int64) time.Duration {
t := time.Duration(byteLength) / BytesPerSample
return t * time.Second / time.Duration(SampleRate)
}
// TODO : DecodeWholeAudio funciton fails when trying to decode very short audio
// multithreaded.
func DecodeWholeAudio(rawFile []byte, fileType string) ([]byte, error) {
{
timer := NewProfTimer("DecodeWholeAudio")
defer timer.Report()
}
const alwaysDecodeSingleThreaded bool = false
const checkIfDecodingWithGoroutinesIsCorrect bool = false
const jobCount = 16
var decoders []AudioDecoder
for range jobCount {
if decoder, err := NewAudioDeocoder(rawFile, fileType); err != nil {
return nil, err
} else {
decoders = append(decoders, decoder)
}
}
// init audio bytes
var totalLen int64
{
totalLen = decoders[0].Length()
// audio file's total length is not available
// we have to just read it until we encounter EOF
if totalLen <= 0 || alwaysDecodeSingleThreaded {
FnfLogger.Println("decoding whole audio using single thread")
audioBytes, err := io.ReadAll(decoders[0])
if err != nil {
return nil, err
}
return audioBytes, nil
}
FnfLogger.Println("decoding whole audio using go routines")
}
// divide and ceil
partLen := (totalLen + jobCount - 1) / jobCount
// closest multiple to bytes per sample (larger one)
partLen = (partLen/BytesPerSample)*BytesPerSample + BytesPerSample
var wg sync.WaitGroup
decodeErrors := make([]error, jobCount)
decodedBytes := make([][]byte, jobCount)
for i := range jobCount {
decodedBytes[i] = make([]byte, 0, partLen)
}
for i := range int64(jobCount) {
wg.Add(1)
go func() {
defer wg.Done()
isLastPart := i == jobCount-1
var partStart, partEnd int64
partStart = i * partLen
if isLastPart {
partEnd = totalLen
} else {
partEnd = (i + 1) * partLen
}
// first seek to where we want to read
{
var err error
var offset int64
offset, err = decoders[i].Seek(partStart, io.SeekStart)
if err != nil {
decodeErrors[i] = err
return
}
if offset != partStart {
decodeErrors[i] = fmt.Errorf("seek failed : expected: \"%v\" got: \"%v\"",
partStart, offset)
return
}
}
// we read the desired amount
amoutToRead := partEnd - partStart
for {
buf := decodedBytes[i]
var err error
var read int
read, err = decoders[i].Read(buf[len(buf):amoutToRead])
buf = buf[:len(buf)+read]
// some error occured
if err != nil && !(errors.Is(err, io.EOF) && isLastPart) {
decodeErrors[i] = err
return
}
// if we read 0 bytes, we stop just to be safe
if read <= 0 {
decodeErrors[i] = fmt.Errorf("read 0 bytes while decoding")
return
}
// check if we stopped becaun of EOF before reading required amount
if err == io.EOF && int64(len(buf)) < amoutToRead {
decodeErrors[i] = fmt.Errorf("supposed to read \"%v\" but only read \"%v\" because EOF",
amoutToRead, len(buf))
return
}
decodedBytes[i] = buf
if int64(len(decodedBytes[i])) >= amoutToRead {
break
}
}
}()
}
wg.Wait()
for _, err := range decodeErrors {
if err != nil {
return nil, err
}
}
var audioBytes []byte
for _, bs := range decodedBytes {
audioBytes = append(audioBytes, bs...)
}
if int64(len(audioBytes)) != totalLen {
return nil, fmt.Errorf("audio file size is different : expected: \"%v\", got: \"%v\"",
totalLen, len(audioBytes))
}
// debug check to see if it matches reading it single threaded
if checkIfDecodingWithGoroutinesIsCorrect {
var decoder AudioDecoder
var err error
decoder, err = NewAudioDeocoder(rawFile, fileType)
var toCompare []byte
toCompare, err = io.ReadAll(decoder)
if err != nil {
return nil, err
}
// check length
if len(toCompare) != len(audioBytes) {
return nil, fmt.Errorf("audio decoded with multiple goroutines have different length: expected: \"%v\" got: \"%v\"",
len(toCompare), len(audioBytes))
}
for i := range len(toCompare) {
if toCompare[i] != audioBytes[i] {
return nil, fmt.Errorf(
"audio decoded with multiple goroutines has different value %d : %X %X",
i, toCompare[i], audioBytes[i])
}
}
}
return audioBytes, nil
}