ScarletsFiction / SFMediaStream

HTML5 media streamer library for playing music, video, playlist, or even live streaming microphone & camera with node server
MIT License
101 stars 30 forks source link

pitchShift connect to ScarletsMediaPresenter #11

Closed krolig closed 4 years ago

krolig commented 4 years ago

Hi! How to connect pitchShift effect to ScarletsMediaPresenter?

StefansArya commented 4 years ago

To reduce bandwidth and CPU usage, you shouldn't add effect from the presenter. But add it on the streamer.
Just like the PingPongDelay on the music player's example.

https://github.com/ScarletsFiction/SFMediaStream/blob/661b26f22dacfc727d4e2017caebc53f370c24ed/example/music-player/index.html#L45-L50

var streamer = new ScarletsAudioStreamer();
var pitchShift = ScarletsMediaEffect.pitchShift(); 

streamer.connect(pitchShift.input);
pitchShift.output.connect(ScarletsMedia.audioContext.destination);

If you want to combine effect, you can connect the output to another effect's input.

pitchShift.output.connect(ppDelay.input)

Then don't forget to connect it to the speaker/destination.

ppDelay.output.connect(ScarletsMedia.audioContext.destination)
krolig commented 4 years ago

Thank you for your answer.

I would like to enable users of the voice chat could change your (self) voice. Not everyone wants to hear their real voices.

I need to change it for the microphone, and not the receptor.

StefansArya commented 4 years ago

I see.. Below haven't been compiled to distributable js, but could you try it from there? (As I can't test it right now)

https://github.com/ScarletsFiction/SFMediaStream/blob/821591427f6abf29433bde0abb44246b35e9802f/src/MediaPresenter.js#L118-L124

You can change the scope with your presenter's variable and add the effect just like the streamer from my last comment.

krolig commented 4 years ago

I see.. Below haven't been compiled to distributable js, but could you try it from there? (As I can't test it right now)

https://github.com/ScarletsFiction/SFMediaStream/blob/821591427f6abf29433bde0abb44246b35e9802f/src/MediaPresenter.js#L118-L124

You can change the scope with your presenter's variable and add the effect just like the streamer from my last comment.

It works on himself, but not sent to the server.

StefansArya commented 4 years ago

Hmm, maybe you connect the effect directly into the speaker. But because of that I realized if it's possible.

I just updated the library and the example, and you can use presenter.destination instead of ScarletsMedia.audioContext.destination.

krolig commented 4 years ago

Yes, now the effect pitchShift is sent to the server, but along with it is sent the raw sound of the voice. Can I somehow disable it?

StefansArya commented 4 years ago

Maybe the presenter still have connection to it's own destination. Can you disconnect it first?

presenter.disconnect(presenter.destination)
krolig commented 4 years ago

Thank you so much!

presenter.disconnect(presenter.destination) - exactly what was needed.

Now everything works as I wanted.

StefansArya commented 4 years ago

Sure, good luck with your project