Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test added to p5.fft #611

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/looper.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class Score {
constructor() {
// for all of the arguments
this.parts = [];
this.currentPart = new Array(arguments.length);;
this.currentPart = new Array(arguments.length);

var thisScore = this;
for (var i in arguments) {
Expand All @@ -396,7 +396,7 @@ class Score {
this.parts[i].onended = function () {
thisScore.resetPart(i);
playNextPart(thisScore);
};
};
}
this.looping = false;
}
Expand Down
57 changes: 57 additions & 0 deletions test/tests/p5.FFT.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,61 @@ describe('p5.FFT', function () {
expect(fft.smoothing).to.equal(0.8);
expect(fft.smooth()).to.equal(0.8);
});

let soundFile, oscillator;
it('can set Oscillator as input', function (done) {
oscillator = new p5.Oscillator();
try {
fft.setInput(oscillator);
} catch (err) {
return expect.fail();
}
oscillator.start();

setTimeout(() => {
let spectrum = fft.analyze();
const someFrequencyIsNotZero = spectrum.some(
(frequency) => frequency !== 0
);
expect(someFrequencyIsNotZero).to.equal(true);
oscillator.dispose();
done();
}, 500);
});
it('can set soundFile as input', function (done) {
soundFile = p5.prototype.loadSound('./testAudio/drum.mp3', () => {
soundFile.disconnect();
try {
fft.setInput(soundFile);
} catch (err) {
return done(err);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it catches an error , right now i am unsure of why we cant set sounfile as input , any suggestions @therewasaguy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davepagurek any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I can't actually reproduce this error, it seems to just work. Maybe it was a browser bug that has since been fixed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to reproduce this error, if it works we can merge this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davepagurek it was dropping these errors for me :

image

but when I added: let fft = new p5.FFT(); it got resolved, anything else seems fine to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh does this happen when running tests headless from the other open PR? I'm running npm run test and going to http://localhost:8000/test/?grep=FFT, which is what shows no errors.

Where are you adding the new p5.FFT() line? It also has that in a beforeEach, but maybe something is up with the asynchronous tests 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I am getting that while running the test headless, I added the new line within the function, at the very beginning just like we did for oscillator = new p5.Oscillator();

}
soundFile.play();
setTimeout(() => {
let spectrum = fft.analyze();
const someFrequencyIsNotZero = spectrum.some(
(frequency) => frequency !== 0
);
expect(someFrequencyIsNotZero).to.equal(true);
soundFile.dispose();
done();
}, 500);
});
});
it('can handle any Unknown sources', function (done) {
let UnknownSource = { UnknownSource: 'this is a unknown object' };
try {
fft.setInput(UnknownSource);
} catch (err) {
return done(err);
}
setTimeout(() => {
let spectrum = fft.analyze();
const someFrequencyIsNotZero = spectrum.some(
(frequency) => frequency !== 0
);
expect(someFrequencyIsNotZero).to.equal(false);
done();
}, 500);
});
});