HISE Logo Forum
    • Categories
    • Register
    • Login

    AudioFile.getNumSamples();

    Scheduled Pinned Locked Moved General Questions
    6 Posts 2 Posters 287 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.
    • CyberGenC
      CyberGen
      last edited by

      Hi,

      I'm trying to get the total number of samples in a convolution audio file. But I can't seem to make "getNumSamples()" work. I was hoping somebody could share an example of what is the proper way to write in the name of the file. I've tried a number of ways with and without the wildcard, with and without the .aif, just can't seem to make it work.
      getSampleLength() is no good in this situation.

      ? 1 Reply Last reply Reply Quote 0
      • ?
        A Former User @CyberGen
        last edited by A Former User

        @CyberGen You can do something like this:

        const myCoolWav = "{PROJECT_FOLDER}AudioFiles/myCoolWav.wav";
        
        var audio = myCoolWav.loadAsAudioFile();
        
        Console.print(audio.length);
        

        EDIT: if it's stereo, the buffer will be multidimensional:

        Console.print(audio[0].length);
        
        CyberGenC 2 Replies Last reply Reply Quote 1
        • CyberGenC
          CyberGen @A Former User
          last edited by

          @iamlamprey Nice! Had no idea I could just .length-it. Thank you so much.

          1 Reply Last reply Reply Quote 0
          • CyberGenC
            CyberGen @A Former User
            last edited by

            @iamlamprey May have spoken to soon. I thought I got it to work for a second there, but now I am getting an error: Unknown function 'loadAsAudioFile'
            The file should be loaded in the pool anyway as I have a Engine.loadAudioFilesIntoPool(); in the interface script.
            But when I try your formula without the loadAsAudioFile it just gives me a count of the characters in the string and not the number of samples? Any suggestions?

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @CyberGen
              last edited by A Former User

              @CyberGen Sorry I should have mentioned the audio file should be a file object first

              const audioFiles = FileSystem.getFolder(FileSystem.AudioFiles); // Replace with whereever you put your audio file
              const myCoolWav = audioFiles.getChildFile("myCoolWav.wav"); // Now it's a file object
              
              var audio = myCoolWav.loadAsAudioFile();
              
              if (isDefined(audio[0].length))
              {
                  Console.print(audio[0].length); // Stereo
              }
              else
              {
                  Console.print(audio.length); // Mono
              }
              
              CyberGenC 1 Reply Last reply Reply Quote 1
              • CyberGenC
                CyberGen @A Former User
                last edited by

                @iamlamprey Alright, this method definitely worked. Though I'm still wondering about getNumSamples(), I tried with audio files as objects and still gave me an error.

                Anyhow, the audio.length method accomplishes my initial objective and I learned a few new tricks so, thank you soooo much.

                cheers!

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

                33

                Online

                1.7k

                Users

                11.8k

                Topics

                102.8k

                Posts