Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Thread Tools Display Modes
Old 10-16-2019, 08:32 PM   #1
Human being with feelings
cfillion's Avatar
Join Date: May 2015
Location: Québec, Canada
Posts: 2,838
Default GetAudioAccessorSamples stops before the end of video files

GetAudioAccessorSamples stops writing to the given sample buffer before reaching the end of the file when reading video sources (tested using VLC and ffmpeg decoders with mp4(AAC-LC) and wma files). It returns 1 even if it did not write as many samples as requested.

SWS and scripts usually expect floor(itemLength * sampleRate) samples to be available in total. Because the current version of SWS does not initialize its sample buffer (fixing that), this leads to potentially grossly invalid Loudness measurements (as reported in issue #1210).

Here's a simple script (no windowing and mono only) that demonstrates the issue (test media files here):

item         = reaper.GetSelectedMediaItem(0, 0)
take         = reaper.GetActiveTake(item)
source       = reaper.GetMediaItemTake_Source(take)
channels     = reaper.GetMediaSourceNumChannels(source)
sampleRate   = reaper.GetMediaSourceSampleRate(source)
accessor     = reaper.CreateTakeAudioAccessor(take)
audioStart   = reaper.GetAudioAccessorStartTime(accessor)
audioEnd     = reaper.GetAudioAccessorEndTime(accessor)
audioLength  = audioEnd - audioStart
sampleCount  = math.floor(audioLength * sampleRate)
bufferSize   = sampleCount * channels
samples      = reaper.new_array(bufferSize)
garbage      = 0xcdcdcdcd

retval = reaper.GetAudioAccessorSamples(accessor, sampleRate, channels, 0, sampleCount, samples)

errors = {}

for i = 1, bufferSize do
  if samples[i] == garbage then
    table.insert(errors, i)

if #errors == 0 then
  reaper.ShowConsoleMsg('Buffer is valid.\n')
  reaper.ShowConsoleMsg(string.format('GetAudioAccessorSamples stopped writing at sample %d (inclusive)! (%d invalid samples)\n', errors[1], #errors))
With "6khz sinewave.mp4" selected, it outputs:
GetAudioAccessorSamples stopped writing at sample 47105 (inclusive)! (1952 invalid samples)

Last edited by cfillion; 10-16-2019 at 08:50 PM.
cfillion is online now   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 06:48 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.