Closed Bug 922247 Opened 6 years ago Closed 6 years ago

When encoding to Opus, resample the input to 48kHz if its sample rate is not suitable

Categories

(Core :: Audio/Video, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla27

People

(Reporter: padenot, Assigned: padenot)

References

Details

Attachments

(1 file)

After bug 918861, an AudioContext can have a sample rate different than 48000Hz.

Opus only accepts input sample rate of 48000Hz, or that divide 48000 evenly. Because having a sample rate of 44100Hz on the AudioContext will be pretty common, we need to support resampling the input properly.
Comment on attachment 815374 [details] [diff] [review]
When an AudioContext is not running at 48kHz, resample the input of the MediaRecorder when encoding in Opus. r=

Review of attachment 815374 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/media/encoder/OpusTrackEncoder.cpp
@@ +147,5 @@
>  
>    // The granule position is required to be incremented at a rate of 48KHz, and
>    // it is simply calculated as |granulepos = samples * (48000/source_rate)|,
>    // that is, the source sampling rate must divide 48000 evenly.
> +  // If this constraint is not satified, we resample the input to 48kHz.

"satisfied"

::: content/media/encoder/OpusTrackEncoder.h
@@ +7,5 @@
>  #define OpusTrackEncoder_h_
>  
> +#define OUTSIDE_SPEEX
> +#define RANDOM_PREFIX speex
> +#include "speex/speex_resampler.h"

I think we should create a SpeexResampler.h #include file which defines these, and #include it everywhere in Gecko that uses Speex.

We might even want to wrap it in a C++ class that automatically calls speex_resampler_destroy.

Although, I don't even know why you're #defining OUTSIDE_SPEEX here when we don't do that anywhere else that uses Speex resampling.

@@ +38,5 @@
>      DATA
>    } mEncoderState;
>  
>    /**
> +   * Get the samplerate of the data to be fed to the opus encoder. This might be

Opus
Attachment #815374 - Flags: review?(roc) → review+
https://hg.mozilla.org/mozilla-central/rev/6ca71aca6e9e
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
You need to log in before you can comment on or make changes to this bug.