WeiWeiXinNet/Games/game3/js/other/waveAudio.js
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
function WAVEAudio(NumChannels, SampleRate, BitsPerSample) {
this.NumChannels = NumChannels; //Mono (1), Stereo (2), up to the 2-byte numerical limit.
this.SampleRate = SampleRate; //Updates per second for the amplitude.
this.BitsPerSample = BitsPerSample; //low quality - 8 bits, high quality - 16 bits.
this.samples = []; //Buffer for audio samples.
this.buildable = false; //Reserved for sanity checks.
this.init = function () {
//First Sanity Check
if (this.NumChannels >= 0x1 && this.NumChannels <= 0xFFFF && (this.BitsPerSample == 0x8 || this.BitsPerSample == 0x10)) {
this.buildable = true;
}
else {
throw(new Error("Initial setup values for WAVEAudio were invalid."));
}
};
this.compileWAVE = function () {
//Convert the buffer data into a raw WAV PCM formated binary stream
var sampleCount = this.samples.length / this.NumChannels;
var samplePayloadSize = this.BitsPerSample * this.NumChannels / 0x8;
var dataPayloadSize = sampleCount * samplePayloadSize;
var output = "RIFF" + to_little_endian_dword(0x24 + dataPayloadSize) + "WAVE";
output += "fmt " + to_little_endian_dword(0x10) + to_little_endian_word(0x1) + to_little_endian_word(this.NumChannels) + to_little_endian_dword(this.SampleRate) + to_little_endian_dword(this.SampleRate * samplePayloadSize) + to_little_endian_word(samplePayloadSize) + to_little_endian_word(this.BitsPerSample);
output += "data" + to_little_endian_dword(dataPayloadSize);
var index = 0;
var length = this.samples.length;
if (this.BitsPerSample == 8) { //Put this outside the loop for TraceMonkey.
while (index < length) {
output += to_byte(this.samples[index++]);
}
}
else {
while (index < length) {
output += to_little_endian_word(this.samples[index++]);
}
}
return output;
};
this.checkSanity = function (sampleData, isRelative) {
//WAV PCM Data Sanity Check
if (this.buildable && sampleData.length == this.NumChannels) {
for (channel in sampleData) {
var dataUnit = (isRelative) ? this.convertRelativeUnits(sampleData[channel]) : sampleData[channel];
switch (this.BitsPerSample) {
case 0x8:
if (dataUnit < 0 || dataUnit > 0xFF) {
return false;
}
break;
case 0x10:
if (dataUnit < -0x8000 || dataUnit > 0x7FFF) {
return false;
}
}
}
return true;
}
return false;
};
this.convertRelativeUnits = function (sampleData) {
//Map relative audio values to WAV PCM values.
后面还有 56 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。