-o dac -d --messagelevel=2 ; ============================================== sr = 48000 ksmps = 1 nchnls = 2 0dbfs = 1 ; p4 = Sfile, p5 = iStart, p6 = iEnd, p7 = iClipdB, p8 = iHeadRoom instr Metre ; Set parameters and get file info Sfile = strget(p4) if (p5 == -1) then iStart init 0 else iStart init p5 endif iChnls = filenchnls(Sfile) iLength = filelen(Sfile) if (p6 == -1) then iEnd init iLength else iEnd init p6 endif iClipDB init p7 iHeadRoom init p8 prints "\nJBS clip %f head %f", iClipDB, iHeadRoom if (p3 < iLength) then xtratim (iLength - p3) endif ; Read the audio aLeft init 0 aRight init 0 if (iChnls == 1) then aLeft soundin Sfile else aLeft, aRight soundin Sfile endif ; Set up audio feedback iSaw = ftgenonce(0, 0, 32768, 7, 1, 32768, 0) iTri = ftgenonce(0, 0, 32768, 7, 0, 16384, 1, 16384, 0) iSoftSaw = ftgenonce(0, 0, 32768, 7, 0, 128, 1, (32768 - 128), 0) kAmp = oscil(.5, 2.5, iSaw) kVol init 1 kWave init -1 kClipCnt init 0 kHeadCnt init 0 kTrig = metro(2.5) ; Trigger to update audio output parameters ; Measure loudness kNow times kMom init 0 kShort init 0 kInt init 0 kStats[] = fillarray(1024, -1, -1024, -1, 1024, -1, -1024, -1) if (iChnls == 1) then kMom, kInt, kShort lufs 0, aLeft else kMom, kInt, kShort lufs 0, aLeft, aRight endif ; Update statistics if in time range if (kNow >= k(iStart)) && (kNow <= k(iEnd)) then printks "\nShort term %f at %f", 1, kShort, kNow if (kMom < kStats[0]) then kStats[0] = kMom kStats[1] = kNow endif if (kMom > kStats[2]) then kStats[2] = kMom kStats[3] = kNow endif if (kShort < kStats[4]) then kStats[4] = kShort kStats[5] = kNow endif if (kShort > kStats[6]) then kStats[6] = kShort kStats[7] = kNow endif endif ; Update audio parameters if (kTrig == 1) then if (kMom < k(iClipDB - iHeadRoom)) then kVol = 1 kWave = -1 elseif (kMom >= k(iClipDB)) then kClipCnt += 1 kVol = 4 kWave = iSoftSaw else kVol = linlin(kMom, 1, 4, (iClipDB - iHeadRoom), iClipDB) kWave = iTri kHeadCnt += 1 endif endif aTone = oscilikt(kAmp*kVol, 220* linlin(kVol, 1, 2, 1, 4), kWave) aDist init 0 if (kVol == 1) then aDist = aTone else aDist = clip(aTone, 0, .6, .5) endif ; Print stats if (lastcycle() != 0) then printks "\n----------------------------------------", 1/kr printks "\nMomentary minimum %f at %f seconds\nMomentary maximum %f at %f seconds\nShort term minimum %f at %f seconds\nShort term maximum %f at %f secondsIntegrated %f", 1/kr, kStats[0], kStats[1], kStats[2], kStats[3], kStats[4], kStats[5], kStats[6], kStats[7], kInt printks "\nAudio clipped %d times and violated headroom %d times\n----------------------------------------\n", 1/kr, kClipCnt, kHeadCnt endif ; Audio output aOutL init 0 aOutR init 0 aOutL = (aDist*.5 + aLeft * .75) if (iChnls == 1) then aOutR = aOutL else aOutR = (aDist *.5 + aRight * .75) endif outs(aOutL, aOutR) endin ; ============================================== i"Metre" 0 1 "file.wav" .4 194 -13 2 e Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here