From 1c175ae0a33217e49265bfa93dc5c18a353099a1 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 12 Sep 2016 21:47:37 -0700 Subject: [PATCH] Create preamp --- js/media.js | 21 ++++++++++----------- js/winamp.js | 13 ++++++++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/js/media.js b/js/media.js index 0ff2a251..702e8964 100644 --- a/js/media.js +++ b/js/media.js @@ -24,6 +24,9 @@ module.exports = { // The _source node has to be recreated each time it's stopped or // paused, so we don't create it here. + // Create the preamp node + this._preamp = this._context.createGain(); + // Create the spliter node this._chanSplit = this._context.createChannelSplitter(2); @@ -64,6 +67,8 @@ module.exports = { // | // destination + this._preamp.connect(this._chanSplit); + // Connect split channels to left / right gains this._chanSplit.connect(this._leftGain, 0); this._chanSplit.connect(this._rightGain, 1); @@ -160,7 +165,7 @@ module.exports = { this._source = this._context.createBufferSource(); this._source.buffer = this._buffer; this._source.connect(this._analyser); - this._source.connect(this._chanSplit); + this._source.connect(this._preamp); this._position = typeof position !== 'undefined' ? position : this._position; this._startTime = this._context.currentTime - this._position; @@ -201,8 +206,10 @@ module.exports = { this._gainNode.gain.value = volume / 100; }, - getVolume: function() { - return this._gainNode.gain.value * 100; + // From 0-1 + setPreamp: function(value) { + console.log('preamp', value); + this._preamp.gain.value = value / 100; }, // From -100 to 100 @@ -231,14 +238,6 @@ module.exports = { this.bands[band].gain.value = db; }, - setPreamp: function() { - // ?? - }, - - getBalance: function() { - return this._balance; - }, - toggleRepeat: function() { this._loop = !this._loop; }, diff --git a/js/winamp.js b/js/winamp.js index 92f1ee68..7e24a999 100755 --- a/js/winamp.js +++ b/js/winamp.js @@ -1,7 +1,13 @@ // UI and App logic import Media from './media'; import MyFile from './myFile'; -import {setSkinFromUrl, setSkinFromFile} from './actionCreators'; +import { + setSkinFromUrl, + setSkinFromFile, + setVolume, + setPreamp, + setBalance +} from './actionCreators'; import '../css/winamp.css'; @@ -12,8 +18,9 @@ module.exports = { this.fileInput.type = 'file'; this.fileInput.style.display = 'none'; - this.dispatch({type: 'SET_VOLUME', volume: options.volume}); - this.dispatch({type: 'SET_BALANCE', balance: options.balance}); + this.dispatch(setVolume(this.media, options.volume)); + this.dispatch(setBalance(this.media, options.balance)); + this.dispatch(setPreamp(this.media, 50)); this.loadFromUrl(options.mediaFile.url, options.mediaFile.name); this.dispatch(setSkinFromUrl(options.skinUrl));