#this scripts reads all sounds from the directory specified in sourceDir$ #and equalizes them to the maximally possible RMS with prevention of clipping #and write them to the directory specified in 'out$' #paramters to set sourceDir$ = "D:\experimentFiles\cs_audio\" out$ = "C:\temp" #making sure the concatenation of director and file name works @getDirSep if right$(sourceDir$,1) <> dirSep$ sourceDir$ = sourceDir$ + dirSep$ endif if right$(out$,1) <> dirSep$ out$ = out$ + dirSep$ endif myStr = Create Strings as file list: "list", sourceDir$ + "*.wav" numberOfFiles = Get number of strings if numberOfFiles < 1 exitScript: "no files in specified folder,\nmaybe there's a typo in the folder name?" endif writeInfoLine: "finding maximal possible RMS" rms_max = 5 for ifile from 1 to numberOfFiles selectObject: myStr a$ = Get string: ifile name$[ifile] = a$ snd[ifile] = Read from file: sourceDir$ + a$ max = Get absolute extremum: 0, 0, "None" rms = Get root-mean-square: 0, 0 rms_max_now = (0.99999/max) * rms if rms_max_now < rms_max rms_max = rms_max_now endif rms[ifile] = rms #remember the rms values of all files in the array rms1, rms2, rms3, .... endfor appendInfoLine: "RMS value for all sounds is : " + fixed$(rms_max,3) for ifile from 1 to numberOfFiles selectObject: snd[ifile] Formula: "self * rms_max/rms[ifile]" Write to WAV file: out$ + name$[ifile] endfor appendInfoLine: "Wrote " + fixed$(numberOfFiles,0) + " files." procedure getDirSep if windows == 0 dirSep$ = "/" else dirSep$ = "\" endif endproc