MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / getSamples

Method getSamples

modules/data/wavreader/wavreader.js:60–78  ·  view source on GitHub ↗
(buffer, count)

Source from the content-addressed store, hash-verified

58 }
59
60 getSamples(buffer, count) { // always returns signed 16-bit sample values
61 this.samples -= count;
62 if (this.samples < 0)
63 throw Error("out of samples");
64
65 count *= this.numChannels;
66 let i = 0;
67 if (16 === this.bitsPerSample) {
68 while (count--)
69 buffer[i++] = this.readInt16();
70 }
71 else
72 if (8 === this.bitsPerSample) {
73 while (count--) {
74 let value = this.readInt8();
75 buffer[i++] = value << 8; // write Uint8 representation of value into low bits
76 }
77 }
78 }
79
80 readFourCC() {
81 let result = String.fromCharCode(this.wav.getUint8(this.position), this.wav.getUint8(this.position + 1),

Callers 2

runMethod · 0.80
readMethod · 0.80

Calls 2

readInt16Method · 0.95
readInt8Method · 0.95

Tested by

no test coverage detected