bugGNU Octave - Bugs: bug #60888, Extend audioread() to read files...

 
 

bug #60888: Extend audioread() to read files where header does not specify number of samples

Submitted by:  John Beale <jbeale>
Submitted on:  Tue 06 Jul 2021 04:16:45 PM UTC  
 
Category:  Octave Function Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  None Assigned to:  None
Originator Name:  John Beale Open/Closed:  Open
Release:  dev Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 07 Jul 2021 07:26:50 PM UTC, comment #3: 

I checked in a changeset that improves this somewhat: http://hg.savannah.gnu.org/hgweb/octave/rev/6dc298d3261c.

If the header does not specify the number of samples then audioinfo() now returns -1 for the TotalSamples and Duration fields to indicate that the results are not accurate.

The function audioread() now emits a more specific error message

"audioread: malformed header does not specify number of samples"

when this situation is encountered.

The reason why Octave has a problem with the test file is just as you suspected: the code works by creating an array of the proper size (TotalSamples X #_of_Channels) and then filling it in.  I put a FIXME note in the code that it would be nice to fix this by using an expandable C++ data container and reading the file into memory in chunks.

I've changed this issue report to be a Feature Request for the behavior above.  In the meantime, there are easy workarounds such as using sox to read the file and write a complete header.  For example, this works

sox fftest.flac good.flac

Because there are easy workarounds I've lovered the Priority.

Rik <rik5>
Project Administrator
Tue 06 Jul 2021 04:25:50 PM UTC, comment #2: 

Looking at the difference in the verbose output from sox between the original .flac from ffmpeg and the re-converted one from sox, I am guessing that the ffmpeg-generated .flac does not contain the duration and/or sample number in the file header. Apparently the other tools can handle that omission, and simply read until EOF to find out how many samples there are, while Octave expects to pre-allocate memory for the file. So this may be an unavoidable consequence of expecting the entire file to be memory-resident for later calculations, whereas the other programs may not require that.

John Beale <jbeale>
Tue 06 Jul 2021 04:20:06 PM UTC, comment #1: 

I didn't include the relevant part from sox, here's what it said on the original file:

ubuntu@ubuntu:~/audio$ sox -V fftest.flac sox.wav
sox:      SoX v14.4.2
sox INFO formats: detected file format type `flac'

Input File     : 'fftest.flac'
Channels       : 1
Sample Rate    : 8000
Precision      : 16-bit
Sample Encoding: 16-bit FLAC
Endian Type    : little
Reverse Nibbles: no
Reverse Bits   : no
Comment        : 'encoder=Lavf58.29.100'

John Beale <jbeale>
Tue 06 Jul 2021 04:16:45 PM UTC, original submission:  

Using a Raspberry Pi 4 with Ubuntu 20.04, a .flac format audio file created by ffmpeg v4.2.4 cannot be read by Octave audioread(). The function audioinfo() shows the duration and sample count is incorrect and extremely large.  'sox' can read and convert this same .flac file without trouble, as can Audacity and VLC. Note that Octave can correctly read a .flac audio file generated by sox created by converting the file to WAV format and then back to FLAC on the same system.  I attach the file in question.

octave:3> info=audioinfo("fftest.flac")
info =

  scalar structure containing the fields:

    Filename = /home/ubuntu/audio/fftest.flac
    CompressionMethod =
    NumChannels =  1
    SampleRate =  8000
    TotalSamples =    9.2234e+18
    Duration =  1152921504606847
    BitsPerSample =  16
    BitRate = -1
    Title =
    Artist =
    Comment =

octave:4> [yraw, fs] = audioread("fftest.flac");
error: out of memory or dimension too large for Octave's index type

ubuntu@ubuntu:~/audio$ sox -V fftest.wav sox.flac
sox:      SoX v14.4.2
sox INFO formats: detected file format type `wav'

Input File     : 'fftest.wav'
Channels       : 1
Sample Rate    : 8000
Precision      : 16-bit
Duration       : 00:00:04.97 = 39744 samples ~ 372.6 CDDA sectors
File Size      : 79.5k
Bit Rate       : 128k
Sample Encoding: 16-bit Signed Integer PCM
Endian Type    : little
Reverse Nibbles: no
Reverse Bits   : no

John Beale <jbeale>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #51653:  fftest.flac added by jbeale (40KiB - audio/flac - Octave cannot read this FLAC format audio file)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jbeale (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-07-07 rik5 Severity3 - Normal => 1 - Wish
        Priority5 - Normal => 3 - Low
        Item GroupUnexpected Error or Warning => Feature Request
        Release5.2.0 => dev
        SummaryCannot read a FLAC from ffmpeg that sox and VLC can => Extend audioread() to read files where header does not specify number of samples
    2021-07-06 jbeale Attached File- => Added fftest.flac, #51653

    Back to the top


    Powered by Savane 3.6