Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
133 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
bower_components/ | ||
node_modules/ | ||
temp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Omnitone Unit Tests</title> | ||
<link rel="stylesheet" href="../bower_components/mocha/mocha.css" /> | ||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
<div id="messages"></div> | ||
<div id="fixtures"></div> | ||
<script src="../bower_components/chai/chai.js"></script> | ||
<script src="../bower_components/mocha/mocha.js"></script> | ||
<script src="../build/omnitone.min.js"></script> | ||
<script src="test-setup.js"></script> | ||
<script>mocha.setup('bdd')</script> | ||
<script src="test-router.js"></script> | ||
<script>mocha.run();</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
describe('FOARouter', function () { | ||
|
||
it('Should route incoming channels according to the channel map correctly.', | ||
function (done) { | ||
var sampleRate = 48000; | ||
var renderLength = 0.1 * sampleRate; | ||
var context = new OfflineAudioContext(4, renderLength, sampleRate); | ||
|
||
var testBuffer = context.createBuffer(4, renderLength, sampleRate); | ||
for (var c = 0; c < testBuffer.numberOfChannels; c++) { | ||
var channelData = testBuffer.getChannelData(c); | ||
for (var i = 0; i < channelData.length; i++) { | ||
channelData[i] = c; | ||
} | ||
} | ||
|
||
var router = Omnitone.createFOARouter(context, [1, 2, 0, 3]); | ||
var source = context.createBufferSource(); | ||
source.buffer = testBuffer; | ||
|
||
source.connect(router.input); | ||
router.output.connect(context.destination); | ||
source.start(); | ||
|
||
// With the router configuration above, this is what must be rendered. | ||
// Channel #0: value [0] => (to channel #1) => value [2] | ||
// Channel #1: value [1] => (to channel #2) => value [0] | ||
// Channel #2: value [2] => (to channel #0) => value [1] | ||
// Channel #3: value [3] => (to channel #3) => value [3] | ||
var expectedValues = [2, 0, 1, 3]; | ||
var passed = false; | ||
context.startRendering().then(function (renderedBuffer) { | ||
for (c = 0; c < renderedBuffer.numberOfChannels; c++) { | ||
passed = isConstantValueOf( | ||
renderedBuffer.getChannelData(c), expectedValues[c]); | ||
expect(passed).to.equal(true); | ||
} | ||
done(); | ||
}); | ||
} | ||
); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
var expect = chai.expect; | ||
var should = chai.should(); | ||
|
||
|
||
/** | ||
* Check if the array is filled with the specified value only. | ||
* @param {Float32Array} channelData The target array for testing. | ||
* @param {Number} value A value for the testing. | ||
* @return {Boolean} | ||
*/ | ||
function isConstantValueOf(channelData, value) { | ||
var mismatches = {}; | ||
for (var i = 0; i < channelData.length; i++) { | ||
if (channelData[i] !== value) | ||
mismatches[i] = channelData[i]; | ||
} | ||
|
||
var numberOfmismatches = Object.keys(mismatches).length; | ||
return numberOfmismatches === 0; | ||
}; |