Example #1
0
    def test_rms(self):
        audio = audiodata.io.open(sample_1)
        cidx = audio.extract_channel(0)
        channel = audio.get_channel(cidx)

        chanvol  = ChannelVolume(channel)
        audiovol = AudioVolume(audio)

        self.assertEqual(chanvol.volume(), channel.rms())
        self.assertEqual(audiovol.volume(), audio.rms())
        self.assertEqual(chanvol.len(), int(channel.get_duration()/0.01) + 1)
        self.assertEqual(chanvol.min(), audiovol.min())
        self.assertEqual(chanvol.max(), audiovol.max())
        self.assertEqual(int(chanvol.mean()), int(audiovol.mean()))
        self.assertEqual(int(chanvol.variance()), int(audiovol.variance()))
        self.assertEqual(int(chanvol.stdev()), int(audiovol.stdev()))
Example #2
0
print "Sample width (bits): ", audio.get_sampwidth()*8
nc = audio.get_nchannels()
print "Number of channels:  ", nc

if nc == 1:
    print "Clipping rate (in %):"
    for i in range(2,9,2):
        f = float(i)/10.
        c = audio.clipping_rate( f ) * 100.
        print "  - factor=%.1f:      %.3f"%(f,c)

    audiovol = AudioVolume(audio, args.f)
    print "Volume:"
    print "  - min:           ", audiovol.min()
    print "  - max:           ", audiovol.max()
    print "  - mean:          ", round(audiovol.mean(),2)
    print "  - median:        ", round(audiovol.median(),2)
    print "  - stdev:         ", round(audiovol.stdev(),2)
    print "  - coefvariation: ", round(audiovol.coefvariation(),2)

else:

    for n in range(nc):
        print "Channel %d:"%(n)
        cidx = audio.extract_channel(n)
        channel = audio.get_channel(cidx)

        # Values related to amplitude
        frames = channel.get_frames(channel.get_nframes())
        ca = AudioFrames(frames, channel.get_sampwidth(), 1)
        for i in range(2,9,2):