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

Inconsistent decoded frame count/length #760

Open
MrBrixican opened this issue Oct 29, 2023 · 1 comment
Open

Inconsistent decoded frame count/length #760

MrBrixican opened this issue Oct 29, 2023 · 1 comment

Comments

@MrBrixican
Copy link
Contributor

I noticed the decoded frame count can differ depending on how you go about it.

This pertains to the following methods:

  • ma_sound_init_from_file
  • ma_sound_get_length_in_pcm_frames
  • ma_decode_memory

Here are some specific test cases. They are in the format:

Test file: filename (
original format |
original channels |
original sample rate |
original frame count |
estimated decoded frame count [48000 / original sample rate * original frame count])
Count 1: frame count from ma_decode_memory using sample rate 48000 , format F32, original channels
Count 2: ma_sound_get_length_in_pcm_frames on sound created with ma_sound_init_from_file (no flags)
Count 3: ma_sound_get_length_in_pcm_frames on sound created with ma_sound_init_from_file (MA_SOUND_FLAG_DECODE)

Failed cases

File: short_IMP.mp3 (F32 | 2 ch | 44100 Hz | 3255552 | 3543457.96)
Count 1: 3543458
Count 2: 3543457
Count 3: 3543457

File: A Journey Awaits.flac (F32 | 2 ch | 44100 Hz | 4559262 | 4962462.04)
Count 1: 4962463
Count 2: 4962462
Count 3: 4962462

File: Pistol Shot_08.wav (S16 | 2 ch | 44100 Hz | 53429 | 58154.01)
Count 1: 58155
Count 2: 58154
Count 3: 58154

File: House In a Forest Loop.ogg (F32 | 2 ch | 44100 Hz | 1110210 | 1208391.84)
Count 1: 1208392
Count 2: 1208391
Count 3: 1208392

File: shortcuts.ogg (F32 | 2 ch | 44100 Hz | 12765112 | 13893999.46)
Count 1: 13894000
Count 2: 13893999
Count 3: 13894000

File: THE LAST NIGHT.ogg (F32 | 2 ch | 48000 Hz | 8307915 | 8307915.00)
Count 1: 8307915
Count 2: 8308275
Count 3: 8307915

Passed cases

File: Pistol Shot_06.wav (S16 | 2 ch | 44100 Hz | 66150 | 72000.00)
Count 1: 72000
Count 2: 72000
Count 3: 72000

File: Examples_Audio_Audio_Blip_Select.ogg (F32 | 1 ch | 48000 Hz | 5952 | 5952.00)
Count 1: 5952
Count 2: 5952
Count 3: 5952

Observations

There are three specific categories I can group the failed cases into:

  • extra frame from ma_decode_memory
    • happens when 48000 / original sample rate * original frame count is not a whole number
    • only occurs with wav/mp3/flac
  • extra frame from ma_decode_memory and ma_sound_get_length_in_pcm_frames on sound created with ma_sound_init_from_file (MA_SOUND_FLAG_DECODE)
    • happens when 48000 / original sample rate * original frame count is not a whole number
    • only occurs with ogg
  • many extra frames from ma_sound_get_length_in_pcm_frames on sound created with ma_sound_init_from_file (no flags)
    • can occur even when 48000 / original sample rate * original frame count is a whole number
    • only visible with THE LAST NIGHT.ogg
    • may be a badly generated ogg, was generated from a youtube video downloader

For completeness, the count returned from ma_decode_memory is equivalent to ma_sound_get_length_in_pcm_frames on sound created with ma_sound_init_from_file (no flags) using a path/name registered via ma_resource_manager_register_encoded_data using the data from ma_decode_memory.

These inconsistencies aren't a super major concern given that most of the time it's only off by 1 frame, but I thought it might be good to bring up and document.

Here are the test files:
Frame Count Test Cases.zip

@mackron
Copy link
Owner

mackron commented Oct 31, 2023

Thanks for reporting this and the test cases. I would like this to be consistent between everything so I'll look at this when I get the chance. Obviously a resampling related error. Sounds like maybe that very last frame isn't being output properly for some reason. The "THE LAST NIGHT.ogg" test is an interesting one though and should definitely be investigated.

Will post a message here when I investigate this, but I've been a bit busy lately so no timeframe.

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

No branches or pull requests

2 participants