Menu

#1680 Audio time stretcher erases all audio data

None
closed
None
5
2024-06-09
2024-02-04
No

How to reproduce:

  • Load some audio file on an audio track
  • Select the created audio segment
  • Call "Segment -> Stretch or Squash..."
  • Modify the segment length (for example, add or remove one measure)
  • Press OK

Debug messages on stdout show that the audio time stretcher has been called:

AudioTimeStretcher::initialise
AudioTimeStretcher::calculateParameters
AudioTimeStretcher: channels = 1, ratio = 0.982962, n1 = 256, n2 = 252, wlen = 2048, max = 1024
making inbuf size 8298 (outbuf size is 6144, ratio 0.982962)
AudioTimeStretcher::~AudioTimeStretcher
AudioTimeStretcher::~AudioTimeStretcher: actual ratio = 0.982971, ideal = 0.982962, nominal = 0.984375)
AudioTimeStretcher::cleanup

The segment length is successfully modified, but there is no more audio in the segment, only a flat line.

Discussion

  • Philip Leishman

    Philip Leishman - 2024-02-26

    I cannot reproduce this. If I try the steps above the audio is slower or faster appropriately !
    Which Rosegarden version are you using ?
    Do you have any preferences which are not default ?
    Anything special about the audio ?

     
  • Yves Guillemot

    Yves Guillemot - 2024-02-27

    I tried with 23.12, the last git and another about two or three years old version (I currently don't remember).
    I tried again with 23.12 and all preferences set to default, but it changes nothing.
    The audio files are ordinary wave files.
    Here are the descriptions of two short files before and after the stretch. The files have been recorded with RG itself.

    Test 1 - Record audio files set in preferences as: 16 bits PCM WAV format

    Before stretch:
    ---------------
    
    $ sndfile-info 'rg-[testaudio.rg]-[Audio_#1]-2024-02-27_22.03.57-16.wav'
    ========================================
    File : rg-[testaudio.rg]-[Audio_#1]-2024-02-27_22.03.57-16.wav
    Length : 2331180
    RIFF : 2331172
    WAVE
    fmt  : 16
      Format        : 0x1 => WAVE_FORMAT_PCM
      Channels      : 2
      Sample Rate   : 48000
      Block Align   : 4
      Bit Width     : 16
      Bytes/sec     : 192000
    data : 2331136
    End
    
    ----------------------------------------
    Sample Rate : 48000
    Frames      : 582784
    Channels    : 2
    Format      : 0x00010002
    Sections    : 1
    Seekable    : TRUE
    Duration    : 00:00:12.141
    Signal Max  : 9766 (-10.51 dB)
    
    $
    
    
    
    
    After stretch:
    --------------
    
    $ sndfile-info 'stretch-[testaudio.rg]--20240227-220505-17.wav'
    ========================================
    File : stretch-[testaudio.rg]--20240227-220505-17.wav
    Length : 3505044
    RIFF : 3505036
    WAVE
    fmt  : 16
      Format        : 0x3 => WAVE_FORMAT_IEEE_FLOAT
      Channels      : 2
      Sample Rate   : 48000
      Block Align   : 8
      Bit Width     : 32
      Bytes/sec     : 384000
    data : 3505000
    End
    **** All non-PCM format files should have a 'fact' chunk.
    
    ----------------------------------------
    Sample Rate : 48000
    Frames      : 438125
    Channels    : 2
    Format      : 0x00010006
    Sections    : 1
    Seekable    : TRUE
    Duration    : 00:00:09.128
    Signal Max  : 0 (-inf dB)
    
    $
    

    Test2 - Record audio files set in preferences as: 32 bits float WAV format

    Before stretch:
    ---------------
    
    $ sndfile-info 'rg-[testaudio.rg]-[Audio_#1]-2024-02-27_22.25.37-3.wav'
    ========================================
    File : rg-[testaudio.rg]-[Audio_#1]-2024-02-27_22.25.37-3.wav
    Length : 4642860
    RIFF : 4642852
    WAVE
    fmt  : 16
      Format        : 0x3 => WAVE_FORMAT_IEEE_FLOAT
      Channels      : 2
      Sample Rate   : 48000
      Block Align   : 8
      Bit Width     : 32
      Bytes/sec     : 384000
    data : 4642816
    End
    **** All non-PCM format files should have a 'fact' chunk.
    
    ----------------------------------------
    Sample Rate : 48000
    Frames      : 580352
    Channels    : 2
    Format      : 0x00010006
    Sections    : 1
    Seekable    : TRUE
    Duration    : 00:00:12.091
    Signal Max  : 0.292768 (-10.67 dB)
    
    $
    
    
    
    
    After stretch:
    --------------
    
    $ sndfile-info 'stretch-[testaudio.rg]--20240227-222616-4.wav'
    ========================================
    File : stretch-[testaudio.rg]--20240227-222616-4.wav
    Length : 3486124
    RIFF : 3486116
    WAVE
    fmt  : 16
      Format        : 0x3 => WAVE_FORMAT_IEEE_FLOAT
      Channels      : 2
      Sample Rate   : 48000
      Block Align   : 8
      Bit Width     : 32
      Bytes/sec     : 384000
    data : 3486080
    End
    **** All non-PCM format files should have a 'fact' chunk.
    
    ----------------------------------------
    Sample Rate : 48000
    Frames      : 435760
    Channels    : 2
    Format      : 0x00010006
    Sections    : 1
    Seekable    : TRUE
    Duration    : 00:00:09.078
    Signal Max  : 0.0679236 (-23.36 dB)
    
    $
    
     
  • Philip Leishman

    Philip Leishman - 2024-02-28

    This is a bit of a puzzle !!
    Tried lots of things but the re-scaling of the audio always works without problem for me.
    Does anyone else have this problem ?
    I always get an additional output:
    20353 debug/[] - [AudioFileTimeStretcher] getStretchedAudioFile(): success, id is 6
    Here is my output:

    20353 debug/[] - [AudioSegmentRescaleCommand] AudioSegmentRescaleCommand: segment file id 5 , given ratio 0.837563
    20353 debug/[] - [AudioSegmentRescaleCommand] AudioSegmentRescaleCommand: unstretched file id 4 , prev ratio 0.858731 , resulting ratio 0.719242
    20353 debug/[] - [AudioFileTimeStretcher] getStretchedAudioFile(): got source file id 4 , name "/home/philip/.local/share/rosegarden/audio/rg-[audio4.rg]-[Audio_#3]-2024-02-28_15.36.11-5.wav"
    20353 debug/[] - [AudioFileTimeStretcher] getStretchedAudioFile(): got derived file id 6 , name "/home/philip/.local/share/rosegarden/audio/stretch-[audio4.rg]-[Au-20240228-154531-7.wav"
    AudioTimeStretcher::initialise
    AudioTimeStretcher::calculateParameters
    AudioTimeStretcher: channels = 2, ratio = 0.719242, n1 = 512, n2 = 368, wlen = 2048, max = 1024
    making inbuf size 10590 (outbuf size is 6144, ratio 0.719242)
    making inbuf size 10590 (outbuf size is 6144, ratio 0.719242)
    20353 debug/[]
    - [AudioFileTimeStretcher] getStretchedAudioFile(): success, id is 6
    AudioTimeStretcher::~AudioTimeStretcher
    AudioTimeStretcher::~AudioTimeStretcher: actual ratio = 0.721116, ideal = 0.719242, nominal = 0.716797)
    AudioTimeStretcher::cleanup

    I think the getStretchedAudioFile(): success message is important. I can't see why it is not coming in your case.

     
  • Yves Guillemot

    Yves Guillemot - 2024-02-28

    Message was not coming because I didn't run RG in debug mode.

    [AudioSegmentRescaleCommand] AudioSegmentRescaleCommand: segment file id 2 , given ratio 0.945976
    [AudioFileTimeStretcher] getStretchedAudioFile(): got source file id 2 , name "/home/yves/rosegarden/sounds/stretch-conv-Sunny Afte-20240227-232331-3.wav"
    [AudioFileTimeStretcher] getStretchedAudioFile(): got derived file id 3 , name "/home/yves/rosegarden/sounds/stretch-stretch-conv-Su-20240228-222741-4.wav"
    AudioTimeStretcher::initialise
    AudioTimeStretcher::calculateParameters
    AudioTimeStretcher: channels = 2, ratio = 0.945976, n1 = 256, n2 = 242, wlen = 2048, max = 1024
    making inbuf size 8543 (outbuf size is 6144, ratio 0.945976)
    making inbuf size 8543 (outbuf size is 6144, ratio 0.945976)
    [AudioFileTimeStretcher] getStretchedAudioFile(): success, id is 3
    AudioTimeStretcher::~AudioTimeStretcher
    AudioTimeStretcher::~AudioTimeStretcher: actual ratio = 0.945984, ideal = 0.945976, nominal = 0.949219)
    AudioTimeStretcher::cleanup
    [AudioPeaksGenerator] ctor Rosegarden::AudioPeaksGenerator(0xf67050) (now 4 extant)

     
  • Philip Leishman

    Philip Leishman - 2024-02-29

    OK - so I seem to have reproduced the problem.
    Do you have libsndfile installed ? Version > 1.0.16 ?
    If you have libsndfile the cmake output looks like:

    ...
    -- The following features have been enabled:

    • ALSA, Alsa library (Advanced Linux Sound Architecture), used for MIDI support
    • SNDFILE, Better support for WAV files
    • JACK, Library for accessing the JACK server (http://jackaudio.org).
      ...

    Without libsndfile you will get:

    ...

    -- The following features have been disabled:

    • SNDFILE, Better support for WAV files

    ...

    Maybe libsndfile should be a required dependency ??!!??

     
  • Yves Guillemot

    Yves Guillemot - 2024-02-29

    Thank Philip, but this is not the cause of the problem: libsndfile 1.0.31 is installed here and its devel package as well. Moreover audio files can be read and write without any problem and I presume it's done with libsndfile.
    Nevertheless, as it works on some system, I suspect the problem is related to a library.
    Concerned libraries may be libfftw3 and libsamplerate.
    I'll try to trace data inside the AudioTimeStretcher as soon as I'll have some time.

     
  • Philip Leishman

    Philip Leishman - 2024-03-01

    Oh well it was a nice theory.
    No further ideas on this.
    Does anyone else have this problem ?

     
  • Yves Guillemot

    Yves Guillemot - 2024-03-27

    The problem occurs in release mode only.
    When RG has been compiled in debug mode, the audio time stretcher works fine.

     
  • Philip Leishman

    Philip Leishman - 2024-04-01

    I can confirm this.
    Since most users will be using a release version this means the time stretcher is not really working at all !

     
  • Philip Leishman

    Philip Leishman - 2024-04-01

    That #ifndef NDEBUG looks suspicious !
    And indeed if I remove it everything works in release mode too
    Please merge

     

    Last edit: Ted Felix 2024-04-03
  • Yves Guillemot

    Yves Guillemot - 2024-04-01

    Thank you, Philip. You got it.
    I confirm the stretcher works fine when the NDEBUG condition is removed.

     
  • Ted Felix

    Ted Felix - 2024-04-03

    Merged as [79d672]. Please test latest git.

     

    Related

    Commit: [79d672]

  • Ted Felix

    Ted Felix - 2024-04-03
    • status: open --> feedback
    • assigned_to: Philip Leishman
     
  • Ted Felix

    Ted Felix - 2024-06-09
    • status: feedback --> closed
     

Log in to post a comment.