@@ -12,22 +12,20 @@ describe('p5.PolySynth', function () {
12
12
const polySynth = new p5 . PolySynth ( ) ;
13
13
const noteDuration = 0.01 ;
14
14
15
- const noteTriggerTime = audioContext . currentTime ;
16
- const noteActiveTime = noteTriggerTime + noteDuration / 2 ;
17
- const noteDoneTime = noteTriggerTime + noteDuration ;
15
+ const getTriggerTime = ( ) => audioContext . currentTime ;
16
+ const getActiveTime = ( ) => getTriggerTime ( ) + noteDuration / 2 ;
17
+ const getDoneTime = ( ) => getTriggerTime ( ) + noteDuration ;
18
18
19
- expect ( polySynth . _voicesInUse . getValueAtTime ( noteTriggerTime ) ) . to . equal ( 0 ) ;
19
+ expect ( polySynth . _voicesInUse . getValueAtTime ( getTriggerTime ( ) ) ) . to . equal ( 0 ) ;
20
20
21
21
polySynth . play ( 'A2' , 0 , 0 , noteDuration ) ;
22
- expect ( polySynth . _voicesInUse . getValueAtTime ( noteActiveTime ) ) . to . equal ( 1 ) ;
22
+ expect ( polySynth . _voicesInUse . getValueAtTime ( getActiveTime ( ) ) ) . to . equal ( 1 ) ;
23
23
polySynth . play ( 'A3' , 0 , 0 , noteDuration ) ;
24
- expect ( polySynth . _voicesInUse . getValueAtTime ( noteActiveTime ) ) . to . equal ( 2 ) ;
24
+ expect ( polySynth . _voicesInUse . getValueAtTime ( getActiveTime ( ) ) ) . to . equal ( 2 ) ;
25
25
polySynth . play ( 'A4' , 0 , 0 , noteDuration ) ;
26
- expect ( polySynth . _voicesInUse . getValueAtTime ( noteActiveTime ) ) . to . equal ( 3 ) ;
26
+ expect ( polySynth . _voicesInUse . getValueAtTime ( getActiveTime ( ) ) ) . to . equal ( 3 ) ;
27
27
28
- setTimeout ( ( ) => {
29
- expect ( polySynth . _voicesInUse . getValueAtTime ( noteDoneTime ) ) . to . equal ( 0 ) ;
30
- } , 10 ) ;
28
+ expect ( polySynth . _voicesInUse . getValueAtTime ( getDoneTime ( ) ) ) . to . equal ( 0 ) ;
31
29
32
30
polySynth . dispose ( ) ;
33
31
} ) ;
0 commit comments