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

Make the output sameplerate match the input #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

darrynten
Copy link

There are 3 arguments that are passed into the Mp3Encoder (channels,
samplerate and kbps).

The input samplerate is generally dependant on AudioContext.sampleRate and
this varies from machine-to-machine.

I was having resampling issues until I make the output samplerate match the
input samplerate. Now everything is OK and I get what I am expecting from my
encoded audio.

A note to others who may read this, ensure that you use the sample rate
provided from AudioContext if you're encoding audio from the users mic in
order to avoid strange resampling issues (different pitch, playback rate etc)

There are 3 arguments that are passed into the `Mp3Encoder` (channels,
samplerate and kbps).

The input samplerate is generally dependant on `AudioContext.sampleRate` and
this varies from machine-to-machine.

I was having resampling issues until I make the output samplerate match the
input samplerate. Now everything is OK and I get what I am expecting from my
encoded audio.

A note to others who may read this, ensure that you use the sample rate
provided from `AudioContext` if you're encoding audio from the users mic in
order to avoid strange resampling issues (different pitch, playback rate etc)
@zhuker
Copy link
Owner

zhuker commented Nov 9, 2015

@darrynten mp3 supports only a handful of output samplerates, there must be some kind of check that output sample rate is one of the supported sample rates
makes sense? am i missing something?

@Kif11
Copy link

Kif11 commented Mar 26, 2018

So, I have similar trouble that prevented me from using this great library.
I need to encode an mp3 file with bitrate 8kbps and sample rate 8000 Hz.
Here is an ffmpeg command that produce the desirable quality:

ffmpeg -i in.mp3 -codec:a libmp3lame -b:a 8k -ar 8000 out.mp3

Modifying worker-realtime.js for mic.html example on line 22 produce the result that sounds like slow motion.

mp3Encoder = new lamejs.Mp3Encoder(1, 44100/2, config.bitRate || 123);

@zhuker can you please merge this pull request?

Nateowami added a commit to sillsdev/web-languageforge that referenced this pull request Feb 28, 2019
Previously the audio sample rate was hard-coded at 44100. This caused
pitch and playback distortions on some machines. This commit bases the
sample rate on the rate provided by the AudioContext supplied by the
browser.

See also: zhuker/lamejs#11
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

Successfully merging this pull request may close these issues.

3 participants