The truth is rarely pure and never simple

New Year’s Eve in Berlin

Have you ever wondered when the fireworks actually start and how long people remain busy? Yes, everybody is making fun of those who cannot wait until midnight. But most of the people are getting it right:

silvester2012-grob

Or the more interesting part:

silvester2012-fein

My notebook has pulled an all-nighter to record the street noise with fireworks at my place in Berlin yesterday. I was interested in the sound level as a measure for the amount of firework projectiles launched. In case you want to do the same for your place, here is the script that analyzed the 3.6 GB of wave audio.

#!/usr/bin/env python

import wave, struct

# reference data
total_sum = 0
w = wave.open('silence.wav')
l = w.getnframes()
while l > 0:
    framedata = struct.unpack('h' * min(20, l), w.readframes(min(20, l)))
    total_sum += sum(framedata)
    l -= 20
total_sum /= 1.0 * w.getnframes()
w.close()

# check recording (sample each five seconds)
w = wave.open('silvester2012.wav')
chunklength = w.getframerate() * 5
chunks = w.getnframes() / chunklength
for i in range(chunks):
    framedata = struct.unpack('h'*chunklength, w.readframes(chunklength))
    refdata = [abs(x-total_sum) for x in framedata]
    print i*5, sum(refdata)/chunklength

Although numpy is much faster in working on audio files, it is unable to deal with files bigger than the memory of the machine. For my setup, the relative drift between sound chip clock and system clock is about 2e-3 on the 12:18 hours of recording.

Leave a comment

Your email address will not be published.