Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preamp or loudness #37

Closed
proyb6 opened this issue Jan 10, 2017 · 9 comments
Closed

Preamp or loudness #37

proyb6 opened this issue Jan 10, 2017 · 9 comments
Assignees

Comments

@proyb6
Copy link

proyb6 commented Jan 10, 2017

Some audio source or wave may sound tinny, are there any way to increase loudness or preamp that found in music players? Would be great for improve music quality

@alemangui
Copy link
Owner

Pizzicato is limited in the volume output of the Sound objects, but there is a workaround:

  1. Create a detached Sound object (details here)

This sound object will not be automatically connected to the destination, which means you can connect it manually.

  1. Connect the sound to a gainNode, and then the gain node to the destination:
gain = Pz.context.createGain();
sound.connect(gain);
gain.connect(Pz.context.destination);

You will then be able to raise the gain as much as you want. The gain node is basically a multiplier, so you can try any values to see which one fits, like:

gain.gain.value = 1.5

@proyb6
Copy link
Author

proyb6 commented Jan 11, 2017

Do you mean createAnalyser instead of createAnaliser?

Not sure if the code is correct, I still hear the volume at the same level as 100% normal volume.

var analyser = Pizzicato.context.createAnalyser();
var a = new Pizzicato.Sound('./1.flac', function() {
    options: { 
        detached: true 
    }
});
a.attack = 0;
a.release = .8;
a.connect(analyser)

gain = Pz.context.createGain();
a.connect(gain);
gain.connect(Pz.context.destination);
gain.gain.value = 2

@alemangui
Copy link
Owner

No need for the analyser (but thanks for pointing out the typo :) )

var a = new Pizzicato.Sound('./1.flac', function() {
    options: { detached: true }
});
a.attack = 0;
a.release = .8;

gain = Pz.context.createGain();
a.connect(gain);
gain.connect(Pz.context.destination);

gain.gain.value = 2

@proyb6
Copy link
Author

proyb6 commented Jan 11, 2017

There is one issue if adding convolver to var a, will cause all gains to be increase to 2. Without convolver, I can hear the difference gain between each keys.

<script src="./Pizzicato.min.js"></script>
<p onmousedown="d()" onmouseup="u()">A key</p>
<p onmousedown="d2()" onmouseup="u2()">B key</p>
<p onmousedown="d3()" onmouseup="u3()">C key</p>

var a = new Pizzicato.Sound('./1.flac', function() {
    options: { detached: true }
});
a.attack = 0;
a.release = .8;

var a2 = new Pizzicato.Sound('./2.flac', function() {});
a2.attack = 0;
a2.release = .8;

var a3 = new Pizzicato.Sound('./3.flac', function() {});
a3.attack = 0;
a3.release = .8;

var convolver = new Pizzicato.Effects.Convolver({
    impulse: './c.wav',
    mix: 0.4
}, function() {
    console.log('Convolver ready to be used.');
});

a2.addEffect(convolver);
a3.addEffect(convolver);

gain = Pz.context.createGain();
a.connect(gain);
gain.connect(Pz.context.destination);

gain.gain.value = 2

//This code still overriding the gain, to appear the same volume as non-detached sound. I tried to 
//move the code before ```gain = Pz.context.createGain();```, is still being override.
a.addEffect(convolver);

function d() {
a.play();
}
function d2() {
a2.play();
}
function d3() {
a3.play();
}

function u() {a.stop();}
function u2() {a2.stop();}
function u3() {a3.stop();}

@proyb6
Copy link
Author

proyb6 commented Jan 12, 2017

Is this the expected behaviour or a bug?

@alemangui
Copy link
Owner

It's not expected behavior, sounds like a bug. I will take a look.

@alemangui alemangui reopened this Jan 12, 2017
@alemangui alemangui added the bug label Jan 14, 2017
@alemangui
Copy link
Owner

Definitely a bug. When adding a single effect to multiple sounds, the output of the effect remains connected only to the last sound added.

@alemangui
Copy link
Owner

I have created issue #40 for following this problem - given that this one talks mainly about preamp.

@alemangui
Copy link
Owner

@proyb6 There might be a workaround by creating your own audio graph.

To do so, instead of adding effects using addEffect you can try to:

1- Create only detached Pz.Sound objects (all of them).
2- Create the preamp gain and connect it to the desired sound as before. At this moment you should have something like:

[s1]-[gain(2)]
[s2]
[s3]

3- Create a gain to unite all sounds and connect it to your desired effect.

[s1]-[gain(2)]--|
[s2]-----------|--[gain]--[convolver]
[s3]-----------|

4- Connect the convolver to the destination

[s1]-[gain(2)]--|
[s2]-----------|--[gain]--[convolver]--[destination]
[s3]-----------|

An example of this is done here: https://jsfiddle.net/udzutzLj/2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants