HISE Logo Forum
    • Categories
    • Register
    • Login

    Get wav length in milliseconds OR sample rate

    Scheduled Pinned Locked Moved Scripting
    4 Posts 3 Posters 150 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dejaru
      last edited by

      Hey all.
      I'd like to get my wav file's length in milliseconds. I can do sample.getSampleLength() and get the length in samples and then do:

      var ms = (samples/samplerate) * 1000
      

      However, how can I get the samplerate of the wav?

      ustkU 1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @dejaru
        last edited by

        @dejaru there's a method called AudioFile.getSampleRate()

        Can't help pressing F5 in the forum...

        1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey
          last edited by

          You could also use Engine.getMilliSecondsForSamples()

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          1 Reply Last reply Reply Quote 0
          • D
            dejaru
            last edited by

            Appreciated guys, can't believe I missed these! Also got a bit confused with getting getSampleLength and getSampleRate.
            Case of the mondays I guess.

            const var SamplePlayer1 = Synth.getAudioSampleProcessor("SamplePlayer1");
            const var audioFile1 = SamplePlayer1.getAudioFile(0);
            const var samples = SamplePlayer1.getSampleLength();
            const var sampleRate = audioFile1.getSampleRate();
            const var lengthMs = (samples / sampleRate) * 1000;
            

            Thanks again.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            26

            Online

            1.7k

            Users

            11.8k

            Topics

            103.0k

            Posts