sdrtrunk icon indicating copy to clipboard operation
sdrtrunk copied to clipboard

Actual sample rate is inconsistent with config

Open doug-hoffman opened this issue 3 years ago • 3 comments

Setting the sample rate above 16kHz results in a sample rate of 16kHz:

BCFY Calls:

$ file 1651891145-20071.mp3 
1651891145-20071.mp3: Audio file with ID3 version 2.4.0, contains:MPEG ADTS, layer III, v2,  16 kbps, 16 kHz, Monaural

Icecast:

$ mpv <url>
 (+) Audio --aid=1 (mp3 1ch 16000Hz)
File tags:
 icy-title: Scanning...
AO: [coreaudio] 16000Hz mono 1ch floatp
A: 00:00:01 / 00:00:07 (19%) Cache: 6.0s/95KB

doug-hoffman avatar May 07 '22 02:05 doug-hoffman

I've now seen the sample rate change between restarts without changing the configuration. It has been 22.05kHz occasionally, including right now after setting to 44.1kHz and restarting.

doug-hoffman avatar May 07 '22 17:05 doug-hoffman

Adding debug:

    public MP3AudioConverter(InputAudioFormat inputAudioFormat, MP3Setting setting, boolean normalizeAudio)
    {
        mInputAudioFormat = inputAudioFormat;
        mEncoder = LameFactory.getLameEncoder(inputAudioFormat, setting);
        mNormalizeAudio = normalizeAudio;

        mLog.debug("Audio format:" + mInputAudioFormat);
        mLog.debug("Effective sample rate:" + mEncoder.getEffectiveSampleRate());

Confirms LAME sample rate differs:

15:32:07.138 DEBUG i.g.d.a.c.MP3AudioConverter - Audio format:16-Bit 22050 Hz (default)  [41MB/80MB 52%]
15:32:07.138 DEBUG i.g.d.a.c.MP3AudioConverter - Effective sample rate:16000  [41MB/80MB 52%]

doug-hoffman avatar May 07 '22 19:05 doug-hoffman

I'm not seeing a clear way to fix this while using the LameEncoder class. We need to be able to call mEncoder.lame.getFlags().setOutSampleRate(), which isn't accessible, to prevent it from resampling. Warning seems like the best immediate path forward.

doug-hoffman avatar May 20 '22 00:05 doug-hoffman