2015-08-17 02:21:14 +00:00
|
|
|
define(["Test", "Tone/core/Buffer"], function (Test, Buffer) {
|
2016-03-04 21:25:44 +00:00
|
|
|
|
|
|
|
if (window.__karma__){
|
|
|
|
Buffer.baseUrl = "/base/test/";
|
|
|
|
}
|
2015-08-17 02:21:14 +00:00
|
|
|
|
2016-03-05 05:07:17 +00:00
|
|
|
var testFile = "./audio/sine.wav";
|
|
|
|
|
2015-08-17 02:21:14 +00:00
|
|
|
describe("Buffer", function(){
|
|
|
|
it ("can be created and disposed", function(){
|
2016-03-05 05:07:17 +00:00
|
|
|
var buff = new Buffer(testFile);
|
2015-08-17 02:21:14 +00:00
|
|
|
buff.dispose();
|
|
|
|
Test.wasDisposed(buff);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("loads a file from a url string", function(done){
|
2016-03-05 05:07:17 +00:00
|
|
|
var buffer = new Buffer(testFile, function(buff){
|
2015-08-17 02:21:14 +00:00
|
|
|
expect(buff).to.be.instanceof(Buffer);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("has a duration", function(done){
|
2016-03-05 05:07:17 +00:00
|
|
|
var buffer = new Buffer(testFile, function(){
|
|
|
|
expect(buffer.duration).to.be.closeTo(3, 0.01);
|
2015-08-17 02:21:14 +00:00
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-11-11 17:33:11 +00:00
|
|
|
it("the static on('load') method is invoked", function(done){
|
2016-03-05 05:07:17 +00:00
|
|
|
var buffer = new Buffer(testFile);
|
2015-11-11 17:33:11 +00:00
|
|
|
Buffer.on("load", function(){
|
2015-08-17 02:21:14 +00:00
|
|
|
buffer.dispose();
|
2015-11-11 17:33:11 +00:00
|
|
|
Buffer.off("load");
|
2015-08-17 02:21:14 +00:00
|
|
|
done();
|
2015-11-11 17:33:11 +00:00
|
|
|
});
|
2015-08-17 02:21:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("can be constructed with an options object", function(done){
|
|
|
|
var buffer = new Buffer({
|
2016-03-05 05:07:17 +00:00
|
|
|
"url" : testFile,
|
2015-08-17 02:21:14 +00:00
|
|
|
"reverse" : true,
|
|
|
|
"onload" : function(){
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("takes an AudioBuffer in the constructor method", function(done){
|
|
|
|
var buffer = new Buffer({
|
2016-03-05 05:07:17 +00:00
|
|
|
"url" : testFile,
|
2015-08-17 02:21:14 +00:00
|
|
|
"onload" : function(){
|
|
|
|
var testOne = new Buffer(buffer.get());
|
|
|
|
expect(testOne.get()).to.equal(buffer.get());
|
|
|
|
testOne.dispose();
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-10-21 17:52:03 +00:00
|
|
|
it("takes a Tone.Buffer in the constructor method", function(done){
|
|
|
|
var buffer = new Buffer({
|
2016-03-05 05:07:17 +00:00
|
|
|
"url" : testFile,
|
2015-10-21 17:52:03 +00:00
|
|
|
"onload" : function(){
|
|
|
|
var testOne = new Buffer(buffer);
|
|
|
|
expect(testOne.get()).to.equal(buffer.get());
|
|
|
|
testOne.dispose();
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-08-17 02:21:14 +00:00
|
|
|
it("takes Tone.Buffer in the set method", function(done){
|
|
|
|
var buffer = new Buffer({
|
2016-03-05 05:07:17 +00:00
|
|
|
"url" : testFile,
|
2015-08-17 02:21:14 +00:00
|
|
|
"onload" : function(){
|
2016-03-05 05:07:17 +00:00
|
|
|
var testOne = new Buffer(testFile);
|
2015-08-17 02:21:14 +00:00
|
|
|
testOne.set(buffer);
|
|
|
|
expect(testOne.get()).to.equal(buffer.get());
|
|
|
|
testOne.dispose();
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("takes AudioBuffer in the set method", function(done){
|
|
|
|
var buffer = new Buffer({
|
2016-03-05 05:07:17 +00:00
|
|
|
"url" : testFile,
|
2015-08-17 02:21:14 +00:00
|
|
|
"onload" : function(){
|
2016-03-05 05:07:17 +00:00
|
|
|
var testOne = new Buffer(testFile);
|
2015-08-17 02:21:14 +00:00
|
|
|
testOne.set(buffer.get());
|
|
|
|
expect(testOne.get()).to.equal(buffer.get());
|
|
|
|
testOne.dispose();
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-11-11 17:33:11 +00:00
|
|
|
it("the static on('progress') method is invoked", function(done){
|
2016-03-05 05:07:17 +00:00
|
|
|
var buffer = new Buffer(testFile);
|
2015-11-11 17:33:11 +00:00
|
|
|
Buffer.on("progress", function(percent){
|
|
|
|
expect(percent).to.be.a.number;
|
|
|
|
Buffer.off("progress");
|
2015-08-17 02:21:14 +00:00
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can reverse a buffer", function(done){
|
2016-03-05 05:07:17 +00:00
|
|
|
var buffer = new Buffer(testFile, function(){
|
2015-08-17 02:21:14 +00:00
|
|
|
var buffArray = buffer.get();
|
|
|
|
var lastSample = buffArray[buffArray.length - 1];
|
|
|
|
buffer.reverse = true;
|
|
|
|
expect(buffer.get()[0]).to.equal(lastSample);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|