Rantanen / node-mumble

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

Streaming MP3 #32

Closed johnrnelson closed 9 years ago

johnrnelson commented 9 years ago

Using lame npm assume the rough sudo code...

var lame = require('lame');
var decoder = new lame.Decoder();
decoder.pipe(connection.inputStream());

I hear the mp3 audio but it's very distorted. I checked the "lame" npm with "speaker" npm and can hear it just fine there so I am wondering if there is something special needed to fix the stream? Perhaps a connection option that I missing?

Prior99 commented 9 years ago

This could be due to wrong samplerate, maybe lame is outputting 44100KHz but you need 48000Khz.

You need to sample up or down your stream, there currently is no real stable library to do this, but you can use my wrapper for libsamplerate.

johnrnelson commented 9 years ago

Is it fair to say that if the sample rate was wrong then it should be distorted on my speakers? This is my first real step in steaming so my ignorance might be the issue as well. :-)

Prior99 commented 9 years ago

Yes, for example:

Check how much channels you have and which samplerate your audio is.

I am no audio engineerer or physicist but this is what I figured out from my projects.

johnrnelson commented 9 years ago

Yes I see. That makes sense. Per your suggestions, I tried changing a few settings on the decoder and think I have made progress.

Would adding to the project (manifest/json) the lame npm (or some other alternative) be out of the question? Working with mp3 files would certainly add to the overall value.

I'm having a ball working with this code.

Prior99 commented 9 years ago

I do not think this is needed, I would keep this in a seperate project.

Rantanen commented 9 years ago

I'm against adding lame as a dependency to node-mumble as well but we should certainly make sure it is easy to inter-operate the two libraries.

johnrnelson commented 9 years ago

Perhaps adding to the examples folder a sample of playing a mp3 file to the current channel then?

As far as the issue is concerned; it looks closed. You have clearly shown me where the problem is and I do appreciate the schooling. :-)

Prior99 commented 9 years ago

@johnrnelson That sounds good :) I am not concerned about using node-samplerate though, it did not prove to be stable.

Rantanen commented 9 years ago

Improved the MumbleInputStreams to do resampling etc.

See: https://github.com/Rantanen/node-mumble/blob/master/examples/mp3.js

The resampling especially is very dirty sample duplication. Not the best quality but fast and it works.

Rantanen commented 9 years ago

@Prior99 If node-samplerate is stable, feel free to replace the resampling in lib/util.js#resample with your implementation.

johnrnelson commented 9 years ago

@Rantanen Thanks for the new addition. Is the stdin on line 38 stream = process.stdin.pipe( decoder );

where you would read the file path for the mp3 file as in input = fs.createReadStream(FilePath); input.pipe(decoder)

Again, thanks for the code! :-)

Rantanen commented 9 years ago

Yeah. You can do that. Or just pipe it into the process with: node mp3 < file.mp3

johnrnelson commented 9 years ago

I still get that same distortion. Seems to be at 1/4th the speed it should be. I'll try to pipe it but I'm afraid that will be just a band-aid as the overall solution will have multiple files that will, no doubtfully, come from fs.

Rantanen commented 9 years ago

Any chance you could share the mp3 file? I'm curious what it contains.

johnrnelson commented 9 years ago

Sure. What is the best method? I've tried both music and audio books.

I've already forked the project but does not sound like the best method to share files. :-)

Rantanen commented 9 years ago

If the files you've used for testing are publicly available somewhere you could just link to them. If they aren't, you can always mail it with jubjub a jubjubnest net

Prior99 commented 9 years ago

@Rantanen I mainly want it to be a stream but I do not know about streams in node and currently do not have the time available working on it.

I am also not sure whether it supports any other platform than linux.

Also libsamplerate is GPL licensed so my wrapper had to be GPL also and is incompatible with our MIT license.

Rantanen commented 9 years ago

Ah, okay. Streaming on that level would be difficult as well as currently the processing is taking part on the frame-packet level where we only have 10ms buffer segments instead of streams.

Let's leave the quick solution in for now then. We can always implement proper resampling in JavaScript later. Also given we got lossy celt opus codec there, I'm not sure if the resampling artifacts are that noticeable.

Prior99 commented 9 years ago

okay

johnrnelson commented 9 years ago

Perhaps open an issue for streaming if not now then for a later time?

I've put some files in my fork but network issues and smartgit are preventing me from pushing. Should be good by Monday though.

BTW: http://mumble-protocol.readthedocs.org/en/latest/voice_data.html#codecs was a good read for me.