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

Reply
 
Thread Tools Display Modes
Old 10-16-2019, 08:32 PM   #1
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,964
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):

Code:
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
samples.clear(garbage)

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

errors = {}

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

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

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

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 02:32 PM.


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