| @@ 6-83 (lines=78) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | var assert = require('assert'); |
|
| 7 | ||
| 8 | describe('read 32bit IEEE from disk and write to new file', function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "32bitIEEE-16kHz-bext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | let wav2 = new wavefile.WaveFile(wav.toBytes()); |
|
| 17 | fs.writeFileSync(path + "/out/32bitIEEE-16kHz-bext-mono.wav", wav2.toBytes()); |
|
| 18 | ||
| 19 | it("toBytes should return a array of bytes", |
|
| 20 | function() { |
|
| 21 | assert.ok(wav.toBytes()); |
|
| 22 | }); |
|
| 23 | it("chunkId should be 'RIFF'", |
|
| 24 | function() { |
|
| 25 | assert.equal(wav2.chunkId, "RIFF"); |
|
| 26 | }); |
|
| 27 | it("subChunk1Id should be 'fmt '", |
|
| 28 | function() { |
|
| 29 | assert.equal(wav2.subChunk1Id, "fmt "); |
|
| 30 | }); |
|
| 31 | it("format should be 'WAVE'", |
|
| 32 | function() { |
|
| 33 | assert.equal(wav2.format, "WAVE"); |
|
| 34 | }); |
|
| 35 | it("subChunk1Size should be 16", |
|
| 36 | function() { |
|
| 37 | assert.equal(wav2.subChunk1Size, 16); |
|
| 38 | }); |
|
| 39 | it("audioFormat should be 3 (IEEE)", |
|
| 40 | function() { |
|
| 41 | assert.equal(wav2.audioFormat, 3); |
|
| 42 | }); |
|
| 43 | it("numChannels should be 1", |
|
| 44 | function() { |
|
| 45 | assert.equal(wav2.numChannels, 1); |
|
| 46 | }); |
|
| 47 | it("sampleRate should be 16000", |
|
| 48 | function() { |
|
| 49 | assert.equal(wav2.sampleRate, 16000); |
|
| 50 | }); |
|
| 51 | it("byteRate should be 64000", |
|
| 52 | function() { |
|
| 53 | assert.equal(wav2.byteRate, 64000); |
|
| 54 | }); |
|
| 55 | it("blockAlign should be 4", |
|
| 56 | function() { |
|
| 57 | assert.equal(wav2.blockAlign, 4); |
|
| 58 | }); |
|
| 59 | it("bitsPerSample should be 32", |
|
| 60 | function() { |
|
| 61 | assert.equal(wav2.bitsPerSample, 32); |
|
| 62 | }); |
|
| 63 | it("subChunk2Id should be 'data'", |
|
| 64 | function() { |
|
| 65 | assert.equal(wav2.subChunk2Id, 'data'); |
|
| 66 | }); |
|
| 67 | it("subChunk2Size should be > 0", |
|
| 68 | function() { |
|
| 69 | assert.ok(wav2.subChunk2Size > 0); |
|
| 70 | }); |
|
| 71 | it("samples.length should be > 0", |
|
| 72 | function() { |
|
| 73 | assert.ok(wav2.samples_.length > 0); |
|
| 74 | }); |
|
| 75 | it("samples_ on the new file should have the same length as in the original file", |
|
| 76 | function() { |
|
| 77 | assert.equal(wav2.samples_.length, wav.samples_.length); |
|
| 78 | }); |
|
| 79 | it("samples_ on the new file should be same as the original file", |
|
| 80 | function() { |
|
| 81 | assert.deepEqual(wav2.samples_, wav.samples_); |
|
| 82 | }); |
|
| 83 | }); |
|
| 84 | ||
| @@ 6-79 (lines=74) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | var assert = require('assert'); |
|
| 7 | ||
| 8 | describe('read 32bit PCM from disk and write to new file', function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "32bit-48kHz-noBext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | let wav2 = new wavefile.WaveFile(wav.toBytes()); |
|
| 17 | fs.writeFileSync(path + "/out/32bit-48kHz-noBext-mono.wav", wav2.toBytes()); |
|
| 18 | ||
| 19 | it("chunkId should be 'RIFF'", |
|
| 20 | function() { |
|
| 21 | assert.equal(wav2.chunkId, "RIFF"); |
|
| 22 | }); |
|
| 23 | it("subChunk1Id should be 'fmt '", |
|
| 24 | function() { |
|
| 25 | assert.equal(wav2.subChunk1Id, "fmt "); |
|
| 26 | }); |
|
| 27 | it("format should be 'WAVE'", |
|
| 28 | function() { |
|
| 29 | assert.equal(wav2.format, "WAVE"); |
|
| 30 | }); |
|
| 31 | it("subChunk1Size should be 16", |
|
| 32 | function() { |
|
| 33 | assert.equal(wav2.subChunk1Size, 16); |
|
| 34 | }); |
|
| 35 | it("audioFormat should be 1 (PCM)", |
|
| 36 | function() { |
|
| 37 | assert.equal(wav2.audioFormat, 1); |
|
| 38 | }); |
|
| 39 | it("numChannels should be 1", |
|
| 40 | function() { |
|
| 41 | assert.equal(wav2.numChannels, 1); |
|
| 42 | }); |
|
| 43 | it("sampleRate should be 48000", |
|
| 44 | function() { |
|
| 45 | assert.equal(wav2.sampleRate, 48000); |
|
| 46 | }); |
|
| 47 | it("byteRate should be 192000", |
|
| 48 | function() { |
|
| 49 | assert.equal(wav2.byteRate, 192000); |
|
| 50 | }); |
|
| 51 | it("blockAlign should be 4", |
|
| 52 | function() { |
|
| 53 | assert.equal(wav2.blockAlign, 4); |
|
| 54 | }); |
|
| 55 | it("bitsPerSample should be 32", |
|
| 56 | function() { |
|
| 57 | assert.equal(wav2.bitsPerSample, 32); |
|
| 58 | }); |
|
| 59 | it("subChunk2Id should be 'data'", |
|
| 60 | function() { |
|
| 61 | assert.equal(wav2.subChunk2Id, 'data'); |
|
| 62 | }); |
|
| 63 | it("subChunk2Size should be > 0", |
|
| 64 | function() { |
|
| 65 | assert.ok(wav2.subChunk2Size > 0); |
|
| 66 | }); |
|
| 67 | it("samples.length should be > 0", |
|
| 68 | function() { |
|
| 69 | assert.ok(wav2.samples_.length > 0); |
|
| 70 | }); |
|
| 71 | it("samples_ on the new file should have the same length as in the original file", |
|
| 72 | function() { |
|
| 73 | assert.equal(wav2.samples_.length, wav.samples_.length); |
|
| 74 | }); |
|
| 75 | it("samples_ on the new file should be same as the original file", |
|
| 76 | function() { |
|
| 77 | assert.deepEqual(wav2.samples_, wav.samples_); |
|
| 78 | }); |
|
| 79 | }); |
|
| 80 | ||
| @@ 6-79 (lines=74) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | var assert = require('assert'); |
|
| 7 | ||
| 8 | describe('read 64-bit file from disk and write to new file', function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "64bit-48kHz-noBext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | let wav2 = new wavefile.WaveFile(wav.toBytes()); |
|
| 17 | fs.writeFileSync(path + "/out/64bit-48kHz-noBext-mono.wav", wav2.toBytes()); |
|
| 18 | ||
| 19 | it("chunkId should be 'RIFF'", |
|
| 20 | function() { |
|
| 21 | assert.equal(wav2.chunkId, "RIFF"); |
|
| 22 | }); |
|
| 23 | it("subChunk1Id should be 'fmt '", |
|
| 24 | function() { |
|
| 25 | assert.equal(wav2.subChunk1Id, "fmt "); |
|
| 26 | }); |
|
| 27 | it("format should be 'WAVE'", |
|
| 28 | function() { |
|
| 29 | assert.equal(wav2.format, "WAVE"); |
|
| 30 | }); |
|
| 31 | it("subChunk1Size should be 16", |
|
| 32 | function() { |
|
| 33 | assert.equal(wav2.subChunk1Size, 16); |
|
| 34 | }); |
|
| 35 | it("audioFormat should be 3 (IEEE)", |
|
| 36 | function() { |
|
| 37 | assert.equal(wav2.audioFormat, 3); |
|
| 38 | }); |
|
| 39 | it("numChannels should be 1", |
|
| 40 | function() { |
|
| 41 | assert.equal(wav2.numChannels, 1); |
|
| 42 | }); |
|
| 43 | it("sampleRate should be 48000", |
|
| 44 | function() { |
|
| 45 | assert.equal(wav2.sampleRate, 48000); |
|
| 46 | }); |
|
| 47 | it("byteRate should be 384000", |
|
| 48 | function() { |
|
| 49 | assert.equal(wav2.byteRate, 384000); |
|
| 50 | }); |
|
| 51 | it("blockAlign should be 8", |
|
| 52 | function() { |
|
| 53 | assert.equal(wav2.blockAlign, 8); |
|
| 54 | }); |
|
| 55 | it("bitsPerSample should be 64", |
|
| 56 | function() { |
|
| 57 | assert.equal(wav2.bitsPerSample, 64); |
|
| 58 | }); |
|
| 59 | it("subChunk2Id should be 'data'", |
|
| 60 | function() { |
|
| 61 | assert.equal(wav2.subChunk2Id, 'data'); |
|
| 62 | }); |
|
| 63 | it("subChunk2Size should be > 0", |
|
| 64 | function() { |
|
| 65 | assert.ok(wav2.subChunk2Size > 0); |
|
| 66 | }); |
|
| 67 | it("samples.length should be > 0", |
|
| 68 | function() { |
|
| 69 | assert.ok(wav2.samples_.length > 0); |
|
| 70 | }); |
|
| 71 | it("samples_ on the new file should have the same length as in the original file ", |
|
| 72 | function() { |
|
| 73 | assert.equal(wav2.samples_.length, wav.samples_.length); |
|
| 74 | }); |
|
| 75 | it("samples_ on the new file should be same as the original file ", |
|
| 76 | function() { |
|
| 77 | assert.deepEqual(wav2.samples_, wav.samples_); |
|
| 78 | }); |
|
| 79 | }); |
|
| 80 | ||
| @@ 6-79 (lines=74) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | var assert = require('assert'); |
|
| 7 | ||
| 8 | describe('read 24bit file from disk and write to new file', function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "24bit-16kHz-bext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | let wav2 = new wavefile.WaveFile(wav.toBytes()); |
|
| 17 | fs.writeFileSync(path + "/out/24bit-16kHz-bext-mono.wav", wav2.toBytes()); |
|
| 18 | ||
| 19 | it("chunkId should be 'RIFF'", |
|
| 20 | function() { |
|
| 21 | assert.equal(wav2.chunkId, "RIFF"); |
|
| 22 | }); |
|
| 23 | it("subChunk1Id should be 'fmt '", |
|
| 24 | function() { |
|
| 25 | assert.equal(wav2.subChunk1Id, "fmt "); |
|
| 26 | }); |
|
| 27 | it("format should be 'WAVE'", |
|
| 28 | function() { |
|
| 29 | assert.equal(wav2.format, "WAVE"); |
|
| 30 | }); |
|
| 31 | it("subChunk1Size should be 16", |
|
| 32 | function() { |
|
| 33 | assert.equal(wav2.subChunk1Size, 16); |
|
| 34 | }); |
|
| 35 | it("audioFormat should be 1 (PCM)", |
|
| 36 | function() { |
|
| 37 | assert.equal(wav2.audioFormat, 1); |
|
| 38 | }); |
|
| 39 | it("numChannels should be 1", |
|
| 40 | function() { |
|
| 41 | assert.equal(wav2.numChannels, 1); |
|
| 42 | }); |
|
| 43 | it("sampleRate should be 16000", |
|
| 44 | function() { |
|
| 45 | assert.equal(wav2.sampleRate, 16000); |
|
| 46 | }); |
|
| 47 | it("byteRate should be 48000", |
|
| 48 | function() { |
|
| 49 | assert.equal(wav2.byteRate, 48000); |
|
| 50 | }); |
|
| 51 | it("blockAlign should be 3", |
|
| 52 | function() { |
|
| 53 | assert.equal(wav2.blockAlign, 3); |
|
| 54 | }); |
|
| 55 | it("bitsPerSample should be 24", |
|
| 56 | function() { |
|
| 57 | assert.equal(wav2.bitsPerSample, 24); |
|
| 58 | }); |
|
| 59 | it("subChunk2Id should be 'data'", |
|
| 60 | function() { |
|
| 61 | assert.equal(wav2.subChunk2Id, 'data'); |
|
| 62 | }); |
|
| 63 | it("subChunk2Size should be > 0", |
|
| 64 | function() { |
|
| 65 | assert.ok(wav2.subChunk2Size > 0); |
|
| 66 | }); |
|
| 67 | it("samples.length should be > 0", |
|
| 68 | function() { |
|
| 69 | assert.ok(wav2.samples_.length > 0); |
|
| 70 | }); |
|
| 71 | it("samples_ on the new file should have the same length as in the original file", |
|
| 72 | function() { |
|
| 73 | assert.equal(wav2.samples_.length, wav.samples_.length); |
|
| 74 | }); |
|
| 75 | it("samples_ on the new file should be same as the original file", |
|
| 76 | function() { |
|
| 77 | assert.deepEqual(wav2.samples_, wav.samples_); |
|
| 78 | }); |
|
| 79 | }); |
|
| 80 | ||
| @@ 6-79 (lines=74) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | var assert = require('assert'); |
|
| 7 | ||
| 8 | describe('read 8-bit file from disk and write to new file', function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "8bit-16kHz-bext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | let wav2 = new wavefile.WaveFile(wav.toBytes()); |
|
| 17 | fs.writeFileSync(path + "/out/8bit-16kHz-bext-mono.wav", wav2.toBytes()); |
|
| 18 | ||
| 19 | it("chunkId should be 'RIFF'", |
|
| 20 | function() { |
|
| 21 | assert.equal(wav2.chunkId, "RIFF"); |
|
| 22 | }); |
|
| 23 | it("subChunk1Id should be 'fmt '", |
|
| 24 | function() { |
|
| 25 | assert.equal(wav2.subChunk1Id, "fmt "); |
|
| 26 | }); |
|
| 27 | it("format in should be 'WAVE'", |
|
| 28 | function() { |
|
| 29 | assert.equal(wav2.format, "WAVE"); |
|
| 30 | }); |
|
| 31 | it("subChunk1Size should be 16", |
|
| 32 | function() { |
|
| 33 | assert.equal(wav2.subChunk1Size, 16); |
|
| 34 | }); |
|
| 35 | it("audioFormat should be 1 (PCM)", |
|
| 36 | function() { |
|
| 37 | assert.equal(wav2.audioFormat, 1); |
|
| 38 | }); |
|
| 39 | it("numChannels should be 1", |
|
| 40 | function() { |
|
| 41 | assert.equal(wav2.numChannels, 1); |
|
| 42 | }); |
|
| 43 | it("sampleRate should be 16000", |
|
| 44 | function() { |
|
| 45 | assert.equal(wav2.sampleRate, 16000); |
|
| 46 | }); |
|
| 47 | it("byteRate should be 16000", |
|
| 48 | function() { |
|
| 49 | assert.equal(wav2.byteRate, 16000); |
|
| 50 | }); |
|
| 51 | it("blockAlign should be 1", |
|
| 52 | function() { |
|
| 53 | assert.equal(wav2.blockAlign, 1); |
|
| 54 | }); |
|
| 55 | it("bitsPerSample should be 8", |
|
| 56 | function() { |
|
| 57 | assert.equal(wav2.bitsPerSample, 8); |
|
| 58 | }); |
|
| 59 | it("subChunk2Id should be 'data'", |
|
| 60 | function() { |
|
| 61 | assert.equal(wav2.subChunk2Id, 'data'); |
|
| 62 | }); |
|
| 63 | it("subChunk2Size should be > 0", |
|
| 64 | function() { |
|
| 65 | assert.ok(wav2.subChunk2Size > 0); |
|
| 66 | }); |
|
| 67 | it("samples.length should be > 0", |
|
| 68 | function() { |
|
| 69 | assert.ok(wav2.samples_.length > 0); |
|
| 70 | }); |
|
| 71 | it("samples_ on the new file should have the same length as in the original file ", |
|
| 72 | function() { |
|
| 73 | assert.equal(wav2.samples_.length, wav.samples_.length); |
|
| 74 | }); |
|
| 75 | it("samples_ on the new file should be same as the original file ", |
|
| 76 | function() { |
|
| 77 | assert.deepEqual(wav2.samples_, wav.samples_); |
|
| 78 | }); |
|
| 79 | }); |
|
| 80 | ||
| @@ 6-89 (lines=84) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | var assert = require('assert'); |
|
| 7 | ||
| 8 | describe('read 16bit file from disk and write to new file', function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "16-bit-8kHz-noBext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(); |
|
| 16 | ||
| 17 | wav.fromBytes(wBytes); |
|
| 18 | ||
| 19 | let wav2 = new wavefile.WaveFile(); |
|
| 20 | ||
| 21 | let bytes3 = wav.toBytes(); |
|
| 22 | ||
| 23 | wav2.fromBytes(bytes3); |
|
| 24 | ||
| 25 | let bytes4 = wav2.toBytes(); |
|
| 26 | ||
| 27 | fs.writeFileSync(path + "/out/16-bit-8kHz-noBext-mono.wav", bytes4); |
|
| 28 | ||
| 29 | it("chunkId should be 'RIFF'", |
|
| 30 | function() { |
|
| 31 | assert.equal(wav2.chunkId, "RIFF"); |
|
| 32 | }); |
|
| 33 | it("subChunk1Id should be 'fmt '", |
|
| 34 | function() { |
|
| 35 | assert.equal(wav2.subChunk1Id, "fmt "); |
|
| 36 | }); |
|
| 37 | it("format should be 'WAVE'", |
|
| 38 | function() { |
|
| 39 | assert.equal(wav2.format, "WAVE"); |
|
| 40 | }); |
|
| 41 | it("subChunk1Size should be 16", |
|
| 42 | function() { |
|
| 43 | assert.equal(wav2.subChunk1Size, 16); |
|
| 44 | }); |
|
| 45 | it("audioFormat should be 1 (PCM)", |
|
| 46 | function() { |
|
| 47 | assert.equal(wav2.audioFormat, 1); |
|
| 48 | }); |
|
| 49 | it("numChannels should be 1", |
|
| 50 | function() { |
|
| 51 | assert.equal(wav2.numChannels, 1); |
|
| 52 | }); |
|
| 53 | it("sampleRate should be 8000", |
|
| 54 | function() { |
|
| 55 | assert.equal(wav2.sampleRate, 8000); |
|
| 56 | }); |
|
| 57 | it("byteRate should be 16000", |
|
| 58 | function() { |
|
| 59 | assert.equal(wav2.byteRate, 16000); |
|
| 60 | }); |
|
| 61 | it("blockAlign should be 2", |
|
| 62 | function() { |
|
| 63 | assert.equal(wav2.blockAlign, 2); |
|
| 64 | }); |
|
| 65 | it("bitsPerSample should be 16", |
|
| 66 | function() { |
|
| 67 | assert.equal(wav2.bitsPerSample, 16); |
|
| 68 | }); |
|
| 69 | it("subChunk2Id should be 'data'", |
|
| 70 | function() { |
|
| 71 | assert.equal(wav2.subChunk2Id, 'data'); |
|
| 72 | }); |
|
| 73 | it("subChunk2Size should be > 0", |
|
| 74 | function() { |
|
| 75 | assert.ok(wav2.subChunk2Size > 0); |
|
| 76 | }); |
|
| 77 | it("samples.length should be > 0", |
|
| 78 | function() { |
|
| 79 | assert.ok(wav2.samples_.length > 0); |
|
| 80 | }); |
|
| 81 | it("samples_ on the new file should have the same length as in the original file", |
|
| 82 | function() { |
|
| 83 | assert.equal(wav2.samples_.length, wav.samples_.length); |
|
| 84 | }); |
|
| 85 | it("samples_ on the new file should be same as the original file", |
|
| 86 | function() { |
|
| 87 | assert.deepEqual(wav2.samples_, wav.samples_); |
|
| 88 | }); |
|
| 89 | }); |
|
| 90 | ||
| @@ 6-87 (lines=82) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | var assert = require('assert'); |
|
| 7 | ||
| 8 | describe('read 4-bit file from disk and write to new file', function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "4bit-imaadpcm-8kHz-noBext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | let wav2 = new wavefile.WaveFile(wav.toBytes()); |
|
| 17 | fs.writeFileSync(path + "/out/4bit-imaadpcm-8kHz-noBext-mono.wav", wav2.toBytes()); |
|
| 18 | ||
| 19 | it("chunkId should be 'RIFF'", |
|
| 20 | function() { |
|
| 21 | assert.equal(wav2.chunkId, "RIFF"); |
|
| 22 | }); |
|
| 23 | it("subChunk1Id should be 'fmt '", |
|
| 24 | function() { |
|
| 25 | assert.equal(wav2.subChunk1Id, "fmt "); |
|
| 26 | }); |
|
| 27 | it("format should be 'WAVE'", |
|
| 28 | function() { |
|
| 29 | assert.equal(wav2.format, "WAVE"); |
|
| 30 | }); |
|
| 31 | it("subChunk1Size should be 20", |
|
| 32 | function() { |
|
| 33 | assert.equal(wav2.subChunk1Size, 20); |
|
| 34 | }); |
|
| 35 | it("audioFormat should be 17 (IMA ADPCM)", |
|
| 36 | function() { |
|
| 37 | assert.equal(wav2.audioFormat, 17); |
|
| 38 | }); |
|
| 39 | it("numChannels should be 1", |
|
| 40 | function() { |
|
| 41 | assert.equal(wav2.numChannels, 1); |
|
| 42 | }); |
|
| 43 | it("sampleRate should be 8000", |
|
| 44 | function() { |
|
| 45 | assert.equal(wav2.sampleRate, 8000); |
|
| 46 | }); |
|
| 47 | it("byteRate should be 4055", |
|
| 48 | function() { |
|
| 49 | assert.equal(wav2.byteRate, 4055); |
|
| 50 | }); |
|
| 51 | it("blockAlign should be 256", |
|
| 52 | function() { |
|
| 53 | assert.equal(wav2.blockAlign, 256); |
|
| 54 | }); |
|
| 55 | it("bitsPerSample should be 4", |
|
| 56 | function() { |
|
| 57 | assert.equal(wav2.bitsPerSample, 4); |
|
| 58 | }); |
|
| 59 | it("factChunkId should be 'fact'", |
|
| 60 | function() { |
|
| 61 | assert.equal(wav2.factChunkId, 'fact'); |
|
| 62 | }); |
|
| 63 | it("factChunkSize should be 4", |
|
| 64 | function() { |
|
| 65 | assert.equal(wav2.factChunkSize, 4); |
|
| 66 | }); |
|
| 67 | it("subChunk2Id should be 'data'", |
|
| 68 | function() { |
|
| 69 | assert.equal(wav2.subChunk2Id, 'data'); |
|
| 70 | }); |
|
| 71 | it("subChunk2Size should be > 0", |
|
| 72 | function() { |
|
| 73 | assert.ok(wav2.subChunk2Size > 0); |
|
| 74 | }); |
|
| 75 | it("samples.length should be > 0", |
|
| 76 | function() { |
|
| 77 | assert.ok(wav2.samples_.length > 0); |
|
| 78 | }); |
|
| 79 | it("samples_ on the new file should have the same length as in the original file", |
|
| 80 | function() { |
|
| 81 | assert.equal(wav2.samples_.length, wav.samples_.length); |
|
| 82 | }); |
|
| 83 | it("samples_ on the new file should be same as the original file", |
|
| 84 | function() { |
|
| 85 | assert.deepEqual(wav2.samples_, wav.samples_); |
|
| 86 | }); |
|
| 87 | }); |
|
| 88 | ||
| @@ 6-87 (lines=82) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | var assert = require('assert'); |
|
| 7 | ||
| 8 | describe('read 4-bit file from disk and write to new file (different APDCM source)', function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "4-bit-imaadpcm-8kHz-noBext-mono-reaper.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | let wav2 = new wavefile.WaveFile(wav.toBytes()); |
|
| 17 | fs.writeFileSync(path + "/out/4-bit-imaadpcm-8kHz-noBext-mono-reaper.wav", wav2.toBytes()); |
|
| 18 | ||
| 19 | it("chunkId should be 'RIFF'", |
|
| 20 | function() { |
|
| 21 | assert.equal(wav2.chunkId, "RIFF"); |
|
| 22 | }); |
|
| 23 | it("subChunk1Id should be 'fmt '", |
|
| 24 | function() { |
|
| 25 | assert.equal(wav2.subChunk1Id, "fmt "); |
|
| 26 | }); |
|
| 27 | it("format should be 'WAVE'", |
|
| 28 | function() { |
|
| 29 | assert.equal(wav2.format, "WAVE"); |
|
| 30 | }); |
|
| 31 | it("subChunk1Size should be 20", |
|
| 32 | function() { |
|
| 33 | assert.equal(wav2.subChunk1Size, 20); |
|
| 34 | }); |
|
| 35 | it("audioFormat should be 17 (IMA ADPCM)", |
|
| 36 | function() { |
|
| 37 | assert.equal(wav2.audioFormat, 17); |
|
| 38 | }); |
|
| 39 | it("numChannels should be 1", |
|
| 40 | function() { |
|
| 41 | assert.equal(wav2.numChannels, 1); |
|
| 42 | }); |
|
| 43 | it("sampleRate should be 8000", |
|
| 44 | function() { |
|
| 45 | assert.equal(wav2.sampleRate, 8000); |
|
| 46 | }); |
|
| 47 | it("byteRate should be 4000", |
|
| 48 | function() { |
|
| 49 | assert.equal(wav2.byteRate, 4000); |
|
| 50 | }); |
|
| 51 | it("blockAlign should be 1024", |
|
| 52 | function() { |
|
| 53 | assert.equal(wav2.blockAlign, 1024); |
|
| 54 | }); |
|
| 55 | it("bitsPerSample should be 4", |
|
| 56 | function() { |
|
| 57 | assert.equal(wav2.bitsPerSample, 4); |
|
| 58 | }); |
|
| 59 | it("factChunkId should be 'fact'", |
|
| 60 | function() { |
|
| 61 | assert.equal(wav2.factChunkId, 'fact'); |
|
| 62 | }); |
|
| 63 | it("factChunkSize should be 4", |
|
| 64 | function() { |
|
| 65 | assert.equal(wav2.factChunkSize, 4); |
|
| 66 | }); |
|
| 67 | it("subChunk2Id should be 'data'", |
|
| 68 | function() { |
|
| 69 | assert.equal(wav2.subChunk2Id, 'data'); |
|
| 70 | }); |
|
| 71 | it("subChunk2Size should be > 0", |
|
| 72 | function() { |
|
| 73 | assert.ok(wav2.subChunk2Size > 0); |
|
| 74 | }); |
|
| 75 | it("samples.length should be > 0", |
|
| 76 | function() { |
|
| 77 | assert.ok(wav2.samples_.length > 0); |
|
| 78 | }); |
|
| 79 | it("samples_ on the new file should have the same length as in the original file", |
|
| 80 | function() { |
|
| 81 | assert.equal(wav2.samples_.length, wav.samples_.length); |
|
| 82 | }); |
|
| 83 | it("samples_ on the new file should be same as the original file", |
|
| 84 | function() { |
|
| 85 | assert.deepEqual(wav2.samples_, wav.samples_); |
|
| 86 | }); |
|
| 87 | }); |
|
| 88 | ||
| @@ 7-70 (lines=64) @@ | ||
| 4 | * |
|
| 5 | */ |
|
| 6 | ||
| 7 | let assert = require("assert"); |
|
| 8 | ||
| 9 | describe("4-bit IMA ADPCM reading", function() { |
|
| 10 | ||
| 11 | let fs = require("fs"); |
|
| 12 | let wavefile = require("../index.js"); |
|
| 13 | let path = "test/files/"; |
|
| 14 | ||
| 15 | let wBytes = fs.readFileSync(path + '4bit-imaadpcm-8kHz-noBext-mono.wav'); |
|
| 16 | let wav = new wavefile.WaveFile(wBytes); |
|
| 17 | ||
| 18 | it("chunkId should be 'RIFF'", |
|
| 19 | function() { |
|
| 20 | assert.equal(wav.chunkId, "RIFF"); |
|
| 21 | }); |
|
| 22 | it("subChunk1Id should be 'fmt '", |
|
| 23 | function() { |
|
| 24 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 25 | }); |
|
| 26 | it("format should be 'WAVE'", |
|
| 27 | function() { |
|
| 28 | assert.equal(wav.format, "WAVE"); |
|
| 29 | }); |
|
| 30 | it("subChunk1Size should be 20", |
|
| 31 | function() { |
|
| 32 | assert.equal(wav.subChunk1Size, 20); |
|
| 33 | }); |
|
| 34 | it("audioFormat should be 17 (IMA ADPCM)", |
|
| 35 | function() { |
|
| 36 | assert.equal(wav.audioFormat, 17); |
|
| 37 | }); |
|
| 38 | it("numChannels should be 1", |
|
| 39 | function() { |
|
| 40 | assert.equal(wav.numChannels, 1); |
|
| 41 | }); |
|
| 42 | it("sampleRate should be 8000", |
|
| 43 | function() { |
|
| 44 | assert.equal(wav.sampleRate, 8000); |
|
| 45 | }); |
|
| 46 | it("bitsPerSample should be 4", |
|
| 47 | function() { |
|
| 48 | assert.equal(wav.bitsPerSample, 4); |
|
| 49 | }); |
|
| 50 | it("factChunkId should be 'fact'", |
|
| 51 | function() { |
|
| 52 | assert.equal(wav.factChunkId, 'fact'); |
|
| 53 | }); |
|
| 54 | it("factChunkSize should be 4", |
|
| 55 | function() { |
|
| 56 | assert.equal(wav.factChunkSize, 4); |
|
| 57 | }); |
|
| 58 | it("subChunk2Id should be 'data'", |
|
| 59 | function() { |
|
| 60 | assert.equal(wav.subChunk2Id, 'data'); |
|
| 61 | }); |
|
| 62 | it("subChunk2Size should be > 0", |
|
| 63 | function() { |
|
| 64 | assert.ok(wav.subChunk2Size > 0); |
|
| 65 | }); |
|
| 66 | it("samples.length should be > 0", |
|
| 67 | function() { |
|
| 68 | assert.ok(wav.samples_.length > 0); |
|
| 69 | }); |
|
| 70 | }); |
|
| 71 | ||
| @@ 6-69 (lines=64) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | let assert = require("assert"); |
|
| 7 | ||
| 8 | describe("32-bit IEEE (with bwf) reading", function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "32bitIEEE-16kHz-bext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | ||
| 17 | it("chunkId should be 'RIFF'", |
|
| 18 | function() { |
|
| 19 | assert.equal(wav.chunkId, "RIFF"); |
|
| 20 | }); |
|
| 21 | it("subChunk1Id should be 'fmt '", |
|
| 22 | function() { |
|
| 23 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 24 | }); |
|
| 25 | it("format should be 'WAVE'", |
|
| 26 | function() { |
|
| 27 | assert.equal(wav.format, "WAVE"); |
|
| 28 | }); |
|
| 29 | it("subChunk1Size should be 16", |
|
| 30 | function() { |
|
| 31 | assert.equal(wav.subChunk1Size, 16); |
|
| 32 | }); |
|
| 33 | it("audioFormat should be 3 (IEEE)", |
|
| 34 | function() { |
|
| 35 | assert.equal(wav.audioFormat, 3); |
|
| 36 | }); |
|
| 37 | it("numChannels should be 1", |
|
| 38 | function() { |
|
| 39 | assert.equal(wav.numChannels, 1); |
|
| 40 | }); |
|
| 41 | it("sampleRate should be 16000", |
|
| 42 | function() { |
|
| 43 | assert.equal(wav.sampleRate, 16000); |
|
| 44 | }); |
|
| 45 | it("byteRate should be 64000", |
|
| 46 | function() { |
|
| 47 | assert.equal(wav.byteRate, 64000); |
|
| 48 | }); |
|
| 49 | it("blockAlign should be 4", |
|
| 50 | function() { |
|
| 51 | assert.equal(wav.blockAlign, 4); |
|
| 52 | }); |
|
| 53 | it("bitsPerSample should be 32", |
|
| 54 | function() { |
|
| 55 | assert.equal(wav.bitsPerSample, 32); |
|
| 56 | }); |
|
| 57 | it("subChunk2Id be 'data'", |
|
| 58 | function() { |
|
| 59 | assert.equal(wav.subChunk2Id, 'data'); |
|
| 60 | }); |
|
| 61 | it("subChunk2Size should be > 0", |
|
| 62 | function() { |
|
| 63 | assert.ok(wav.subChunk2Size > 0); |
|
| 64 | }); |
|
| 65 | it("samples.length should be > 0", |
|
| 66 | function() { |
|
| 67 | assert.ok(wav.samples_.length > 0); |
|
| 68 | }); |
|
| 69 | }); |
|
| 70 | ||
| @@ 6-69 (lines=64) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | let assert = require("assert"); |
|
| 7 | ||
| 8 | describe("64-bit reading", function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "64bit-48kHz-noBext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | ||
| 17 | it("chunkId should be 'RIFF'", |
|
| 18 | function() { |
|
| 19 | assert.equal(wav.chunkId, "RIFF"); |
|
| 20 | }); |
|
| 21 | it("subChunk1Id should be 'fmt '", |
|
| 22 | function() { |
|
| 23 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 24 | }); |
|
| 25 | it("format should be 'WAVE'", |
|
| 26 | function() { |
|
| 27 | assert.equal(wav.format, "WAVE"); |
|
| 28 | }); |
|
| 29 | it("subChunk1Size should be 16", |
|
| 30 | function() { |
|
| 31 | assert.equal(wav.subChunk1Size, 16); |
|
| 32 | }); |
|
| 33 | it("audioFormat should be 3 (IEEE)", |
|
| 34 | function() { |
|
| 35 | assert.equal(wav.audioFormat, 3); |
|
| 36 | }); |
|
| 37 | it("numChannels should be 1", |
|
| 38 | function() { |
|
| 39 | assert.equal(wav.numChannels, 1); |
|
| 40 | }); |
|
| 41 | it("sampleRate should be 48000", |
|
| 42 | function() { |
|
| 43 | assert.equal(wav.sampleRate, 48000); |
|
| 44 | }); |
|
| 45 | it("byteRate should be 384000", |
|
| 46 | function() { |
|
| 47 | assert.equal(wav.byteRate, 384000); |
|
| 48 | }); |
|
| 49 | it("blockAlign should be 8", |
|
| 50 | function() { |
|
| 51 | assert.equal(wav.blockAlign, 8); |
|
| 52 | }); |
|
| 53 | it("bitsPerSample should be 64", |
|
| 54 | function() { |
|
| 55 | assert.equal(wav.bitsPerSample, 64); |
|
| 56 | }); |
|
| 57 | it("subChunk2Id should be 'data'", |
|
| 58 | function() { |
|
| 59 | assert.equal(wav.subChunk2Id, 'data'); |
|
| 60 | }); |
|
| 61 | it("subChunk2Size should be > 0", |
|
| 62 | function() { |
|
| 63 | assert.ok(wav.subChunk2Size > 0); |
|
| 64 | }); |
|
| 65 | it("samples.length should be > 0", |
|
| 66 | function() { |
|
| 67 | assert.ok(wav.samples_.length > 0); |
|
| 68 | }); |
|
| 69 | }); |
|
| 70 | ||
| @@ 6-69 (lines=64) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | let assert = require("assert"); |
|
| 7 | ||
| 8 | describe("8-bit file (with bwf) reading", function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "8bit-16kHz-bext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | ||
| 17 | it("chunkId should be 'RIFF'", |
|
| 18 | function() { |
|
| 19 | assert.equal(wav.chunkId, "RIFF"); |
|
| 20 | }); |
|
| 21 | it("subChunk1Id should be 'fmt '", |
|
| 22 | function() { |
|
| 23 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 24 | }); |
|
| 25 | it("format should be 'WAVE'", |
|
| 26 | function() { |
|
| 27 | assert.equal(wav.format, "WAVE"); |
|
| 28 | }); |
|
| 29 | it("subChunk1Size should be 16", |
|
| 30 | function() { |
|
| 31 | assert.equal(wav.subChunk1Size, 16); |
|
| 32 | }); |
|
| 33 | it("audioFormat should be 1 (PCM)", |
|
| 34 | function() { |
|
| 35 | assert.equal(wav.audioFormat, 1); |
|
| 36 | }); |
|
| 37 | it("numChannels should be 1", |
|
| 38 | function() { |
|
| 39 | assert.equal(wav.numChannels, 1); |
|
| 40 | }); |
|
| 41 | it("sampleRate should be 16000", |
|
| 42 | function() { |
|
| 43 | assert.equal(wav.sampleRate, 16000); |
|
| 44 | }); |
|
| 45 | it("byteRate should be 16000", |
|
| 46 | function() { |
|
| 47 | assert.equal(wav.byteRate, 16000); |
|
| 48 | }); |
|
| 49 | it("blockAlign should be 1", |
|
| 50 | function() { |
|
| 51 | assert.equal(wav.blockAlign, 1); |
|
| 52 | }); |
|
| 53 | it("bitsPerSample should be 8", |
|
| 54 | function() { |
|
| 55 | assert.equal(wav.bitsPerSample, 8); |
|
| 56 | }); |
|
| 57 | it("subChunk2Id should be 'data'", |
|
| 58 | function() { |
|
| 59 | assert.equal(wav.subChunk2Id, 'data'); |
|
| 60 | }); |
|
| 61 | it("subChunk2Size should be > 0", |
|
| 62 | function() { |
|
| 63 | assert.ok(wav.subChunk2Size > 0); |
|
| 64 | }); |
|
| 65 | it("samples.length should be > 0", |
|
| 66 | function() { |
|
| 67 | assert.ok(wav.samples_.length > 0); |
|
| 68 | }); |
|
| 69 | }); |
|
| 70 | ||
| @@ 6-69 (lines=64) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | let assert = require("assert"); |
|
| 7 | ||
| 8 | describe("24-bit (with bwf) reading", function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "24bit-16kHz-bext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | ||
| 17 | it("chunkId should be 'RIFF'", |
|
| 18 | function() { |
|
| 19 | assert.equal(wav.chunkId, "RIFF"); |
|
| 20 | }); |
|
| 21 | it("subChunk1Id should be 'fmt '", |
|
| 22 | function() { |
|
| 23 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 24 | }); |
|
| 25 | it("format should be 'WAVE'", |
|
| 26 | function() { |
|
| 27 | assert.equal(wav.format, "WAVE"); |
|
| 28 | }); |
|
| 29 | it("subChunk1Size should be 16", |
|
| 30 | function() { |
|
| 31 | assert.equal(wav.subChunk1Size, 16); |
|
| 32 | }); |
|
| 33 | it("audioFormat should be 1 (PCM)", |
|
| 34 | function() { |
|
| 35 | assert.equal(wav.audioFormat, 1); |
|
| 36 | }); |
|
| 37 | it("numChannels should be 1", |
|
| 38 | function() { |
|
| 39 | assert.equal(wav.numChannels, 1); |
|
| 40 | }); |
|
| 41 | it("sampleRate should be 16000", |
|
| 42 | function() { |
|
| 43 | assert.equal(wav.sampleRate, 16000); |
|
| 44 | }); |
|
| 45 | it("byteRate should be 48000", |
|
| 46 | function() { |
|
| 47 | assert.equal(wav.byteRate, 48000); |
|
| 48 | }); |
|
| 49 | it("blockAlign should be 3", |
|
| 50 | function() { |
|
| 51 | assert.equal(wav.blockAlign, 3); |
|
| 52 | }); |
|
| 53 | it("bitsPerSample should be 24", |
|
| 54 | function() { |
|
| 55 | assert.equal(wav.bitsPerSample, 24); |
|
| 56 | }); |
|
| 57 | it("subChunk2Id should be 'data'", |
|
| 58 | function() { |
|
| 59 | assert.equal(wav.subChunk2Id, 'data'); |
|
| 60 | }); |
|
| 61 | it("subChunk2Size should be > 0", |
|
| 62 | function() { |
|
| 63 | assert.ok(wav.subChunk2Size > 0); |
|
| 64 | }); |
|
| 65 | it("samples.length should be > 0", |
|
| 66 | function() { |
|
| 67 | assert.ok(wav.samples_.length > 0); |
|
| 68 | }); |
|
| 69 | }); |
|
| 70 | ||
| @@ 6-69 (lines=64) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | let assert = require("assert"); |
|
| 7 | ||
| 8 | describe("32-bit PCM reading", function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "32bit-48kHz-noBext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | ||
| 17 | it("chunkId should be 'RIFF'", |
|
| 18 | function() { |
|
| 19 | assert.equal(wav.chunkId, "RIFF"); |
|
| 20 | }); |
|
| 21 | it("subChunk1Id should be 'fmt '", |
|
| 22 | function() { |
|
| 23 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 24 | }); |
|
| 25 | it("format should be 'WAVE'", |
|
| 26 | function() { |
|
| 27 | assert.equal(wav.format, "WAVE"); |
|
| 28 | }); |
|
| 29 | it("subChunk1Size should be 16", |
|
| 30 | function() { |
|
| 31 | assert.equal(wav.subChunk1Size, 16); |
|
| 32 | }); |
|
| 33 | it("audioFormat should be 1 (PCM)", |
|
| 34 | function() { |
|
| 35 | assert.equal(wav.audioFormat, 1); |
|
| 36 | }); |
|
| 37 | it("numChannels should be 1", |
|
| 38 | function() { |
|
| 39 | assert.equal(wav.numChannels, 1); |
|
| 40 | }); |
|
| 41 | it("sampleRate should be 48000", |
|
| 42 | function() { |
|
| 43 | assert.equal(wav.sampleRate, 48000); |
|
| 44 | }); |
|
| 45 | it("byteRate should be 192000", |
|
| 46 | function() { |
|
| 47 | assert.equal(wav.byteRate, 192000); |
|
| 48 | }); |
|
| 49 | it("blockAlign should be 4", |
|
| 50 | function() { |
|
| 51 | assert.equal(wav.blockAlign, 4); |
|
| 52 | }); |
|
| 53 | it("bitsPerSample should be 32", |
|
| 54 | function() { |
|
| 55 | assert.equal(wav.bitsPerSample, 32); |
|
| 56 | }); |
|
| 57 | it("subChunk2Id should be 'data'", |
|
| 58 | function() { |
|
| 59 | assert.equal(wav.subChunk2Id, 'data'); |
|
| 60 | }); |
|
| 61 | it("subChunk2Size should be > 0", |
|
| 62 | function() { |
|
| 63 | assert.ok(wav.subChunk2Size > 0); |
|
| 64 | }); |
|
| 65 | it("samples.length should be > 0", |
|
| 66 | function() { |
|
| 67 | assert.ok(wav.samples_.length > 0); |
|
| 68 | }); |
|
| 69 | }); |
|
| 70 | ||
| @@ 6-69 (lines=64) @@ | ||
| 3 | * |
|
| 4 | */ |
|
| 5 | ||
| 6 | let assert = require("assert"); |
|
| 7 | ||
| 8 | describe("16-bit reading", function() { |
|
| 9 | ||
| 10 | let fs = require("fs"); |
|
| 11 | let wavefile = require("../index.js"); |
|
| 12 | let path = "test/files/"; |
|
| 13 | ||
| 14 | let wBytes = fs.readFileSync(path + "16-bit-8kHz-noBext-mono.wav"); |
|
| 15 | let wav = new wavefile.WaveFile(wBytes); |
|
| 16 | ||
| 17 | it("chunkId should be 'RIFF'", |
|
| 18 | function() { |
|
| 19 | assert.equal(wav.chunkId, "RIFF"); |
|
| 20 | }); |
|
| 21 | it("subChunk1Id should be 'fmt '", |
|
| 22 | function() { |
|
| 23 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 24 | }); |
|
| 25 | it("format should be 'WAVE'", |
|
| 26 | function() { |
|
| 27 | assert.equal(wav.format, "WAVE"); |
|
| 28 | }); |
|
| 29 | it("subChunk1Size should be 16", |
|
| 30 | function() { |
|
| 31 | assert.equal(wav.subChunk1Size, 16); |
|
| 32 | }); |
|
| 33 | it("audioFormat should be 1 (PCM)", |
|
| 34 | function() { |
|
| 35 | assert.equal(wav.audioFormat, 1); |
|
| 36 | }); |
|
| 37 | it("numChannels should be 1", |
|
| 38 | function() { |
|
| 39 | assert.equal(wav.numChannels, 1); |
|
| 40 | }); |
|
| 41 | it("sampleRate should be 8000", |
|
| 42 | function() { |
|
| 43 | assert.equal(wav.sampleRate, 8000); |
|
| 44 | }); |
|
| 45 | it("byteRate be 16000", |
|
| 46 | function() { |
|
| 47 | assert.equal(wav.byteRate, 16000); |
|
| 48 | }); |
|
| 49 | it("blockAlign should be 2", |
|
| 50 | function() { |
|
| 51 | assert.equal(wav.blockAlign, 2); |
|
| 52 | }); |
|
| 53 | it("bitsPerSample should be 16", |
|
| 54 | function() { |
|
| 55 | assert.equal(wav.bitsPerSample, 16); |
|
| 56 | }); |
|
| 57 | it("subChunk2Id should be 'data'", |
|
| 58 | function() { |
|
| 59 | assert.equal(wav.subChunk2Id, 'data'); |
|
| 60 | }); |
|
| 61 | it("subChunk2Size should be > 0", |
|
| 62 | function() { |
|
| 63 | assert.ok(wav.subChunk2Size > 0); |
|
| 64 | }); |
|
| 65 | it("samples.length should be > 0", |
|
| 66 | function() { |
|
| 67 | assert.ok(wav.samples_.length > 0); |
|
| 68 | }); |
|
| 69 | }); |
|
| 70 | ||
| @@ 10-531 (lines=522) @@ | ||
| 7 | * |
|
| 8 | */ |
|
| 9 | ||
| 10 | var assert = require('assert'); |
|
| 11 | ||
| 12 | describe('create 32-bit IEEE wave file from scratch', function() { |
|
| 13 | ||
| 14 | let wavefile = require('../../index.js'); |
|
| 15 | let wav = new wavefile.WaveFile(); |
|
| 16 | wav.fromScratch(1, 44100, '32f', [0, 0.04029441, -0.04029440, 1]); |
|
| 17 | ||
| 18 | let fs = require('fs'); |
|
| 19 | fs.writeFileSync("./test/files/out/32-bitIEEE-441kHz-mono-fromScratch.wav", wav.toBytes()); |
|
| 20 | ||
| 21 | it('chunkId should be "RIFF"', function() { |
|
| 22 | assert.equal(wav.chunkId, "RIFF"); |
|
| 23 | }); |
|
| 24 | ||
| 25 | it('format should be "WAVE"', function() { |
|
| 26 | assert.equal(wav.format, "WAVE"); |
|
| 27 | }); |
|
| 28 | ||
| 29 | it('subChunk1Id should be "fmt "', function() { |
|
| 30 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 31 | }); |
|
| 32 | ||
| 33 | it('subChunk1Size should be 16', function() { |
|
| 34 | assert.equal(wav.subChunk1Size, 16); |
|
| 35 | }); |
|
| 36 | ||
| 37 | it('audioFormat should be 3', function() { |
|
| 38 | assert.equal(wav.audioFormat, 3); |
|
| 39 | }); |
|
| 40 | ||
| 41 | it('numChannels should be 1', function() { |
|
| 42 | assert.equal(wav.numChannels, 1); |
|
| 43 | }); |
|
| 44 | ||
| 45 | it('sampleRate should be 44100', function() { |
|
| 46 | assert.equal(wav.sampleRate, 44100); |
|
| 47 | }); |
|
| 48 | ||
| 49 | it('byteRate should be 176400', function() { |
|
| 50 | assert.equal(wav.byteRate, 176400); |
|
| 51 | }); |
|
| 52 | ||
| 53 | it('blockAlign should be 4', function() { |
|
| 54 | assert.equal(wav.blockAlign, 4); |
|
| 55 | }); |
|
| 56 | ||
| 57 | it('bitsPerSample should be 32', function() { |
|
| 58 | assert.equal(wav.bitsPerSample, 32); |
|
| 59 | }); |
|
| 60 | ||
| 61 | it('subChunk2Id should be "data"', function() { |
|
| 62 | assert.equal(wav.subChunk2Id, "data"); |
|
| 63 | }); |
|
| 64 | ||
| 65 | it('subChunk2Size should be 16', function() { |
|
| 66 | assert.equal(wav.subChunk2Size, 16); |
|
| 67 | }); |
|
| 68 | ||
| 69 | it('samples_ should be the same as the args', function() { |
|
| 70 | assert.deepEqual(wav.samples_, [0, 0.04029441, -0.04029440, 1]); |
|
| 71 | }); |
|
| 72 | ||
| 73 | it('bitDepth_ should be "24"', function() { |
|
| 74 | assert.equal(wav.bitDepth_, "32f"); |
|
| 75 | }); |
|
| 76 | ||
| 77 | /* |
|
| 78 | it('should return a 8-bit wave file with an odd number of samples', |
|
| 79 | function() { |
|
| 80 | let wav = rw64.writeWavBytes(1, 48000, '8', [0, 255, 2]); |
|
| 81 | let wavRead = rw64.readWavBytes(wav); |
|
| 82 | ||
| 83 | assert.equal(wavRead.audioFormat, 1); |
|
| 84 | assert.equal(wavRead.numChannels, 1); |
|
| 85 | assert.equal(wavRead.blockAlign, 1); |
|
| 86 | assert.equal(wavRead.sampleRate, 48000); |
|
| 87 | assert.equal(wavRead.bitsPerSample, 8); |
|
| 88 | assert.deepEqual(wavRead.samples, [0, 255, 2]); |
|
| 89 | }); |
|
| 90 | ||
| 91 | it('should return a 16-bit wave file', function() { |
|
| 92 | let wav = rw64.writeWavBytes(1, 48000, '16', |
|
| 93 | [0, 1, -32768, 32767]); |
|
| 94 | let wavRead = rw64.readWavBytes(wav); |
|
| 95 | ||
| 96 | assert.equal(wavRead.audioFormat, 1); |
|
| 97 | assert.equal(wavRead.numChannels, 1); |
|
| 98 | assert.equal(wavRead.blockAlign, 2); |
|
| 99 | assert.equal(wavRead.sampleRate, 48000); |
|
| 100 | assert.equal(wavRead.bitsPerSample, 16); |
|
| 101 | assert.deepEqual(wavRead.samples, [0, 1, -32768, 32767]); |
|
| 102 | }); |
|
| 103 | ||
| 104 | it('should return a 16-bit wave file with a odd number of samples', |
|
| 105 | function() { |
|
| 106 | let wav = rw64.writeWavBytes(1, 48000, '16', |
|
| 107 | [0, 1, -32768, 32767, 4]); |
|
| 108 | let wavRead = rw64.readWavBytes(wav); |
|
| 109 | ||
| 110 | assert.equal(wavRead.audioFormat, 1); |
|
| 111 | assert.equal(wavRead.numChannels, 1); |
|
| 112 | assert.equal(wavRead.blockAlign, 2); |
|
| 113 | assert.equal(wavRead.sampleRate, 48000); |
|
| 114 | assert.equal(wavRead.bitsPerSample, 16); |
|
| 115 | assert.deepEqual(wavRead.samples, [0, 1, -32768, 32767, 4]); |
|
| 116 | }); |
|
| 117 | ||
| 118 | it('should return a 24-bit wave file', function() { |
|
| 119 | let wav = rw64.writeWavBytes(1, 48000, '24', |
|
| 120 | [0, 1, -8388608, 8388607]); |
|
| 121 | let wavRead = rw64.readWavBytes(wav); |
|
| 122 | ||
| 123 | assert.equal(wavRead.audioFormat, 1); |
|
| 124 | assert.equal(wavRead.numChannels, 1); |
|
| 125 | assert.equal(wavRead.blockAlign, 3); |
|
| 126 | assert.equal(wavRead.sampleRate, 48000); |
|
| 127 | assert.equal(wavRead.bitsPerSample, 24); |
|
| 128 | assert.equal(wavRead.subChunk2Size, 12); // 4 x 3 |
|
| 129 | assert.deepEqual(wavRead.samples, [0, 1, -8388608, 8388607]); |
|
| 130 | }); |
|
| 131 | ||
| 132 | it('should return a 24-bit wave file with a odd number of samples', |
|
| 133 | function() { |
|
| 134 | let wav = rw64.writeWavBytes(1, 48000, '24', |
|
| 135 | [0, 1, -8388608, 8388607, 4]); |
|
| 136 | let wavRead = rw64.readWavBytes(wav); |
|
| 137 | ||
| 138 | assert.equal(wavRead.audioFormat, 1); |
|
| 139 | assert.equal(wavRead.numChannels, 1); |
|
| 140 | assert.equal(wavRead.sampleRate, 48000); |
|
| 141 | assert.equal(wavRead.bitsPerSample, 24); |
|
| 142 | assert.equal(wavRead.blockAlign, 3); |
|
| 143 | assert.equal(wavRead.subChunk2Size, 15); // 5 x 3 |
|
| 144 | assert.deepEqual(wavRead.samples, [0, 1, -8388608, 8388607, 4]); |
|
| 145 | }); |
|
| 146 | ||
| 147 | it('should return a 32-bit PCM wave file', function() { |
|
| 148 | let wav = rw64.writeWavBytes(1, 44100, '32', |
|
| 149 | [0, -2147483648, 2147483647, 4]); |
|
| 150 | let wavRead = rw64.readWavBytes(wav); |
|
| 151 | ||
| 152 | assert.equal(wavRead.audioFormat, 1); |
|
| 153 | assert.equal(wavRead.numChannels, 1); |
|
| 154 | assert.equal(wavRead.sampleRate, 44100); |
|
| 155 | assert.equal(wavRead.bitsPerSample, 32); |
|
| 156 | assert.equal(wavRead.blockAlign, 4); |
|
| 157 | assert.deepEqual(wavRead.samples, [0, -2147483648, 2147483647, 4]); |
|
| 158 | }); |
|
| 159 | ||
| 160 | it('should return a 32-bit PCM wave file with a odd number of samples', |
|
| 161 | function() { |
|
| 162 | let wav = rw64.writeWavBytes(1, 44100, '32', |
|
| 163 | [0, -2147483648, 45, 0, 1]); |
|
| 164 | let wavRead = rw64.readWavBytes(wav); |
|
| 165 | ||
| 166 | assert.equal(wavRead.audioFormat, 1); |
|
| 167 | assert.equal(wavRead.numChannels, 1); |
|
| 168 | assert.equal(wavRead.sampleRate, 44100); |
|
| 169 | assert.equal(wavRead.bitsPerSample, 32); |
|
| 170 | assert.equal(wavRead.blockAlign, 4); |
|
| 171 | assert.deepEqual(wavRead.samples, [0, -2147483648, 45, 0, 1]); |
|
| 172 | }); |
|
| 173 | ||
| 174 | it('should return a 32-bit IEEE wave file', function() { |
|
| 175 | let wav = rw64.writeWavBytes(1, 48000, '32f', |
|
| 176 | [0, 0.04029441, -0.04029440, 1, -1, 0]); |
|
| 177 | let wavRead = rw64.readWavBytes(wav); |
|
| 178 | ||
| 179 | assert.equal(wavRead.audioFormat, 3); |
|
| 180 | assert.equal(wavRead.numChannels, 1); |
|
| 181 | assert.equal(wavRead.sampleRate, 48000); |
|
| 182 | assert.equal(wavRead.blockAlign, 4); |
|
| 183 | assert.equal(wavRead.bitsPerSample, 32); |
|
| 184 | for (let i=0; i<wavRead.samples.length; i++) { |
|
| 185 | wavRead.samples[i] = Number((wavRead.samples[i]).toFixed(8)); |
|
| 186 | } |
|
| 187 | assert.deepEqual(wavRead.samples, |
|
| 188 | [0, 0.04029441, -0.04029440, 1, -1, 0]); |
|
| 189 | }); |
|
| 190 | ||
| 191 | it('should return a 32-bit IEEE wave file ' + |
|
| 192 | 'with a odd number of samples', |
|
| 193 | function() { |
|
| 194 | let wav = rw64.writeWavBytes(1, 48000, '32f', |
|
| 195 | [0, 0.04029441, -0.04029440, 1, -1, 0, 1]); |
|
| 196 | let wavRead = rw64.readWavBytes(wav); |
|
| 197 | ||
| 198 | assert.equal(wavRead.audioFormat, 3); |
|
| 199 | assert.equal(wavRead.numChannels, 1); |
|
| 200 | assert.equal(wavRead.sampleRate, 48000); |
|
| 201 | assert.equal(wavRead.blockAlign, 4); |
|
| 202 | assert.equal(wavRead.bitsPerSample, 32); |
|
| 203 | for (let i=0; i<wavRead.samples.length; i++) { |
|
| 204 | wavRead.samples[i] = Number((wavRead.samples[i]).toFixed(8)); |
|
| 205 | } |
|
| 206 | assert.deepEqual(wavRead.samples, |
|
| 207 | [0, 0.04029441, -0.04029440, 1, -1, 0, 1]); |
|
| 208 | }); |
|
| 209 | ||
| 210 | it('should return a wave file with 64-bit audio', function() { |
|
| 211 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 212 | [0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
|
| 213 | let wavRead = rw64.readWavBytes(wav); |
|
| 214 | ||
| 215 | assert.equal(wavRead.audioFormat, 3); |
|
| 216 | assert.equal(wavRead.numChannels, 1); |
|
| 217 | assert.equal(wavRead.sampleRate, 48000); |
|
| 218 | assert.equal(wavRead.blockAlign, 8); |
|
| 219 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 220 | assert.deepEqual(wavRead.samples, |
|
| 221 | [0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
|
| 222 | }); |
|
| 223 | ||
| 224 | it('should return a wave file with 64-bit ' + |
|
| 225 | 'audio and a odd number of samples', |
|
| 226 | function() { |
|
| 227 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 228 | [0.0, 0.04029440055111987, -0.04029440055111987, 1.0, 1]); |
|
| 229 | let wavRead = rw64.readWavBytes(wav); |
|
| 230 | ||
| 231 | assert.equal(wavRead.audioFormat, 3); |
|
| 232 | assert.equal(wavRead.numChannels, 1); |
|
| 233 | assert.equal(wavRead.sampleRate, 48000); |
|
| 234 | assert.equal(wavRead.blockAlign, 8); |
|
| 235 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 236 | assert.deepEqual(wavRead.samples, |
|
| 237 | [0.0, 0.04029440055111987, -0.04029440055111987, 1, 1]); |
|
| 238 | }); |
|
| 239 | ||
| 240 | it('check rouding for double values on read/write', |
|
| 241 | function() { |
|
| 242 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 243 | [3.141592653589793]); |
|
| 244 | let wavRead = rw64.readWavBytes(wav); |
|
| 245 | ||
| 246 | assert.ok(wavRead.samples[0] == |
|
| 247 | 3.141592653589793); |
|
| 248 | ||
| 249 | }); |
|
| 250 | ||
| 251 | it('check rouding for double values on read/write (forced change)', |
|
| 252 | function() { |
|
| 253 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 254 | [3.141592653589793]); |
|
| 255 | let wavRead = rw64.readWavBytes(wav); |
|
| 256 | ||
| 257 | assert.ok(wavRead.samples[0] != |
|
| 258 | 3.141592653589792); |
|
| 259 | }); |
|
| 260 | ||
| 261 | it('should return a wave file with 64-bit audio on max and min range', |
|
| 262 | function() { |
|
| 263 | let wav = rw64.writeWavBytes(1, 48000, '64', [0,1,0,-1]); |
|
| 264 | let wavRead = rw64.readWavBytes(wav); |
|
| 265 | ||
| 266 | assert.equal(wavRead.audioFormat, 3); |
|
| 267 | assert.equal(wavRead.numChannels, 1); |
|
| 268 | assert.equal(wavRead.sampleRate, 48000); |
|
| 269 | assert.equal(wavRead.blockAlign, 8); |
|
| 270 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 271 | assert.deepEqual(wavRead.samples, [0,1,0,-1]); |
|
| 272 | }); |
|
| 273 | ||
| 274 | it('should return another wave file with 64-bit audio', function() { |
|
| 275 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 276 | [0.0, 0.99999999999999999, -0.00000000000000001, 1]); |
|
| 277 | let wavRead = rw64.readWavBytes(wav); |
|
| 278 | ||
| 279 | assert.equal(wavRead.audioFormat, 3); |
|
| 280 | assert.equal(wavRead.numChannels, 1); |
|
| 281 | assert.equal(wavRead.sampleRate, 48000); |
|
| 282 | assert.equal(wavRead.blockAlign, 8); |
|
| 283 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 284 | assert.deepEqual(wavRead.samples, |
|
| 285 | [0, 0.99999999999999999, -0.00000000000000001, 1]); |
|
| 286 | }); |
|
| 287 | ||
| 288 | it('should return one more wave file with 64-bit audio', function() { |
|
| 289 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 290 | [0, 1, 1, -1, 0, -1, 0.99999999999999999, |
|
| 291 | -0.00000000000000001, 1]); |
|
| 292 | let wavRead = rw64.readWavBytes(wav); |
|
| 293 | ||
| 294 | assert.equal(wavRead.audioFormat, 3); |
|
| 295 | assert.equal(wavRead.numChannels, 1); |
|
| 296 | assert.equal(wavRead.sampleRate, 48000); |
|
| 297 | assert.equal(wavRead.blockAlign, 8); |
|
| 298 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 299 | assert.deepEqual(wavRead.samples, |
|
| 300 | [0, 1, 1, -1, 0, -1, 0.99999999999999999, |
|
| 301 | -0.00000000000000001, 1]); |
|
| 302 | }); |
|
| 303 | ||
| 304 | it('should return a 24-bit wave file with 8 channels', function() { |
|
| 305 | let wav = rw64.writeWavBytes(8, 48000, '24', |
|
| 306 | [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]); |
|
| 307 | let read = rw64.readWavBytes(wav); |
|
| 308 | ||
| 309 | assert.equal(read.subChunk1Size, 16); |
|
| 310 | assert.equal(read.audioFormat, 1); |
|
| 311 | assert.equal(read.numChannels, 8); |
|
| 312 | assert.equal(read.sampleRate, 48000); |
|
| 313 | assert.equal(read.blockAlign, 24); |
|
| 314 | assert.equal(read.bitsPerSample, 24); |
|
| 315 | }); |
|
| 316 | ||
| 317 | it('should return a 32-bit PCM wave file with 7 channels', function() { |
|
| 318 | let wav = rw64.writeWavBytes(7, 48000, '32', |
|
| 319 | [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]); |
|
| 320 | let read = rw64.readWavBytes(wav); |
|
| 321 | ||
| 322 | assert.equal(read.subChunk1Size, 16); |
|
| 323 | assert.equal(read.audioFormat, 1); |
|
| 324 | assert.equal(read.numChannels, 7); |
|
| 325 | assert.equal(read.sampleRate, 48000); |
|
| 326 | assert.equal(read.blockAlign, 28); |
|
| 327 | assert.equal(read.bitsPerSample, 32); |
|
| 328 | }); |
|
| 329 | ||
| 330 | it('should return a 24-bit wave file encoded as a base 64 string', |
|
| 331 | function() { |
|
| 332 | assert.ok(rw64.writeWavBase64(1, 48000, '24', |
|
| 333 | [0, 0.5, -0.5])); |
|
| 334 | }); |
|
| 335 | ||
| 336 | it('should return a 32-bit IEEE wave file encoded as a base 64 string', |
|
| 337 | function() { |
|
| 338 | assert.ok(rw64.writeWavBase64(1, 48000, '32f', |
|
| 339 | [0, 0.5, -0.5])); |
|
| 340 | }); |
|
| 341 | ||
| 342 | it('should return a 64-bit wave file encoded as a base 64 string', |
|
| 343 | function() { |
|
| 344 | assert.ok(rw64.writeWavBase64(1, 48000, '64', |
|
| 345 | [0, 0.5, -0.5])); |
|
| 346 | }); |
|
| 347 | ||
| 348 | it('should return a 24-bit wave file encoded as a Data URI', |
|
| 349 | function() { |
|
| 350 | assert.ok(rw64.writeWavDataURI(1, 48000, '24', |
|
| 351 | [0, 0.5, -0.5])); |
|
| 352 | }); |
|
| 353 | ||
| 354 | it('should return a 32-bit IEEE wave file encoded as a Data URI', |
|
| 355 | function() { |
|
| 356 | assert.ok(rw64.writeWavDataURI(1, 48000, '32f', |
|
| 357 | [0, 0.5, -0.5])); |
|
| 358 | }); |
|
| 359 | ||
| 360 | it('should return a 64-bit wave file encoded as a Data URI', |
|
| 361 | function() { |
|
| 362 | assert.ok(rw64.writeWavDataURI(1, 48000, '64', |
|
| 363 | [0, 0.5, -0.5])); |
|
| 364 | }); |
|
| 365 | ||
| 366 | it('should return another 64-bit wave file encoded as a Data URI', |
|
| 367 | function() { |
|
| 368 | assert.ok(rw64.writeWavDataURI(1, 48000, '64', |
|
| 369 | [0, 1, -1, 0, 1])); |
|
| 370 | }); |
|
| 371 | ||
| 372 | it('should write a 8-bit wav file with 1 Hz sample rate', |
|
| 373 | function() { |
|
| 374 | let samples = [0,1]; |
|
| 375 | let wav = rw64.writeWavBytes(1, 1, '8', samples); |
|
| 376 | let read = rw64.readWavBytes(wav); |
|
| 377 | ||
| 378 | assert.equal(read.subChunk1Size, 16); |
|
| 379 | assert.equal(read.audioFormat, 1); |
|
| 380 | assert.equal(read.numChannels, 1); |
|
| 381 | assert.equal(read.sampleRate, 1); |
|
| 382 | assert.equal(read.blockAlign, 1); |
|
| 383 | assert.equal(read.bitsPerSample, 8); |
|
| 384 | }); |
|
| 385 | ||
| 386 | it('should write a 8-bit stereo wav file', function() { |
|
| 387 | let channels = [ |
|
| 388 | [0,1,2], |
|
| 389 | [0,1,2] |
|
| 390 | ]; |
|
| 391 | let samples = rw64.interleave(channels); |
|
| 392 | let wav = rw64.writeWavBytes(2, 44100, '8', samples); |
|
| 393 | let read = rw64.readWavBytes(wav); |
|
| 394 | ||
| 395 | assert.equal(read.subChunk1Size, 16); |
|
| 396 | assert.equal(read.audioFormat, 1); |
|
| 397 | assert.equal(read.numChannels, 2); |
|
| 398 | assert.equal(read.sampleRate, 44100); |
|
| 399 | assert.equal(read.blockAlign, 2); |
|
| 400 | assert.equal(read.bitsPerSample, 8); |
|
| 401 | }); |
|
| 402 | ||
| 403 | it('should write a 16-bit stereo wav file', function() { |
|
| 404 | let channels = [ |
|
| 405 | [0,1,2], |
|
| 406 | [0,1,2] |
|
| 407 | ]; |
|
| 408 | let samples = rw64.interleave(channels); |
|
| 409 | let wav = rw64.writeWavBytes(2, 44100, '16', samples); |
|
| 410 | let read = rw64.readWavBytes(wav); |
|
| 411 | ||
| 412 | assert.equal(read.subChunk1Size, 16); |
|
| 413 | assert.equal(read.audioFormat, 1); |
|
| 414 | assert.equal(read.numChannels, 2); |
|
| 415 | assert.equal(read.sampleRate, 44100); |
|
| 416 | assert.equal(read.blockAlign, 4); |
|
| 417 | assert.equal(read.bitsPerSample, 16); |
|
| 418 | }); |
|
| 419 | ||
| 420 | it('should write a 24-bit stereo wav file', function() { |
|
| 421 | let channels = [ |
|
| 422 | [0,1,2], |
|
| 423 | [0,1,2] |
|
| 424 | ]; |
|
| 425 | let samples = rw64.interleave(channels); |
|
| 426 | let wav = rw64.writeWavBytes(2, 44100, '24', samples); |
|
| 427 | let read = rw64.readWavBytes(wav); |
|
| 428 | ||
| 429 | assert.equal(read.subChunk1Size, 16); |
|
| 430 | assert.equal(read.audioFormat, 1); |
|
| 431 | assert.equal(read.numChannels, 2); |
|
| 432 | assert.equal(read.sampleRate, 44100); |
|
| 433 | assert.equal(read.blockAlign, 6); |
|
| 434 | assert.equal(read.bitsPerSample, 24); |
|
| 435 | }); |
|
| 436 | ||
| 437 | it('should write a 24-bit stereo wav file', function() { |
|
| 438 | let channels = [ |
|
| 439 | [0,1,2], |
|
| 440 | [0,1,2] |
|
| 441 | ]; |
|
| 442 | let samples = rw64.interleave(channels); |
|
| 443 | let wav = rw64.writeWavBytes(2, 44100, '24', samples); |
|
| 444 | let read = rw64.readWavBytes(wav); |
|
| 445 | ||
| 446 | assert.equal(read.subChunk1Size, 16); |
|
| 447 | assert.equal(read.audioFormat, 1); |
|
| 448 | assert.equal(read.numChannels, 2); |
|
| 449 | assert.equal(read.sampleRate, 44100); |
|
| 450 | assert.equal(read.blockAlign, 6); |
|
| 451 | assert.equal(read.bitsPerSample, 24); |
|
| 452 | }); |
|
| 453 | ||
| 454 | it('should write a 32-bit PCM stereo wav file', function() { |
|
| 455 | let channels = [ |
|
| 456 | [0,1,2], |
|
| 457 | [0,1,2] |
|
| 458 | ]; |
|
| 459 | let samples = rw64.interleave(channels); |
|
| 460 | let wav = rw64.writeWavBytes(2, 44100, '32', samples); |
|
| 461 | let read = rw64.readWavBytes(wav); |
|
| 462 | ||
| 463 | assert.equal(read.subChunk1Size, 16); |
|
| 464 | assert.equal(read.audioFormat, 1); |
|
| 465 | assert.equal(read.numChannels, 2); |
|
| 466 | assert.equal(read.sampleRate, 44100); |
|
| 467 | assert.equal(read.blockAlign, 8); |
|
| 468 | assert.equal(read.bitsPerSample, 32); |
|
| 469 | }); |
|
| 470 | ||
| 471 | it('should write a 32-bit IEEE stereo wav file', function() { |
|
| 472 | let channels = [ |
|
| 473 | [0,1,-1], |
|
| 474 | [0,1,-1] |
|
| 475 | ]; |
|
| 476 | let samples = rw64.interleave(channels); |
|
| 477 | let wav = rw64.writeWavBytes(2, 44100, '32f', samples); |
|
| 478 | let read = rw64.readWavBytes(wav); |
|
| 479 | ||
| 480 | assert.equal(read.subChunk1Size, 16); |
|
| 481 | assert.equal(read.audioFormat, 3); |
|
| 482 | assert.equal(read.numChannels, 2); |
|
| 483 | assert.equal(read.sampleRate, 44100); |
|
| 484 | assert.equal(read.blockAlign, 8); |
|
| 485 | assert.equal(read.bitsPerSample, 32); |
|
| 486 | }); |
|
| 487 | ||
| 488 | it('should write a 64-bit stereo wav file', function() { |
|
| 489 | let channels = [ |
|
| 490 | [0,1,-1], |
|
| 491 | [0,1,-1] |
|
| 492 | ]; |
|
| 493 | let samples = rw64.interleave(channels); |
|
| 494 | let wav = rw64.writeWavBytes(2, 44100, '64', samples); |
|
| 495 | let read = rw64.readWavBytes(wav); |
|
| 496 | ||
| 497 | assert.equal(read.subChunk1Size, 16); |
|
| 498 | assert.equal(read.audioFormat, 3); |
|
| 499 | assert.equal(read.numChannels, 2); |
|
| 500 | assert.equal(read.sampleRate, 44100); |
|
| 501 | assert.equal(read.blockAlign, 16); |
|
| 502 | assert.equal(read.bitsPerSample, 64); |
|
| 503 | }); |
|
| 504 | ||
| 505 | it('should return a 64-bit wave file with non-negative 0', |
|
| 506 | function() { |
|
| 507 | let wav = rw64.writeWavBytes(1, 48000, '64', [0, 1, -1, -0, 1]); |
|
| 508 | let wavRead = rw64.readWavBytes(wav); |
|
| 509 | assert.equal(wavRead.audioFormat, 3); |
|
| 510 | assert.equal(wavRead.numChannels, 1); |
|
| 511 | assert.equal(wavRead.sampleRate, 48000); |
|
| 512 | assert.equal(wavRead.blockAlign, 8); |
|
| 513 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 514 | assert.deepEqual(wavRead.samples, [0, 1, -1, 0, 1]); |
|
| 515 | }); |
|
| 516 | ||
| 517 | it('should return a 32-bit PCM file with max possible sample value', |
|
| 518 | function() { |
|
| 519 | let wav = rw64.writeWavBytes(1, 16000, '32', |
|
| 520 | [-2147483648, 2147483647, -1, 1, 0]); |
|
| 521 | let wavRead = rw64.readWavBytes(wav); |
|
| 522 | assert.equal(wavRead.audioFormat, 1); |
|
| 523 | assert.equal(wavRead.numChannels, 1); |
|
| 524 | assert.equal(wavRead.sampleRate, 16000); |
|
| 525 | assert.equal(wavRead.blockAlign, 4); |
|
| 526 | assert.equal(wavRead.bitsPerSample, 32); |
|
| 527 | assert.deepEqual(wavRead.samples, |
|
| 528 | [-2147483648, 2147483647, -1, 1, 0]); |
|
| 529 | }); |
|
| 530 | */ |
|
| 531 | }); |
|
| 532 | ||
| @@ 10-219 (lines=210) @@ | ||
| 7 | * |
|
| 8 | */ |
|
| 9 | ||
| 10 | var assert = require('assert'); |
|
| 11 | ||
| 12 | describe('create 64-bit wave file from scratch', function() { |
|
| 13 | ||
| 14 | let wavefile = require('../../index.js'); |
|
| 15 | let wav = new wavefile.WaveFile(); |
|
| 16 | wav.fromScratch(1, 44100, '64', [0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
|
| 17 | ||
| 18 | let fs = require('fs'); |
|
| 19 | fs.writeFileSync("./test/files/out/64-bit-441kHz-mono-fromScratch.wav", wav.toBytes()); |
|
| 20 | ||
| 21 | it('chunkId should be "RIFF"', function() { |
|
| 22 | assert.equal(wav.chunkId, "RIFF"); |
|
| 23 | }); |
|
| 24 | ||
| 25 | it('format should be "WAVE"', function() { |
|
| 26 | assert.equal(wav.format, "WAVE"); |
|
| 27 | }); |
|
| 28 | ||
| 29 | it('subChunk1Id should be "fmt "', function() { |
|
| 30 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 31 | }); |
|
| 32 | ||
| 33 | it('subChunk1Size should be 16', function() { |
|
| 34 | assert.equal(wav.subChunk1Size, 16); |
|
| 35 | }); |
|
| 36 | ||
| 37 | it('audioFormat should be 3', function() { |
|
| 38 | assert.equal(wav.audioFormat, 3); |
|
| 39 | }); |
|
| 40 | ||
| 41 | it('numChannels should be 1', function() { |
|
| 42 | assert.equal(wav.numChannels, 1); |
|
| 43 | }); |
|
| 44 | ||
| 45 | it('sampleRate should be 44100', function() { |
|
| 46 | assert.equal(wav.sampleRate, 44100); |
|
| 47 | }); |
|
| 48 | ||
| 49 | it('byteRate should be 176400', function() { |
|
| 50 | assert.equal(wav.byteRate, 352800); |
|
| 51 | }); |
|
| 52 | ||
| 53 | it('blockAlign should be 4', function() { |
|
| 54 | assert.equal(wav.blockAlign, 8); |
|
| 55 | }); |
|
| 56 | ||
| 57 | it('bitsPerSample should be 32', function() { |
|
| 58 | assert.equal(wav.bitsPerSample, 64); |
|
| 59 | }); |
|
| 60 | ||
| 61 | it('subChunk2Id should be "data"', function() { |
|
| 62 | assert.equal(wav.subChunk2Id, "data"); |
|
| 63 | }); |
|
| 64 | ||
| 65 | it('subChunk2Size should be 16', function() { |
|
| 66 | assert.equal(wav.subChunk2Size, 32); |
|
| 67 | }); |
|
| 68 | ||
| 69 | it('samples_ should be the same as the args', function() { |
|
| 70 | assert.deepEqual(wav.samples_, [0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
|
| 71 | }); |
|
| 72 | ||
| 73 | it('bitDepth_ should be "24"', function() { |
|
| 74 | assert.equal(wav.bitDepth_, "64"); |
|
| 75 | }); |
|
| 76 | ||
| 77 | /* |
|
| 78 | it('should return a wave file with 64-bit audio', function() { |
|
| 79 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 80 | [0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
|
| 81 | let wavRead = rw64.readWavBytes(wav); |
|
| 82 | ||
| 83 | assert.equal(wavRead.audioFormat, 3); |
|
| 84 | assert.equal(wavRead.numChannels, 1); |
|
| 85 | assert.equal(wavRead.sampleRate, 48000); |
|
| 86 | assert.equal(wavRead.blockAlign, 8); |
|
| 87 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 88 | assert.deepEqual(wavRead.samples, |
|
| 89 | [0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
|
| 90 | }); |
|
| 91 | ||
| 92 | it('should return a wave file with 64-bit ' + |
|
| 93 | 'audio and a odd number of samples', |
|
| 94 | function() { |
|
| 95 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 96 | [0.0, 0.04029440055111987, -0.04029440055111987, 1.0, 1]); |
|
| 97 | let wavRead = rw64.readWavBytes(wav); |
|
| 98 | ||
| 99 | assert.equal(wavRead.audioFormat, 3); |
|
| 100 | assert.equal(wavRead.numChannels, 1); |
|
| 101 | assert.equal(wavRead.sampleRate, 48000); |
|
| 102 | assert.equal(wavRead.blockAlign, 8); |
|
| 103 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 104 | assert.deepEqual(wavRead.samples, |
|
| 105 | [0.0, 0.04029440055111987, -0.04029440055111987, 1, 1]); |
|
| 106 | }); |
|
| 107 | ||
| 108 | it('check rouding for double values on read/write', |
|
| 109 | function() { |
|
| 110 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 111 | [3.141592653589793]); |
|
| 112 | let wavRead = rw64.readWavBytes(wav); |
|
| 113 | ||
| 114 | assert.ok(wavRead.samples[0] == |
|
| 115 | 3.141592653589793); |
|
| 116 | ||
| 117 | }); |
|
| 118 | ||
| 119 | it('check rouding for double values on read/write (forced change)', |
|
| 120 | function() { |
|
| 121 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 122 | [3.141592653589793]); |
|
| 123 | let wavRead = rw64.readWavBytes(wav); |
|
| 124 | ||
| 125 | assert.ok(wavRead.samples[0] != |
|
| 126 | 3.141592653589792); |
|
| 127 | }); |
|
| 128 | ||
| 129 | it('should return a wave file with 64-bit audio on max and min range', |
|
| 130 | function() { |
|
| 131 | let wav = rw64.writeWavBytes(1, 48000, '64', [0,1,0,-1]); |
|
| 132 | let wavRead = rw64.readWavBytes(wav); |
|
| 133 | ||
| 134 | assert.equal(wavRead.audioFormat, 3); |
|
| 135 | assert.equal(wavRead.numChannels, 1); |
|
| 136 | assert.equal(wavRead.sampleRate, 48000); |
|
| 137 | assert.equal(wavRead.blockAlign, 8); |
|
| 138 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 139 | assert.deepEqual(wavRead.samples, [0,1,0,-1]); |
|
| 140 | }); |
|
| 141 | ||
| 142 | it('should return another wave file with 64-bit audio', function() { |
|
| 143 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 144 | [0.0, 0.99999999999999999, -0.00000000000000001, 1]); |
|
| 145 | let wavRead = rw64.readWavBytes(wav); |
|
| 146 | ||
| 147 | assert.equal(wavRead.audioFormat, 3); |
|
| 148 | assert.equal(wavRead.numChannels, 1); |
|
| 149 | assert.equal(wavRead.sampleRate, 48000); |
|
| 150 | assert.equal(wavRead.blockAlign, 8); |
|
| 151 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 152 | assert.deepEqual(wavRead.samples, |
|
| 153 | [0, 0.99999999999999999, -0.00000000000000001, 1]); |
|
| 154 | }); |
|
| 155 | ||
| 156 | it('should return one more wave file with 64-bit audio', function() { |
|
| 157 | let wav = rw64.writeWavBytes(1, 48000, '64', |
|
| 158 | [0, 1, 1, -1, 0, -1, 0.99999999999999999, |
|
| 159 | -0.00000000000000001, 1]); |
|
| 160 | let wavRead = rw64.readWavBytes(wav); |
|
| 161 | ||
| 162 | assert.equal(wavRead.audioFormat, 3); |
|
| 163 | assert.equal(wavRead.numChannels, 1); |
|
| 164 | assert.equal(wavRead.sampleRate, 48000); |
|
| 165 | assert.equal(wavRead.blockAlign, 8); |
|
| 166 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 167 | assert.deepEqual(wavRead.samples, |
|
| 168 | [0, 1, 1, -1, 0, -1, 0.99999999999999999, |
|
| 169 | -0.00000000000000001, 1]); |
|
| 170 | }); |
|
| 171 | ||
| 172 | it('should return a 64-bit wave file encoded as a base 64 string', |
|
| 173 | function() { |
|
| 174 | assert.ok(rw64.writeWavBase64(1, 48000, '64', |
|
| 175 | [0, 0.5, -0.5])); |
|
| 176 | }); |
|
| 177 | ||
| 178 | it('should return a 64-bit wave file encoded as a Data URI', |
|
| 179 | function() { |
|
| 180 | assert.ok(rw64.writeWavDataURI(1, 48000, '64', |
|
| 181 | [0, 0.5, -0.5])); |
|
| 182 | }); |
|
| 183 | ||
| 184 | it('should return another 64-bit wave file encoded as a Data URI', |
|
| 185 | function() { |
|
| 186 | assert.ok(rw64.writeWavDataURI(1, 48000, '64', |
|
| 187 | [0, 1, -1, 0, 1])); |
|
| 188 | }); |
|
| 189 | ||
| 190 | it('should write a 64-bit stereo wav file', function() { |
|
| 191 | let channels = [ |
|
| 192 | [0,1,-1], |
|
| 193 | [0,1,-1] |
|
| 194 | ]; |
|
| 195 | let samples = rw64.interleave(channels); |
|
| 196 | let wav = rw64.writeWavBytes(2, 44100, '64', samples); |
|
| 197 | let read = rw64.readWavBytes(wav); |
|
| 198 | ||
| 199 | assert.equal(read.subChunk1Size, 16); |
|
| 200 | assert.equal(read.audioFormat, 3); |
|
| 201 | assert.equal(read.numChannels, 2); |
|
| 202 | assert.equal(read.sampleRate, 44100); |
|
| 203 | assert.equal(read.blockAlign, 16); |
|
| 204 | assert.equal(read.bitsPerSample, 64); |
|
| 205 | }); |
|
| 206 | ||
| 207 | it('should return a 64-bit wave file with non-negative 0', |
|
| 208 | function() { |
|
| 209 | let wav = rw64.writeWavBytes(1, 48000, '64', [0, 1, -1, -0, 1]); |
|
| 210 | let wavRead = rw64.readWavBytes(wav); |
|
| 211 | assert.equal(wavRead.audioFormat, 3); |
|
| 212 | assert.equal(wavRead.numChannels, 1); |
|
| 213 | assert.equal(wavRead.sampleRate, 48000); |
|
| 214 | assert.equal(wavRead.blockAlign, 8); |
|
| 215 | assert.equal(wavRead.bitsPerSample, 64); |
|
| 216 | assert.deepEqual(wavRead.samples, [0, 1, -1, 0, 1]); |
|
| 217 | }); |
|
| 218 | */ |
|
| 219 | }); |
|
| 220 | ||
| @@ 10-166 (lines=157) @@ | ||
| 7 | * |
|
| 8 | */ |
|
| 9 | ||
| 10 | var assert = require('assert'); |
|
| 11 | ||
| 12 | describe('create 24-bit wave files from scratch', function() { |
|
| 13 | ||
| 14 | let wavefile = require('../../index.js'); |
|
| 15 | let wav = new wavefile.WaveFile(); |
|
| 16 | wav.fromScratch(1, 48000, '24', [0, 1, -8388608, 8388607]); |
|
| 17 | ||
| 18 | let fs = require('fs'); |
|
| 19 | fs.writeFileSync("./test/files/out/24-bit-48kHz-mono-fromScratch.wav", wav.toBytes()); |
|
| 20 | ||
| 21 | it('chunkId should be "RIFF"', function() { |
|
| 22 | assert.equal(wav.chunkId, "RIFF"); |
|
| 23 | }); |
|
| 24 | ||
| 25 | it('format should be "WAVE"', function() { |
|
| 26 | assert.equal(wav.format, "WAVE"); |
|
| 27 | }); |
|
| 28 | ||
| 29 | it('subChunk1Id should be "fmt "', function() { |
|
| 30 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 31 | }); |
|
| 32 | ||
| 33 | it('subChunk1Size should be 16', function() { |
|
| 34 | assert.equal(wav.subChunk1Size, 16); |
|
| 35 | }); |
|
| 36 | ||
| 37 | it('audioFormat should be 1', function() { |
|
| 38 | assert.equal(wav.audioFormat, 1); |
|
| 39 | }); |
|
| 40 | ||
| 41 | it('numChannels should be 1', function() { |
|
| 42 | assert.equal(wav.numChannels, 1); |
|
| 43 | }); |
|
| 44 | ||
| 45 | it('sampleRate should be 48000', function() { |
|
| 46 | assert.equal(wav.sampleRate, 48000); |
|
| 47 | }); |
|
| 48 | ||
| 49 | it('byteRate should be 144000', function() { |
|
| 50 | assert.equal(wav.byteRate, 144000); |
|
| 51 | }); |
|
| 52 | ||
| 53 | it('blockAlign should be 3', function() { |
|
| 54 | assert.equal(wav.blockAlign, 3); |
|
| 55 | }); |
|
| 56 | ||
| 57 | it('bitsPerSample should be 24', function() { |
|
| 58 | assert.equal(wav.bitsPerSample, 24); |
|
| 59 | }); |
|
| 60 | ||
| 61 | it('subChunk2Id should be "data"', function() { |
|
| 62 | assert.equal(wav.subChunk2Id, "data"); |
|
| 63 | }); |
|
| 64 | ||
| 65 | it('subChunk2Size should be 12', function() { |
|
| 66 | assert.equal(wav.subChunk2Size, 12); |
|
| 67 | }); |
|
| 68 | ||
| 69 | it('samples_ should be the same as the args', function() { |
|
| 70 | assert.deepEqual(wav.samples_, [0, 1, -8388608, 8388607]); |
|
| 71 | }); |
|
| 72 | ||
| 73 | it('bitDepth_ should be "24"', function() { |
|
| 74 | assert.equal(wav.bitDepth_, "24"); |
|
| 75 | }); |
|
| 76 | ||
| 77 | /* |
|
| 78 | it('should return a 24-bit wave file', function() { |
|
| 79 | let wav = rw64.writeWavBytes(1, 48000, '24', |
|
| 80 | [0, 1, -8388608, 8388607]); |
|
| 81 | let wavRead = rw64.readWavBytes(wav); |
|
| 82 | ||
| 83 | assert.equal(wavRead.audioFormat, 1); |
|
| 84 | assert.equal(wavRead.numChannels, 1); |
|
| 85 | assert.equal(wavRead.blockAlign, 3); |
|
| 86 | assert.equal(wavRead.sampleRate, 48000); |
|
| 87 | assert.equal(wavRead.bitsPerSample, 24); |
|
| 88 | assert.equal(wavRead.subChunk2Size, 12); // 4 x 3 |
|
| 89 | assert.deepEqual(wavRead.samples, [0, 1, -8388608, 8388607]); |
|
| 90 | }); |
|
| 91 | ||
| 92 | it('should return a 24-bit wave file with a odd number of samples', |
|
| 93 | function() { |
|
| 94 | let wav = rw64.writeWavBytes(1, 48000, '24', |
|
| 95 | [0, 1, -8388608, 8388607, 4]); |
|
| 96 | let wavRead = rw64.readWavBytes(wav); |
|
| 97 | ||
| 98 | assert.equal(wavRead.audioFormat, 1); |
|
| 99 | assert.equal(wavRead.numChannels, 1); |
|
| 100 | assert.equal(wavRead.sampleRate, 48000); |
|
| 101 | assert.equal(wavRead.bitsPerSample, 24); |
|
| 102 | assert.equal(wavRead.blockAlign, 3); |
|
| 103 | assert.equal(wavRead.subChunk2Size, 15); // 5 x 3 |
|
| 104 | assert.deepEqual(wavRead.samples, [0, 1, -8388608, 8388607, 4]); |
|
| 105 | }); |
|
| 106 | ||
| 107 | it('should return a 24-bit wave file with 8 channels', function() { |
|
| 108 | let wav = rw64.writeWavBytes(8, 48000, '24', |
|
| 109 | [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]); |
|
| 110 | let read = rw64.readWavBytes(wav); |
|
| 111 | ||
| 112 | assert.equal(read.subChunk1Size, 16); |
|
| 113 | assert.equal(read.audioFormat, 1); |
|
| 114 | assert.equal(read.numChannels, 8); |
|
| 115 | assert.equal(read.sampleRate, 48000); |
|
| 116 | assert.equal(read.blockAlign, 24); |
|
| 117 | assert.equal(read.bitsPerSample, 24); |
|
| 118 | }); |
|
| 119 | ||
| 120 | it('should return a 24-bit wave file encoded as a base 64 string', |
|
| 121 | function() { |
|
| 122 | assert.ok(rw64.writeWavBase64(1, 48000, '24', |
|
| 123 | [0, 0.5, -0.5])); |
|
| 124 | }); |
|
| 125 | ||
| 126 | it('should return a 24-bit wave file encoded as a Data URI', |
|
| 127 | function() { |
|
| 128 | assert.ok(rw64.writeWavDataURI(1, 48000, '24', |
|
| 129 | [0, 0.5, -0.5])); |
|
| 130 | }); |
|
| 131 | ||
| 132 | it('should write a 24-bit stereo wav file', function() { |
|
| 133 | let channels = [ |
|
| 134 | [0,1,2], |
|
| 135 | [0,1,2] |
|
| 136 | ]; |
|
| 137 | let samples = rw64.interleave(channels); |
|
| 138 | let wav = rw64.writeWavBytes(2, 44100, '24', samples); |
|
| 139 | let read = rw64.readWavBytes(wav); |
|
| 140 | ||
| 141 | assert.equal(read.subChunk1Size, 16); |
|
| 142 | assert.equal(read.audioFormat, 1); |
|
| 143 | assert.equal(read.numChannels, 2); |
|
| 144 | assert.equal(read.sampleRate, 44100); |
|
| 145 | assert.equal(read.blockAlign, 6); |
|
| 146 | assert.equal(read.bitsPerSample, 24); |
|
| 147 | }); |
|
| 148 | ||
| 149 | it('should write a 24-bit stereo wav file', function() { |
|
| 150 | let channels = [ |
|
| 151 | [0,1,2], |
|
| 152 | [0,1,2] |
|
| 153 | ]; |
|
| 154 | let samples = rw64.interleave(channels); |
|
| 155 | let wav = rw64.writeWavBytes(2, 44100, '24', samples); |
|
| 156 | let read = rw64.readWavBytes(wav); |
|
| 157 | ||
| 158 | assert.equal(read.subChunk1Size, 16); |
|
| 159 | assert.equal(read.audioFormat, 1); |
|
| 160 | assert.equal(read.numChannels, 2); |
|
| 161 | assert.equal(read.sampleRate, 44100); |
|
| 162 | assert.equal(read.blockAlign, 6); |
|
| 163 | assert.equal(read.bitsPerSample, 24); |
|
| 164 | }); |
|
| 165 | */ |
|
| 166 | }); |
|
| 167 | ||
| @@ 10-149 (lines=140) @@ | ||
| 7 | * |
|
| 8 | */ |
|
| 9 | ||
| 10 | var assert = require('assert'); |
|
| 11 | ||
| 12 | describe('create 32-bit PCM wave files from scratch', function() { |
|
| 13 | ||
| 14 | let wavefile = require('../../index.js'); |
|
| 15 | let wav = new wavefile.WaveFile(); |
|
| 16 | wav.fromScratch(1, 44100, '32', [0, -2147483648, 2147483647, 4]); |
|
| 17 | ||
| 18 | let fs = require('fs'); |
|
| 19 | fs.writeFileSync("./test/files/out/32-bitPCM-441kHz-mono-fromScratch.wav", wav.toBytes()); |
|
| 20 | ||
| 21 | it('chunkId should be "RIFF"', function() { |
|
| 22 | assert.equal(wav.chunkId, "RIFF"); |
|
| 23 | }); |
|
| 24 | ||
| 25 | it('format should be "WAVE"', function() { |
|
| 26 | assert.equal(wav.format, "WAVE"); |
|
| 27 | }); |
|
| 28 | ||
| 29 | it('subChunk1Id should be "fmt "', function() { |
|
| 30 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 31 | }); |
|
| 32 | ||
| 33 | it('subChunk1Size should be 16', function() { |
|
| 34 | assert.equal(wav.subChunk1Size, 16); |
|
| 35 | }); |
|
| 36 | ||
| 37 | it('audioFormat should be 1', function() { |
|
| 38 | assert.equal(wav.audioFormat, 1); |
|
| 39 | }); |
|
| 40 | ||
| 41 | it('numChannels should be 1', function() { |
|
| 42 | assert.equal(wav.numChannels, 1); |
|
| 43 | }); |
|
| 44 | ||
| 45 | it('sampleRate should be 44100', function() { |
|
| 46 | assert.equal(wav.sampleRate, 44100); |
|
| 47 | }); |
|
| 48 | ||
| 49 | it('byteRate should be 176400', function() { |
|
| 50 | assert.equal(wav.byteRate, 176400); |
|
| 51 | }); |
|
| 52 | ||
| 53 | it('blockAlign should be 4', function() { |
|
| 54 | assert.equal(wav.blockAlign, 4); |
|
| 55 | }); |
|
| 56 | ||
| 57 | it('bitsPerSample should be 32', function() { |
|
| 58 | assert.equal(wav.bitsPerSample, 32); |
|
| 59 | }); |
|
| 60 | ||
| 61 | it('subChunk2Id should be "data"', function() { |
|
| 62 | assert.equal(wav.subChunk2Id, "data"); |
|
| 63 | }); |
|
| 64 | ||
| 65 | it('subChunk2Size should be 16', function() { |
|
| 66 | assert.equal(wav.subChunk2Size, 16); |
|
| 67 | }); |
|
| 68 | ||
| 69 | it('samples_ should be the same as the args', function() { |
|
| 70 | assert.deepEqual(wav.samples_, [0, -2147483648, 2147483647, 4]); |
|
| 71 | }); |
|
| 72 | ||
| 73 | it('bitDepth_ should be "24"', function() { |
|
| 74 | assert.equal(wav.bitDepth_, "32"); |
|
| 75 | }); |
|
| 76 | ||
| 77 | /* |
|
| 78 | it('should return a 32-bit PCM wave file', function() { |
|
| 79 | let wav = rw64.writeWavBytes(1, 44100, '32', |
|
| 80 | [0, -2147483648, 2147483647, 4]); |
|
| 81 | let wavRead = rw64.readWavBytes(wav); |
|
| 82 | ||
| 83 | assert.equal(wavRead.audioFormat, 1); |
|
| 84 | assert.equal(wavRead.numChannels, 1); |
|
| 85 | assert.equal(wavRead.sampleRate, 44100); |
|
| 86 | assert.equal(wavRead.bitsPerSample, 32); |
|
| 87 | assert.equal(wavRead.blockAlign, 4); |
|
| 88 | assert.deepEqual(wavRead.samples, [0, -2147483648, 2147483647, 4]); |
|
| 89 | }); |
|
| 90 | ||
| 91 | it('should return a 32-bit PCM wave file with a odd number of samples', |
|
| 92 | function() { |
|
| 93 | let wav = rw64.writeWavBytes(1, 44100, '32', |
|
| 94 | [0, -2147483648, 45, 0, 1]); |
|
| 95 | let wavRead = rw64.readWavBytes(wav); |
|
| 96 | ||
| 97 | assert.equal(wavRead.audioFormat, 1); |
|
| 98 | assert.equal(wavRead.numChannels, 1); |
|
| 99 | assert.equal(wavRead.sampleRate, 44100); |
|
| 100 | assert.equal(wavRead.bitsPerSample, 32); |
|
| 101 | assert.equal(wavRead.blockAlign, 4); |
|
| 102 | assert.deepEqual(wavRead.samples, [0, -2147483648, 45, 0, 1]); |
|
| 103 | }); |
|
| 104 | ||
| 105 | it('should return a 32-bit PCM wave file with 7 channels', function() { |
|
| 106 | let wav = rw64.writeWavBytes(7, 48000, '32', |
|
| 107 | [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]); |
|
| 108 | let read = rw64.readWavBytes(wav); |
|
| 109 | ||
| 110 | assert.equal(read.subChunk1Size, 16); |
|
| 111 | assert.equal(read.audioFormat, 1); |
|
| 112 | assert.equal(read.numChannels, 7); |
|
| 113 | assert.equal(read.sampleRate, 48000); |
|
| 114 | assert.equal(read.blockAlign, 28); |
|
| 115 | assert.equal(read.bitsPerSample, 32); |
|
| 116 | }); |
|
| 117 | ||
| 118 | it('should write a 32-bit PCM stereo wav file', function() { |
|
| 119 | let channels = [ |
|
| 120 | [0,1,2], |
|
| 121 | [0,1,2] |
|
| 122 | ]; |
|
| 123 | let samples = rw64.interleave(channels); |
|
| 124 | let wav = rw64.writeWavBytes(2, 44100, '32', samples); |
|
| 125 | let read = rw64.readWavBytes(wav); |
|
| 126 | ||
| 127 | assert.equal(read.subChunk1Size, 16); |
|
| 128 | assert.equal(read.audioFormat, 1); |
|
| 129 | assert.equal(read.numChannels, 2); |
|
| 130 | assert.equal(read.sampleRate, 44100); |
|
| 131 | assert.equal(read.blockAlign, 8); |
|
| 132 | assert.equal(read.bitsPerSample, 32); |
|
| 133 | }); |
|
| 134 | ||
| 135 | it('should return a 32-bit PCM file with max possible sample value', |
|
| 136 | function() { |
|
| 137 | let wav = rw64.writeWavBytes(1, 16000, '32', |
|
| 138 | [-2147483648, 2147483647, -1, 1, 0]); |
|
| 139 | let wavRead = rw64.readWavBytes(wav); |
|
| 140 | assert.equal(wavRead.audioFormat, 1); |
|
| 141 | assert.equal(wavRead.numChannels, 1); |
|
| 142 | assert.equal(wavRead.sampleRate, 16000); |
|
| 143 | assert.equal(wavRead.blockAlign, 4); |
|
| 144 | assert.equal(wavRead.bitsPerSample, 32); |
|
| 145 | assert.deepEqual(wavRead.samples, |
|
| 146 | [-2147483648, 2147483647, -1, 1, 0]); |
|
| 147 | }); |
|
| 148 | */ |
|
| 149 | }); |
|
| 150 | ||
| @@ 10-122 (lines=113) @@ | ||
| 7 | * |
|
| 8 | */ |
|
| 9 | ||
| 10 | var assert = require('assert'); |
|
| 11 | ||
| 12 | describe('create 16-bit wave files from scratch', function() { |
|
| 13 | ||
| 14 | let wavefile = require('../../index.js'); |
|
| 15 | let wav = new wavefile.WaveFile(); |
|
| 16 | wav.fromScratch(1, 48000, '16', [0, 1, -32768, 32767]); |
|
| 17 | ||
| 18 | let fs = require('fs'); |
|
| 19 | fs.writeFileSync("./test/files/out/16-bit-48kHz-mono-fromScratch.wav", wav.toBytes()); |
|
| 20 | ||
| 21 | it('chunkId should be "RIFF"', function() { |
|
| 22 | assert.equal(wav.chunkId, "RIFF"); |
|
| 23 | }); |
|
| 24 | ||
| 25 | it('format should be "WAVE"', function() { |
|
| 26 | assert.equal(wav.format, "WAVE"); |
|
| 27 | }); |
|
| 28 | ||
| 29 | it('subChunk1Id should be "fmt "', function() { |
|
| 30 | assert.equal(wav.subChunk1Id, "fmt "); |
|
| 31 | }); |
|
| 32 | ||
| 33 | it('subChunk1Size should be 16', function() { |
|
| 34 | assert.equal(wav.subChunk1Size, 16); |
|
| 35 | }); |
|
| 36 | ||
| 37 | it('audioFormat should be 1', function() { |
|
| 38 | assert.equal(wav.audioFormat, 1); |
|
| 39 | }); |
|
| 40 | ||
| 41 | it('numChannels should be 1', function() { |
|
| 42 | assert.equal(wav.numChannels, 1); |
|
| 43 | }); |
|
| 44 | ||
| 45 | it('sampleRate should be 48000', function() { |
|
| 46 | assert.equal(wav.sampleRate, 48000); |
|
| 47 | }); |
|
| 48 | ||
| 49 | it('byteRate should be 96000', function() { |
|
| 50 | assert.equal(wav.byteRate, 96000); |
|
| 51 | }); |
|
| 52 | ||
| 53 | it('blockAlign should be 2', function() { |
|
| 54 | assert.equal(wav.blockAlign, 2); |
|
| 55 | }); |
|
| 56 | ||
| 57 | it('bitsPerSample should be 16', function() { |
|
| 58 | assert.equal(wav.bitsPerSample, 16); |
|
| 59 | }); |
|
| 60 | ||
| 61 | it('subChunk2Id should be "data"', function() { |
|
| 62 | assert.equal(wav.subChunk2Id, "data"); |
|
| 63 | }); |
|
| 64 | ||
| 65 | it('subChunk2Size should be 8', function() { |
|
| 66 | assert.equal(wav.subChunk2Size, 8); |
|
| 67 | }); |
|
| 68 | ||
| 69 | it('samples_ should be the same as the args', function() { |
|
| 70 | assert.deepEqual(wav.samples_, [0, 1, -32768, 32767]); |
|
| 71 | }); |
|
| 72 | ||
| 73 | it('bitDepth_ should be "16"', function() { |
|
| 74 | assert.equal(wav.bitDepth_, "16"); |
|
| 75 | }); |
|
| 76 | ||
| 77 | /* |
|
| 78 | it('should return a 16-bit wave file', function() { |
|
| 79 | let wav = rw64.writeWavBytes(1, 48000, '16', |
|
| 80 | [0, 1, -32768, 32767]); |
|
| 81 | let wavRead = rw64.readWavBytes(wav); |
|
| 82 | ||
| 83 | assert.equal(wavRead.audioFormat, 1); |
|
| 84 | assert.equal(wavRead.numChannels, 1); |
|
| 85 | assert.equal(wavRead.blockAlign, 2); |
|
| 86 | assert.equal(wavRead.sampleRate, 48000); |
|
| 87 | assert.equal(wavRead.bitsPerSample, 16); |
|
| 88 | assert.deepEqual(wavRead.samples, [0, 1, -32768, 32767]); |
|
| 89 | }); |
|
| 90 | ||
| 91 | it('should return a 16-bit wave file with a odd number of samples', |
|
| 92 | function() { |
|
| 93 | let wav = rw64.writeWavBytes(1, 48000, '16', |
|
| 94 | [0, 1, -32768, 32767, 4]); |
|
| 95 | let wavRead = rw64.readWavBytes(wav); |
|
| 96 | ||
| 97 | assert.equal(wavRead.audioFormat, 1); |
|
| 98 | assert.equal(wavRead.numChannels, 1); |
|
| 99 | assert.equal(wavRead.blockAlign, 2); |
|
| 100 | assert.equal(wavRead.sampleRate, 48000); |
|
| 101 | assert.equal(wavRead.bitsPerSample, 16); |
|
| 102 | assert.deepEqual(wavRead.samples, [0, 1, -32768, 32767, 4]); |
|
| 103 | }); |
|
| 104 | ||
| 105 | it('should write a 16-bit stereo wav file', function() { |
|
| 106 | let channels = [ |
|
| 107 | [0,1,2], |
|
| 108 | [0,1,2] |
|
| 109 | ]; |
|
| 110 | let samples = rw64.interleave(channels); |
|
| 111 | let wav = rw64.writeWavBytes(2, 44100, '16', samples); |
|
| 112 | let read = rw64.readWavBytes(wav); |
|
| 113 | ||
| 114 | assert.equal(read.subChunk1Size, 16); |
|
| 115 | assert.equal(read.audioFormat, 1); |
|
| 116 | assert.equal(read.numChannels, 2); |
|
| 117 | assert.equal(read.sampleRate, 44100); |
|
| 118 | assert.equal(read.blockAlign, 4); |
|
| 119 | assert.equal(read.bitsPerSample, 16); |
|
| 120 | }); |
|
| 121 | */ |
|
| 122 | }); |
|
| 123 | ||