pcm samples by channel

pull/14/head
Samir 7 years ago
parent 14254cc819
commit 556104a3e8

@ -12,10 +12,10 @@
window.onload = function() {
var socketURL = 'ws://localhost:8080';
var player = new PCMPlayer({
encoding: '16bitInt',
encoding: '32bitFloat',
channels: 2,
sampleRate: 8000,
flushingTime: 1000
flushingTime: 2000
});
var ws = new WebSocket(socketURL);

@ -1,7 +1,7 @@
const WebSocket = require('ws');
const fs = require('fs');
const pcm_file = './16bit-8000.raw';
const pcm_file = './32bit (float)-8000.raw';
let interval = 0,
sampleRate = 8000,
channels = 2,

@ -86,17 +86,18 @@ PCMPlayer.prototype.destroy = function() {
PCMPlayer.prototype.flush = function() {
if (!this.samples.length) return;
var bufferSource = this.audioCtx.createBufferSource(),
length = this.samples.length,
length = this.samples.length / this.option.channels,
audioBuffer = this.audioCtx.createBuffer(this.option.channels, length, this.option.sampleRate),
audioData,
channel,
offset,
i,
decrement = 50;
decrement;
for (channel = 0; channel < this.option.channels; channel++) {
audioData = audioBuffer.getChannelData(channel);
offset = channel;
decrement = 50;
for (i = 0; i < length; i++) {
audioData[i] = this.samples[offset];
/* fadein */
@ -114,7 +115,7 @@ PCMPlayer.prototype.flush = function() {
if (this.startTime < this.audioCtx.currentTime) {
this.startTime = this.audioCtx.currentTime;
}
console.log('start vs current '+this.startTime+' vs '+this.audioCtx.currentTime);
console.log('start vs current '+this.startTime+' vs '+this.audioCtx.currentTime+' duration: '+audioBuffer.duration);
bufferSource.buffer = audioBuffer;
bufferSource.connect(this.gainNode);
bufferSource.start(this.startTime);

Loading…
Cancel
Save