Socket
Socket
Sign inDemoInstall

ysd-media-processor

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.4 to 1.2.0

encoders/BufferToWaveEncoder.js

39

controllers/VolumeBox.js

@@ -37,10 +37,8 @@ export default class VolumeBox {

}
};
}
scheduleFadeOut(source) {
if (this.fadeOutEnabled) {
setTimeout(() => {
source.gain.setValueAtTime(1, this.context.currentTime);
source.gain.linearRampToValueAtTime(0, this.context.currentTime + this.fadeOutDuration);
}, this.fadeOutStartTime * 1000);
source.gain.setValueAtTime(1, this.context.currentTime + this.fadeOutStartTime);
source.gain.linearRampToValueAtTime(0, this.context.currentTime + this.fadeOutStartTime + this.fadeOutDuration);
}

@@ -54,3 +52,3 @@ }

}
};
}

@@ -62,3 +60,3 @@ toggleFadeIn() {

this.fadeInEnabled = !this.fadeInEnabled;
};
}

@@ -70,3 +68,3 @@ toggleFadeOut() {

this.fadeOutEnabled = !this.fadeOutEnabled;
};
}

@@ -78,7 +76,7 @@ toggleCut() {

this.cutEnabled = !this.cutEnabled;
};
}
getFadeInDuration() {
return this.fadeInDuration;
};
}

@@ -90,7 +88,7 @@ setFadeInDuration(sec) {

this.fadeInDuration = sec;
};
}
getFadeOutStartTime() {
return this.fadeOutStartTime;
};
}

@@ -102,7 +100,7 @@ setFadeOutStartTime(sec) {

this.fadeOutStartTime = sec;
};
}
getFadeOutDuration() {
return this.fadeOutDuration;
};
}

@@ -114,7 +112,7 @@ setFadeOutDuration(sec) {

this.fadeOutDuration = sec;
};
}
getCutStartTime() {
return this.cutStartTime;
};
}

@@ -126,7 +124,7 @@ setCutStartTime(sec) {

this.cutStartTime = sec;
};
}
getCutEndTime() {
return this.cutEndTime;
};
}

@@ -138,5 +136,4 @@ setCutEndTime(sec) {

this.cutEndTime = sec;
};
}
};
}

@@ -24,2 +24,3 @@ import EffectBox from './_EffectBox.js';

this.context.decodeAudioData(ab, (irBuffer) => this.convolverNode.buffer = irBuffer);
this.reverbType = type;
};

@@ -32,4 +33,3 @@

// setting
this.reverbType = 'room';
this._setReverbType(this.reverbType);
this._setReverbType('room');

@@ -48,7 +48,7 @@ // wiring

setReverbType(type) {
async setReverbType(type) {
if (!this.getReverbTypes().includes(type)) {
throw 'No shch types.';
}
this._setReverbType(type);
await this._setReverbType(type);
}

@@ -55,0 +55,0 @@

{
"name": "ysd-media-processor",
"version": "1.1.4",
"version": "1.2.0",
"description": "Supports processing of audio files using web audio api.",

@@ -5,0 +5,0 @@ "main": "YsdMediaProcessor.js",

@@ -6,2 +6,4 @@ import VolumeBox from './controllers/VolumeBox.js';

import BufferToWaveEncoder from './encoders/BufferToWaveEncoder.js';
export default class YsdMediaProcessor {

@@ -13,3 +15,3 @@

} catch (e) {
alert('Web Audio API is not supported in this browser.');
throw 'Web Audio API is not supported in this browser.';
}

@@ -21,2 +23,3 @@ this.context = new AudioContext();

this.originalFileName = 'no-name.';
this.started = false;

@@ -52,3 +55,6 @@ this.playTime = 0;

var fileReader = new FileReader();
fileReader.onload = () => this.setArrayBuffer(fileReader.result).then(resolve);
fileReader.onload = () => this.setArrayBuffer(fileReader.result).then(() => {
this.originalFileName = file.name;
resolve();
});
fileReader.readAsArrayBuffer(file);

@@ -222,2 +228,80 @@ });

export() {
return new Promise((resolve, reject) => {
try {
window.OfflineAudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;
} catch (e) {
throw 'OfflineAudioContext is not supported in this browser.';
}
const audioBuffer = this.audioBuffer;
if (!audioBuffer) {
console.error('Audio has not set yet.');
reject();
}
const sampleRate = audioBuffer.sampleRate;
const context = new OfflineAudioContext(audioBuffer.numberOfChannels, audioBuffer.duration * sampleRate, sampleRate);
const source = context.createBufferSource();
source.buffer = audioBuffer;
const masterNode = context.createGain();
const integrateNode = context.createGain();
const volumeBox = new VolumeBox(context, () => false);
if (this.volumeBox.isOnFadeIn()) {
volumeBox.setFadeInDuration(this.volumeBox.getFadeInDuration());
volumeBox.toggleFadeIn();
}
if (this.volumeBox.isOnFadeOut()) {
volumeBox.setFadeOutStartTime(this.volumeBox.getFadeOutStartTime());
volumeBox.setFadeOutDuration(this.volumeBox.getFadeOutDuration());
volumeBox.toggleFadeOut();
}
if (this.volumeBox.isOnCut()) {
volumeBox.setCutStartTime(this.volumeBox.getCutStartTime());
volumeBox.setCutEndTime(this.volumeBox.getCutEndTime());
volumeBox.toggleCut();
}
volumeBox.scheduleFadeIn(masterNode);
volumeBox.scheduleFadeOut(masterNode);
volumeBox.scheduleCut(masterNode);
if (this.delayBox.isOn()) {
const delayBox = new DelayBox(context);
delayBox.setDelayTime(this.delayBox.getDelayTime());
delayBox.setFeedback(this.delayBox.getFeedback());
delayBox.toggle(masterNode, integrateNode);
}
if (this.convolverReverbBox.isOn()) {
const convolverReverbBox = new ConvolverReverbBox(context);
convolverReverbBox.setReverbType(this.convolverReverbBox.getReverbType());
convolverReverbBox.setOutputGain(this.convolverReverbBox.getOutputGain());
convolverReverbBox.toggle(masterNode, integrateNode);
}
if (this.schroederReverbBox.isOn()) {
const schroederReverbBox = new SchroederReverbBox(context);
schroederReverbBox.setOutputGain(this.schroederReverbBox.getOutputGain());
schroederReverbBox.toggle(masterNode, integrateNode);
}
source.connect(masterNode).connect(integrateNode).connect(context.destination);
const renderStartTime = new Date().getTime();
setTimeout(() => {
source.start();
context.startRendering();
context.oncomplete = (e) => {
const renderedBuffer = e.renderedBuffer;
const anchor = document.createElement('a');
anchor.href = URL.createObjectURL(BufferToWaveEncoder.encode(renderedBuffer));
anchor.download = this.originalFileName.slice(0, this.originalFileName.lastIndexOf('.')) + '.mixed.wav';
anchor.click();
console.log('AudioRenderingTime: ' + (new Date().getTime() - renderStartTime) + '[ms]');
resolve();
};
}, 100);
});
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc