mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
testing to/from Array methods
This commit is contained in:
parent
2569bfef8b
commit
1270727098
1 changed files with 69 additions and 0 deletions
|
@ -29,6 +29,22 @@ define(["Test", "Tone/core/Buffer"], function (Test, Buffer) {
|
|||
});
|
||||
});
|
||||
|
||||
it("can get the number of channels", function(done){
|
||||
var buffer = new Buffer(testFile, function(){
|
||||
expect(buffer.numberOfChannels).to.be.equal(1);
|
||||
buffer.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("can get the length of the buffer", function(done){
|
||||
var buffer = new Buffer(testFile, function(){
|
||||
expect(buffer.length).to.be.equal(132301);
|
||||
buffer.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("the static on('load') method is invoked", function(done){
|
||||
var buffer = new Buffer(testFile);
|
||||
Buffer.on("load", function(){
|
||||
|
@ -123,5 +139,58 @@ define(["Test", "Tone/core/Buffer"], function (Test, Buffer) {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("can convert from an array", function(){
|
||||
var buffer = new Buffer();
|
||||
var arr = new Float32Array(0.5 * buffer.context.sampleRate);
|
||||
arr[0] = 0.5;
|
||||
buffer.fromArray(arr);
|
||||
expect(buffer.duration).to.equal(0.5);
|
||||
expect(buffer.numberOfChannels).to.equal(1);
|
||||
//test the first sample of the first channel to see if it's the same
|
||||
expect(buffer.get().getChannelData(0)[0]).to.equal(0.5);
|
||||
buffer.dispose();
|
||||
});
|
||||
|
||||
it("can convert from a multidimentional array", function(){
|
||||
var buffer = new Buffer();
|
||||
var arr = [new Float32Array(0.5 * buffer.context.sampleRate), new Float32Array(0.5 * buffer.context.sampleRate)];
|
||||
arr[0][0] = 0.5;
|
||||
buffer.fromArray(arr);
|
||||
expect(buffer.duration).to.equal(0.5);
|
||||
expect(buffer.numberOfChannels).to.equal(2);
|
||||
expect(buffer.get().getChannelData(0)[0]).to.equal(0.5);
|
||||
buffer.dispose();
|
||||
});
|
||||
|
||||
it("can convert to and from an array", function(){
|
||||
var buffer = new Buffer();
|
||||
var arr = [new Float32Array(0.5 * buffer.context.sampleRate), new Float32Array(0.5 * buffer.context.sampleRate)];
|
||||
arr[0][0] = 0.5;
|
||||
buffer.fromArray(arr);
|
||||
expect(buffer.get().getChannelData(0)[0]).to.equal(0.5);
|
||||
expect(buffer.toArray()[0][0]).to.equal(0.5);
|
||||
//with a selected channel
|
||||
expect(buffer.toArray(0)[0]).to.equal(0.5);
|
||||
buffer.dispose();
|
||||
});
|
||||
|
||||
it("can slice a portion of the array", function(done){
|
||||
var buffer = new Buffer(testFile, function(){
|
||||
//original duration
|
||||
expect(buffer.duration).to.be.closeTo(3, 0.01);
|
||||
var sliced1 = buffer.slice(0, 1);
|
||||
//does not modify the original
|
||||
expect(buffer.duration).to.be.closeTo(3, 0.01);
|
||||
expect(sliced1.duration).to.be.closeTo(1, 0.01);
|
||||
var sliced2 = sliced1.slice(0.5);
|
||||
expect(sliced2.duration).to.be.closeTo(0.5, 0.01);
|
||||
|
||||
buffer.dispose();
|
||||
sliced1.dispose();
|
||||
sliced2.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue