@@ -353,6 +353,7 @@ func TestSynthesizer_PlayStop(t *testing.T) {
353
353
assertSilence (t , buffer )
354
354
355
355
t .Run ("and next note with max volume should be played" , func (t * testing.T ) {
356
+ assert .Equal (t , 2 , synth .Stat ().Sfx [0 ].Note )
356
357
synth .ReadSamples (buffer )
357
358
assertNotSilence (t , buffer )
358
359
})
@@ -415,7 +416,7 @@ func TestSynthesizer_PlayStop(t *testing.T) {
415
416
synth .Play (sfxNo , - 1 , 0 , 1 )
416
417
// then
417
418
stat := synth .Stat ()
418
- assert .Equal (t , sfxNo , stat .Sfx [3 ])
419
+ assert .Equal (t , sfxNo , stat .Sfx [3 ]. SfxNo )
419
420
assertNotSilence (t , readSamples (synth , durationOfNoteWhenSpeedIsOne ))
420
421
})
421
422
@@ -435,7 +436,7 @@ func TestSynthesizer_PlayStop(t *testing.T) {
435
436
synth .Play (sfxNo , - 1 , 0 , 1 )
436
437
// then
437
438
stat := synth .Stat ()
438
- assert .Equal (t , sfxNo , stat .Sfx [3 ])
439
+ assert .Equal (t , sfxNo , stat .Sfx [3 ]. SfxNo )
439
440
assertNotSilence (t , readSamples (synth , durationOfNoteWhenSpeedIsOne ))
440
441
})
441
442
@@ -451,8 +452,8 @@ func TestSynthesizer_PlayStop(t *testing.T) {
451
452
synth .Play (0 , 1 , 0 , 1 )
452
453
// then
453
454
stat := synth .Stat ()
454
- assert .Equal (t , - 1 , stat .Sfx [0 ])
455
- assert .Equal (t , 0 , stat .Sfx [1 ])
455
+ assert .Equal (t , - 1 , stat .Sfx [0 ]. SfxNo )
456
+ assert .Equal (t , 0 , stat .Sfx [1 ]. SfxNo )
456
457
// and
457
458
signal := readSamples (synth , durationOfNoteWhenSpeedIsOne )
458
459
expectedSignal := generateSamples (e , durationOfNoteWhenSpeedIsOne )
@@ -477,7 +478,7 @@ func TestSynthesizer_PlayStop(t *testing.T) {
477
478
synth .Stop (- 1 )
478
479
// then
479
480
stat := synth .Stat ()
480
- assert .Equal (t , - 1 , stat .Sfx [0 ])
481
+ assert .Equal (t , - 1 , stat .Sfx [0 ]. SfxNo )
481
482
// and
482
483
assertSilence (t , readSamples (synth , durationOfNoteWhenSpeedIsOne ))
483
484
})
@@ -500,7 +501,7 @@ func TestSynthesizer_PlayStop(t *testing.T) {
500
501
synth .StopChan (- 1 )
501
502
// then
502
503
stat := synth .Stat ()
503
- assert .Equal (t , - 1 , stat .Sfx [0 ])
504
+ assert .Equal (t , - 1 , stat .Sfx [0 ]. SfxNo )
504
505
// and
505
506
assertSilence (t , readSamples (synth , durationOfNoteWhenSpeedIsOne ))
506
507
})
@@ -522,7 +523,7 @@ func TestSynthesizer_PlayStop(t *testing.T) {
522
523
synth .Play (0 , ch , 0 , 1 )
523
524
// then
524
525
stat := synth .Stat ()
525
- assert .Equal (t , 0 , stat .Sfx [0 ])
526
+ assert .Equal (t , 0 , stat .Sfx [0 ]. SfxNo )
526
527
// and
527
528
assertNotSilence (t , readSamples (synth , durationOfNoteWhenSpeedIsOne ))
528
529
})
@@ -546,7 +547,7 @@ func TestSynthesizer_PlayStop(t *testing.T) {
546
547
synth .Play (sfxNo , 0 , 0 , 1 )
547
548
// then
548
549
stat := synth .Stat ()
549
- assert .Equal (t , 0 , stat .Sfx [0 ])
550
+ assert .Equal (t , 0 , stat .Sfx [0 ]. SfxNo )
550
551
// and
551
552
assertNotSilence (t , readSamples (synth , durationOfNoteWhenSpeedIsOne ))
552
553
})
@@ -928,6 +929,107 @@ func sfxLengthTest(t *testing.T) {
928
929
})
929
930
}
930
931
932
+ func TestSynthesizer_Stat (t * testing.T ) {
933
+ t .Run ("should return sfx stat when no sfx were played" , func (t * testing.T ) {
934
+ var synth audio.Synthesizer
935
+ expected := audio.SfxStat {
936
+ SfxNo : - 1 ,
937
+ Note : - 1 ,
938
+ Remaining : 0 ,
939
+ }
940
+ stat := synth .Stat ()
941
+ for i := 0 ; i < maxChannels ; i ++ {
942
+ assert .Equal (t , expected , stat .Sfx [i ])
943
+ }
944
+ })
945
+
946
+ t .Run ("should return issued note" , func (t * testing.T ) {
947
+ for note := 0 ; note < 2 ; note ++ {
948
+ var synth audio.Synthesizer
949
+ synth .Play (0 , 0 , note , 0 )
950
+ assert .Equal (t , note , synth .Stat ().Sfx [0 ].Note )
951
+ }
952
+ })
953
+
954
+ t .Run ("should return issued remaining notes" , func (t * testing.T ) {
955
+ for length := 1 ; length < 3 ; length ++ {
956
+ var synth audio.Synthesizer
957
+ synth .Play (0 , 0 , 0 , length )
958
+ assert .Equal (t , length , synth .Stat ().Sfx [0 ].Remaining )
959
+ }
960
+ })
961
+
962
+ t .Run ("should return 32 when issued length was 0" , func (t * testing.T ) {
963
+ var synth audio.Synthesizer
964
+ synth .Play (0 , 0 , 0 , 0 )
965
+ assert .Equal (t , 32 , synth .Stat ().Sfx [0 ].Remaining )
966
+ })
967
+
968
+ t .Run ("should return -1 when sfx has loop" , func (t * testing.T ) {
969
+ var synth audio.Synthesizer
970
+ synth .SetSfx (0 , audio.SoundEffect {
971
+ LoopStart : 0 ,
972
+ LoopStop : 1 ,
973
+ })
974
+ synth .Play (0 , 0 , 0 , 0 )
975
+ assert .Equal (t , - 1 , synth .Stat ().Sfx [0 ].Remaining )
976
+ })
977
+
978
+ t .Run ("should return -1 when sfx was updated after played" , func (t * testing.T ) {
979
+ var synth audio.Synthesizer
980
+ synth .Play (0 , 0 , 0 , 0 )
981
+ synth .SetSfx (0 , audio.SoundEffect {
982
+ LoopStart : 0 ,
983
+ LoopStop : 1 ,
984
+ })
985
+ assert .Equal (t , - 1 , synth .Stat ().Sfx [0 ].Remaining )
986
+ })
987
+
988
+ t .Run ("should return length when sfx.LoopStart > sfx.LoopStop" , func (t * testing.T ) {
989
+ var synth audio.Synthesizer
990
+ synth .SetSfx (0 , audio.SoundEffect {
991
+ LoopStart : 1 , // len=1
992
+ LoopStop : 0 ,
993
+ })
994
+ synth .Play (0 , 0 , 0 , 0 )
995
+ assert .Equal (t , 1 , synth .Stat ().Sfx [0 ].Remaining )
996
+ })
997
+
998
+ t .Run ("should return min length when sfx.LoopStart > sfx.LoopStop" , func (t * testing.T ) {
999
+ var synth audio.Synthesizer
1000
+ synth .SetSfx (0 , audio.SoundEffect {
1001
+ LoopStart : 3 , // len=3
1002
+ LoopStop : 0 ,
1003
+ })
1004
+ synth .Play (0 , 0 , 0 , 2 ) // len=2
1005
+ assert .Equal (t , 2 , synth .Stat ().Sfx [0 ].Remaining )
1006
+ })
1007
+
1008
+ t .Run ("should return remaining notes after one note was played" , func (t * testing.T ) {
1009
+ var synth audio.Synthesizer
1010
+ synth .Play (0 , 0 , 0 , 2 )
1011
+ readSamples (& synth , durationOfNoteWhenSpeedIsOne )
1012
+ assert .Equal (t , 1 , synth .Stat ().Sfx [0 ].Remaining )
1013
+ })
1014
+
1015
+ t .Run ("should return 32 when length higher than 32" , func (t * testing.T ) {
1016
+ var synth audio.Synthesizer
1017
+ synth .Play (0 , 0 , 0 , 33 )
1018
+ assert .Equal (t , 32 , synth .Stat ().Sfx [0 ].Remaining )
1019
+ })
1020
+
1021
+ t .Run ("should return remaining notes when sfx has length (loop start > loop stop) and one was played" , func (t * testing.T ) {
1022
+ var synth audio.Synthesizer
1023
+ synth .SetSfx (0 , audio.SoundEffect {
1024
+ LoopStart : 3 , // len=3
1025
+ LoopStop : 0 ,
1026
+ })
1027
+ synth .Play (0 , 0 , 0 , 2 )
1028
+ readSamples (& synth , durationOfNoteWhenSpeedIsOne )
1029
+ assert .Equal (t , 1 , synth .Stat ().Sfx [0 ].Remaining )
1030
+ })
1031
+ }
1032
+
931
1033
func readSamples (synth * audio.Synthesizer , size int ) []float64 {
932
1034
buffer := make ([]float64 , size )
933
1035
synth .ReadSamples (buffer )
0 commit comments