|
1 | 1 | const expect = chai.expect;
|
2 | 2 |
|
| 3 | +p5.prototype.soundFormats('mp3', 'ogg'); |
| 4 | +let soundFile = p5.prototype.loadSound('./testAudio/drum'); |
| 5 | + |
3 | 6 | describe('p5.Reverb', function () {
|
4 | 7 | it('can be created and disposed', function () {
|
5 | 8 | const reverb = new p5.Reverb();
|
6 |
| - reverb.dispose(); |
7 |
| - }); |
8 |
| - |
9 |
| - it('default parmams-> seconds:3, decay: 2, reverse: false', function () { |
10 |
| - const reverb = new p5.Reverb(); |
11 | 9 |
|
| 10 | + expect(reverb.input.gain.value).to.equal(0.5); |
12 | 11 | expect(reverb._seconds).to.equal(3);
|
13 | 12 | expect(reverb._decay).to.equal(2);
|
14 | 13 | expect(reverb._reverse).to.equal(false);
|
| 14 | + //effect initialization |
| 15 | + expect(reverb.input).to.have.property('gain'); |
| 16 | + expect(reverb.input).to.have.property('context'); |
| 17 | + expect(reverb.output).to.have.property('gain'); |
| 18 | + expect(reverb.output).to.have.property('context'); |
| 19 | + expect(reverb._drywet).to.have.property('fade'); |
| 20 | + expect(reverb.wet).to.have.property('gain'); |
| 21 | + expect(reverb.wet).to.have.property('context'); |
| 22 | + |
| 23 | + reverb.dispose(); |
| 24 | + expect(reverb.wet).to.equal(undefined); |
| 25 | + expect(reverb._drywet).to.equal(undefined); |
| 26 | + expect(reverb.input).to.equal(undefined); |
| 27 | + expect(reverb.output).to.equal(undefined); |
| 28 | + expect(reverb.ac).to.equal(undefined); |
15 | 29 | });
|
16 | 30 |
|
17 |
| - it('can set seconds, decayRate, reverse', function () { |
18 |
| - const reverb = new p5.Reverb(); |
19 |
| - reverb.set(5, 6, true); |
20 |
| - expect(reverb._seconds).to.equal(5); |
21 |
| - expect(reverb._decay).to.equal(6); |
22 |
| - expect(reverb._reverse).to.equal(true); |
| 31 | + it('initialization builds and sets a impulse response', function () { |
| 32 | + let reverb = new p5.Reverb(); |
| 33 | + // _buildImpulse calls _setBuffer |
| 34 | + expect(reverb.convolverNode.buffer.duration).to.equal(3); |
| 35 | + expect(reverb.convolverNode.buffer.length).to.equal(144000); |
| 36 | + expect(reverb.convolverNode.buffer.numberOfChannels).to.equal(2); |
| 37 | + expect(reverb.convolverNode.buffer.sampleRate).to.equal(48000); |
| 38 | + //_setBuffer calls _initConvolverNode |
| 39 | + expect(reverb.convolverNode).to.have.property('buffer'); |
| 40 | + expect(reverb.convolverNode).to.have.property('context'); |
| 41 | + expect(reverb.convolverNode).to.have.property('channelCountMode'); |
| 42 | + |
| 43 | + reverb.dispose(); |
| 44 | + //dispose calls _teardownConvolverNode |
| 45 | + expect(reverb).to.not.have.property('convolverNode'); |
| 46 | + }); |
| 47 | + |
| 48 | + describe('methods', function () { |
| 49 | + it('can connect a source to the reverb', function () { |
| 50 | + let reverb = new p5.Reverb(); |
| 51 | + reverb.process(soundFile); |
| 52 | + }); |
| 53 | + it('can connect a source to the reverb and process the parameters', function () { |
| 54 | + let reverb = new p5.Reverb(); |
| 55 | + reverb.process(soundFile, 7, 80, true); |
| 56 | + expect(reverb._seconds).to.equal(7); |
| 57 | + expect(reverb._decay).to.equal(80); |
| 58 | + expect(reverb._reverse).to.equal(true); |
| 59 | + }); |
| 60 | + |
| 61 | + it('can set the reverb parameters individually', function () { |
| 62 | + let reverb = new p5.Reverb(); |
| 63 | + reverb.set(4); |
| 64 | + expect(reverb._seconds).to.equal(4); |
| 65 | + reverb.set(undefined, 18); |
| 66 | + expect(reverb._decay).to.equal(18); |
| 67 | + reverb.set(undefined, undefined, true); |
| 68 | + expect(reverb._reverse).to.equal(true); |
| 69 | + }); |
| 70 | + it('can set all the reverb parameters', function () { |
| 71 | + let reverb = new p5.Reverb(); |
| 72 | + reverb.set(5, 6, true); |
| 73 | + expect(reverb._seconds).to.equal(5); |
| 74 | + expect(reverb._decay).to.equal(6); |
| 75 | + expect(reverb._reverse).to.equal(true); |
| 76 | + }); |
| 77 | + it('setting the duration rebuilds the buffer', function () { |
| 78 | + let reverb = new p5.Reverb(); |
| 79 | + reverb.set(2); |
| 80 | + expect(reverb.convolverNode.buffer.duration).to.equal(2); |
| 81 | + expect(reverb.convolverNode.buffer.length).to.equal(96000); |
| 82 | + }); |
| 83 | + it('can tear down and rebuild the convolver', function () { |
| 84 | + let reverb = new p5.Reverb(); |
| 85 | + reverb._teardownConvolverNode(); |
| 86 | + expect(reverb).to.not.have.property('convolverNode'); |
| 87 | + reverb._initConvolverNode(); |
| 88 | + expect(reverb).to.have.property('convolverNode'); |
| 89 | + }); |
| 90 | + it('can build an impulse', function () { |
| 91 | + let reverb = new p5.Reverb(); |
| 92 | + let buffer = reverb.convolverNode.buffer.getChannelData(0); |
| 93 | + reverb._buildImpulse(); |
| 94 | + expect(reverb.convolverNode.buffer.getChannelData(0)).to.not.deep.equal( |
| 95 | + buffer |
| 96 | + ); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
| 100 | + |
| 101 | +describe('p5.Convolver', function () { |
| 102 | + it('can be created and disposed', function () { |
| 103 | + const cVerb = new p5.Convolver(); |
| 104 | + |
| 105 | + expect(cVerb.input.gain.value).to.equal(0.5); //from reverb |
| 106 | + expect(cVerb._seconds).to.equal(3); |
| 107 | + expect(cVerb._decay).to.equal(2); |
| 108 | + expect(cVerb._reverse).to.equal(false); |
| 109 | + expect(cVerb.convolverNode.buffer.duration).to.equal(3); |
| 110 | + expect(cVerb.convolverNode.buffer.length).to.equal(144000); |
| 111 | + expect(cVerb.convolverNode.buffer.numberOfChannels).to.equal(2); |
| 112 | + expect(cVerb.convolverNode.buffer.sampleRate).to.equal(48000); |
| 113 | + expect(cVerb.convolverNode).to.have.property('context'); |
| 114 | + |
| 115 | + expect(cVerb.impulses).to.be.an('array').to.have.length(0); |
| 116 | + expect(cVerb.set).to.be.null; |
| 117 | + |
| 118 | + cVerb.dispose(); |
| 119 | + expect(cVerb.ac).to.equal(undefined); |
| 120 | + expect(cVerb).to.not.have.property('convolverNode'); |
| 121 | + }); |
| 122 | + |
| 123 | + it('can be created with a given path', function () { |
| 124 | + try { |
| 125 | + const cVerb = new p5.Convolver( |
| 126 | + './testAudio/bx-spring', |
| 127 | + () => { |
| 128 | + expect(cVerb.convolverNode.buffer.duration).to.be.approximately( |
| 129 | + 7.765, |
| 130 | + 0.001 |
| 131 | + ); //file length |
| 132 | + expect(cVerb.convolverNode.buffer.length).to.equal(372736); |
| 133 | + expect(cVerb.convolverNode.buffer.numberOfChannels).to.equal(2); |
| 134 | + expect(cVerb.convolverNode.buffer.sampleRate).to.equal(48000); |
| 135 | + expect(cVerb.impulses.length).to.equal(1); |
| 136 | + expect(cVerb.impulses[0]).to.have.property('audioBuffer'); |
| 137 | + expect(cVerb.impulses[0]).to.have.property('name'); |
| 138 | + }, |
| 139 | + () => {} |
| 140 | + ); |
| 141 | + } catch (error) { |
| 142 | + console.log(error); |
| 143 | + } |
| 144 | + }); |
| 145 | + |
| 146 | + describe('methods', function () { |
| 147 | + it('load buffer can throw', function (done) { |
| 148 | + try { |
| 149 | + new p5.Convolver( |
| 150 | + 'http://badURL.mp3', |
| 151 | + () => {}, |
| 152 | + () => { |
| 153 | + done(); |
| 154 | + } |
| 155 | + ); |
| 156 | + } catch (error) { |
| 157 | + console.log(error); |
| 158 | + } |
| 159 | + }); |
| 160 | + it('can connect a source to the convolver', function () { |
| 161 | + const cVerb = new p5.Convolver(); |
| 162 | + cVerb.process(soundFile); |
| 163 | + }); |
| 164 | + it('can add an impulse', function (done) { |
| 165 | + try { |
| 166 | + const cVerb = new p5.Convolver( |
| 167 | + './testAudio/bx-spring', |
| 168 | + () => { |
| 169 | + cVerb.addImpulse('./testAudio/drum', () => { |
| 170 | + expect(cVerb.convolverNode.buffer.duration).to.equal(1); //file length |
| 171 | + expect(cVerb.convolverNode.buffer.length).to.equal(48000); |
| 172 | + expect(cVerb.impulses.length).to.equal(2); |
| 173 | + expect(cVerb.impulses[1].name).to.include('drum'); |
| 174 | + |
| 175 | + cVerb.dispose(); // dispose removes all impulses |
| 176 | + expect(cVerb.impulses.length).to.equal(2); |
| 177 | + expect(cVerb.impulses[0]).to.be.null; |
| 178 | + expect(cVerb.impulses[1]).to.be.null; |
| 179 | + done(); |
| 180 | + }); |
| 181 | + }, |
| 182 | + () => {} |
| 183 | + ); |
| 184 | + } catch (error) { |
| 185 | + console.log(error); |
| 186 | + } |
| 187 | + }); |
| 188 | + it('can reset impulse', function (done) { |
| 189 | + try { |
| 190 | + const cVerb = new p5.Convolver( |
| 191 | + './testAudio/bx-spring', |
| 192 | + () => { |
| 193 | + cVerb.resetImpulse('./testAudio/drum', () => { |
| 194 | + expect(cVerb.convolverNode.buffer.duration).to.equal(1); //file length |
| 195 | + expect(cVerb.convolverNode.buffer.length).to.equal(48000); |
| 196 | + expect(cVerb.impulses.length).to.equal(1); |
| 197 | + expect(cVerb.impulses[0].name).to.include('drum'); |
| 198 | + done(); |
| 199 | + }); |
| 200 | + }, |
| 201 | + () => {} |
| 202 | + ); |
| 203 | + } catch (error) { |
| 204 | + console.log(error); |
| 205 | + } |
| 206 | + }); |
| 207 | + it('can toggle impulses', function (done) { |
| 208 | + try { |
| 209 | + const cVerb = new p5.Convolver( |
| 210 | + './testAudio/bx-spring', |
| 211 | + () => { |
| 212 | + cVerb.addImpulse('./testAudio/drum', () => { |
| 213 | + expect(cVerb.convolverNode.buffer.duration).to.equal(1); // initially drum |
| 214 | + //toggle using id/position in impulses array |
| 215 | + cVerb.toggleImpulse(0); |
| 216 | + expect(cVerb.convolverNode.buffer.duration).to.be.approximately( |
| 217 | + 7.765, |
| 218 | + 0.001 |
| 219 | + ); // bx-spring |
| 220 | + |
| 221 | + //using filename |
| 222 | + cVerb.toggleImpulse('drum.mp3'); |
| 223 | + cVerb.toggleImpulse('drum.ogg'); |
| 224 | + expect(cVerb.convolverNode.buffer.duration).to.equal(1); // toggled back to drum |
| 225 | + done(); |
| 226 | + }); |
| 227 | + }, |
| 228 | + () => {} |
| 229 | + ); |
| 230 | + } catch (error) { |
| 231 | + console.log(error); |
| 232 | + } |
| 233 | + }); |
23 | 234 | });
|
24 | 235 |
|
25 |
| - it('drywet value can be changed', function () { |
26 |
| - const effect = new p5.Effect(); |
| 236 | + it('can be created using createConvolver', function (done) { |
| 237 | + const cVerb = p5.prototype.createConvolver(); |
| 238 | + expect(cVerb.impulses).to.be.an('array').to.have.length(0); |
| 239 | + expect(cVerb.set).to.be.null; |
27 | 240 |
|
28 |
| - expect(effect.drywet(0.5)).to.equal(0.5); |
| 241 | + try { |
| 242 | + let cVerb = p5.prototype.createConvolver( |
| 243 | + './testAudio/bx-spring', |
| 244 | + () => { |
| 245 | + expect(cVerb.convolverNode.buffer.duration).to.be.approximately( |
| 246 | + 7.765, |
| 247 | + 0.001 |
| 248 | + ); //file length |
| 249 | + expect(cVerb.convolverNode.buffer.length).to.equal(372736); |
| 250 | + expect(cVerb.impulses.length).to.equal(1); |
| 251 | + done(); |
| 252 | + }, |
| 253 | + () => {} |
| 254 | + ); |
| 255 | + } catch (error) { |
| 256 | + console.log(error); |
| 257 | + } |
29 | 258 | });
|
30 | 259 | });
|
0 commit comments