As far as I can see, the code works correctly and takes the maximum value of the two channels.
I'm not sure why you want to multiply by 2. You're aware that the -30 dB threshold is afterwards -26 dB?
Instead of the snd-avg function you can take the rms function instead.
where target samplerate means the track's samplerate divided by the step size:
Code: Select all
(rms s (/ *sound-srate* step) step)
Again, the secondary step is the hop size and is optional. Use it only if you want a smaller value--that smoothens the curve while preserving the accuracy.
Also, there's no lowpassfilter applied yet, this would of course reduce spurious clicks as well.
I gather you want to apply it in a chain, don't you?
Otherwise, it would be easier to simply tell the program how many tracks there are on the LP and to let it search for those x longest gaps.
Another improvement is to use the zero crossing rate as well.
This is e.g. done in GSM standards to detect voice activity.
A song might fade out with a droning bass tone, the amplitude might soon be under the threshold but the gap will actually be longer than it should. Placing the point label in the center could result in splitting the fading tone.
The zero crossing rate for the bass tone is pretty low while it is quite high for silence (or rather white or coloured noise).
The gap would be calculated from the intersection of the amplitude below the threshold and a ZCR above a secondary threshold (ee.g. 6000 Hz).
As for the center:
the last cond expression searches for pauses that are longer than minlen.
However, once this len is reached, the counting begins again. Thus the center would always be half of the minlen.
the following code counts til the end:
Code: Select all
((> val threshold)
(when (and (/= silcount 0) (> silcount minlen))
(setf start (- count (/ silcount 2)))
(list (* (recip sr) start) label-text)
(setf silcount 0)))
((<= val threshold)
I would personally push the point nearer to the next song since fade-outs are much more common than fade-ins.
Again, the Zcr could be helpful for those overlong gaps.