Rantanen / node-mumble

Mumble client in Node.js
MIT License
155 stars 48 forks source link

Audio is garbled #44

Closed justinmchase closed 9 years ago

justinmchase commented 9 years ago

I'm having trouble sending audio. When I am listening and someone else is send me audio everything is fine. When I send audio however it sounds garbled to listeners.

For now I am just using the loopback.js example so I can send and receive audio myself. I've tried the demo on both windows and linux so far and both are having the same issue. I'm now wondering if the issue is now a server configuration issue?

When I connect the real mumble client to my server I get this message:

Server maximum network bandwidth is only 12 kbit/s. Audio quality auto-adjusted to 8 kbit/s (40 ms)

I'm wondering if node-mumble is simply trying to send too high of bandwidth streams to the server and thus having problems. I tried setting the sampleRate on the input options but it didn't seem to have an effect. I tried to patch node mumble to use a default of 8000 instead of 48000 for the SAMPLING_RATE but it gives me this: warning: Sampling rate must be between 32 kHz and 96 kHz

So i have two questions:

justinmchase commented 9 years ago

Upping the quality on my server fixed the issue completely. I would still to know how to lower the quality here and then possibly create a PR to dynamically downgrade based on the server options like the official mumble client does. We will have a variety of users with various quality computers, supporting lower quality streams coudl be very useful.

Rantanen commented 9 years ago

Sample rate is quite a bit different when it comes to compressed audio. Even 8kHz sample rate with 16 bit samples would equal 128kbit/s bitrate uncompressed - and given opus/celt use fixed bitrate that wouldn't reduce the bandwith at all.

MumbleConnection should have setBitrate exposed which . One of the Mumble server messages contains the capped bitrate.

The server's max bitrate is part of the ServerConfig message. Should be a simple case of calling the this.setBitrate in MumbleConnection when receiving new ServerConfig.

I'd do this, but I don't have a low bitrate murmur server currently. If you got one, you could make the change and confirm it fixes the issue?

justinmchase commented 9 years ago

Cool, I will give it a shot and let you know. Thanks.

Rantanen commented 9 years ago

Reopening. Waiting for confirmation.

justinmchase commented 9 years ago

We reconfigured our server up to 48000 to resolve this but I will lower it again and test this soon. Thanks again.

justinmchase commented 9 years ago

Also I have a related question for you. We upped the quality on the server and now audio is going through it fine, except that the sent voice sounds high pitched, chipmunk-like. The incoming audio sounds fine however.

I think that the browsers getUserMedia api is grabbing mic data at a sample rate of 44.1khz. I'm thinking what I need to do is to up-sample to 48khz, then let node-mumble do the rest. Does that sound right?

I'm looking at this for example: http://stackoverflow.com/questions/27411835/web-audio-api-downsample-44-1-khz-in-javascript

Rantanen commented 9 years ago

The input stream constructor should take in options that allow specifying sample rate or something...

I know I wrote code to quickly resample audio somewhere.

Prior99 commented 9 years ago

Maybe take a look at: https://github.com/Prior99/node-samplerate It seems to be pretty stable since many weeks.

justinmchase commented 9 years ago

:+1:

justinmchase commented 9 years ago

@Prior99 I'm noticing that libsamplerate is GPL licensed... that could be a problem. I'm happy to use your node-samplerate addon as is but I'm not sure if consuming it would force my electron application to also become GPL licensed? We're looking into it.

Rantanen commented 9 years ago

As I mentioned earlier, the MumbleInputStream constructor accepts the expected sample rate as an option. These options can be passed in when calling inputStream().

The actual resampling implementation is quite naive but it should do the trick unless you really require high fidelity audio.

The options are somewhat documented in the Wiki as well, although the connection between inputStream() parameters and MumbleInputStream constructor options isn't really spelled out.

justinmchase commented 9 years ago

Yeah, I'm going to use that. Thanks @Rantanen

Prior99 commented 9 years ago

@justinmchase yes, that is a problem. It uses libsamplerate which is gpl licensed so there is no way to change it :/

Rantanen commented 9 years ago

I'll close this and reopen a new one for improving the bitrate limiting logic.

justinmchase commented 9 years ago

Actually, sorry for not following up but using the inputStream trick like you suggested worked for me. I ended up going with the openal approach, which lets me just set it right to 48000, but when I was in the browser it was necessary to set it to 41000.