AudioFile.getNumSamples();
-
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. -
@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);
-
@iamlamprey Nice! Had no idea I could just .length-it. Thank you so much.
-
@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? -
@CyberGen Sorry I should have mentioned the audio file should be a
file
object firstconst 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 }
-
@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!