1
1
const expect = chai . expect ;
2
2
3
3
describe ( 'p5.SoundRecorder' , function ( ) {
4
- let recorder ;
5
4
let inputSoundFile ;
6
5
let writeFileSub ;
7
6
@@ -33,17 +32,34 @@ describe('p5.SoundRecorder', function () {
33
32
} ) ;
34
33
35
34
beforeEach ( function ( ) {
36
- recorder = new p5 . SoundRecorder ( ) ;
37
35
inputSoundFile . disconnect ( ) ;
38
36
inputSoundFile . stop ( ) ;
39
37
writeFileSub . reset ( ) ;
40
38
} ) ;
41
39
42
- afterEach ( function ( ) {
40
+ afterEach ( function ( ) { } ) ;
41
+
42
+ it ( 'can be created and disposed' , function ( ) {
43
+ let recorder = new p5 . SoundRecorder ( ) ;
44
+ expect ( recorder . input ) . to . have . property ( 'context' ) ;
45
+ expect ( recorder . input ) . to . have . property ( 'gain' ) ;
46
+ expect ( recorder . output ) . to . have . property ( 'context' ) ;
47
+ expect ( recorder . output ) . to . have . property ( 'gain' ) ;
48
+ expect ( recorder . _inputChannels ) . to . equal ( 2 ) ;
49
+ expect ( recorder . _outputChannels ) . to . equal ( 2 ) ;
50
+ expect ( recorder . _workletNode ) . to . have . property ( 'context' ) ;
51
+ expect ( recorder . _workletNode ) . to . have . property ( 'parameters' ) ;
52
+
53
+ expect ( p5 . soundOut . soundArray ) . to . include ( recorder ) ;
54
+
43
55
recorder . dispose ( ) ;
56
+ expect ( p5 . soundOut . soundArray ) . to . not . include ( recorder ) ;
57
+ expect ( recorder . input ) . to . be . null ;
58
+ expect ( recorder . _workletNode ) . to . be . null ;
44
59
} ) ;
45
60
46
61
it ( 'can record input from a microphone' , function ( done ) {
62
+ let recorder = new p5 . SoundRecorder ( ) ;
47
63
// this is the shortest possible recording duration
48
64
const recordingDuration =
49
65
recorder . bufferSize / p5 . soundOut . audiocontext . sampleRate ;
@@ -65,13 +81,15 @@ describe('p5.SoundRecorder', function () {
65
81
outputSoundFile . dispose ( ) ;
66
82
mic . dispose ( ) ;
67
83
p5 . prototype . outputVolume ( 0 ) ;
84
+ recorder . dispose ( ) ;
68
85
done ( ) ;
69
86
} ) ;
70
- } , 130 ) ;
87
+ } , 500 ) ;
71
88
} ) ;
72
89
} ) ;
73
90
74
91
it ( 'can record input from a sound file' , function ( done ) {
92
+ let recorder = new p5 . SoundRecorder ( ) ;
75
93
const sampleIndex = 0 ;
76
94
// this is the shortest possible recording duration
77
95
const recordingDuration =
@@ -91,11 +109,13 @@ describe('p5.SoundRecorder', function () {
91
109
expect ( outputChannel [ sampleIndex ] ) . to . eq ( inputChannelSampleValue ) ;
92
110
93
111
outputSoundFile . dispose ( ) ;
112
+ recorder . dispose ( ) ;
94
113
done ( ) ;
95
114
} ) ;
96
115
} ) ;
97
116
98
117
it ( 'can record the main output of a sketch' , function ( done ) {
118
+ let recorder = new p5 . SoundRecorder ( ) ;
99
119
// this is the shortest possible recording duration
100
120
const recordingDuration =
101
121
recorder . bufferSize / p5 . soundOut . audiocontext . sampleRate ;
@@ -119,12 +139,14 @@ describe('p5.SoundRecorder', function () {
119
139
120
140
outputSoundFile . dispose ( ) ;
121
141
p5 . prototype . outputVolume ( 0 ) ;
142
+ recorder . dispose ( ) ;
122
143
done ( ) ;
123
144
} ) ;
124
145
} , 20 ) ;
125
146
} ) ;
126
147
127
- it ( 'can save a recorded buffer to a .wav file' , function ( done ) {
148
+ it ( 'can save a recorded buffer to a .wav file and be stopped' , function ( done ) {
149
+ let recorder = new p5 . SoundRecorder ( ) ;
128
150
// this is the shortest possible recording duration
129
151
const recordingDuration =
130
152
recorder . bufferSize / p5 . soundOut . audiocontext . sampleRate ;
@@ -139,6 +161,8 @@ describe('p5.SoundRecorder', function () {
139
161
expect ( writeFileSub . called ) . to . be . true ;
140
162
141
163
outputSoundFile . dispose ( ) ;
164
+ recorder . stop ( ) ;
165
+ recorder . dispose ( ) ;
142
166
done ( ) ;
143
167
} ) ;
144
168
} ) ;
0 commit comments