Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function onPlaying(f) {
self.lameFormat = f
var speaker = new Volume()
speaker.pipe(new Speaker(self.lameFormat))
self.speaker = {
'readableStream': this,
'Speaker': speaker,
}
self.emit('playing', song)
self.history.push(index)
// This is where the song acturaly played end,
// can't trigger playend event here cause
// unpipe will fire this speaker's close event.
this.pipe(speaker)
.once('close', () =>
self.emit('playend', song))
}
this._node = new stream.Readable();
this._node._read = (n) => {
let streamL = this.processor.streams[0];
let streamR = this.processor.streams[1];
let buf = new Buffer(n);
this.processor.process(this.streamSize);
for (let i = 0, imax = this.streamSize; i < imax; i++) {
buf.writeFloatLE(streamL[i], i * 8 + 0);
buf.writeFloatLE(streamR[i], i * 8 + 4);
}
this._node.push(buf);
};
this._node.pipe(new Speaker({
sampleRate: this.sampleRate,
samplesPerFrame: this.streamSize,
channels: 2,
float: true
}));
}
const createSpeaker = callback => {
const speaker = new Speaker({
channels: 1,
bitDepth: 16,
sampleRate: 17650
})
speaker.on('open', () => {
logger.info('Speaker opened')
})
speaker.on('close', () => {
logger.info('Speaker closed')
callback()
})
return speaker
}
pause() {
if (this.paused) {
this.speaker.Speaker = new Volume()
this.speaker.Speaker.pipe(new Speaker(this.lameFormat))
this.lameStream.pipe(this.speaker.Speaker)
} else {
this.speaker.Speaker.end()
}
this.paused = !this.paused
return this
}