def testNormalize(self):
        '''Test Normalize Volume'''

        largest = 0
        f = 'Blip.wav'
        media.setTestMediaFolder()
        sound = media.makeSound(f)

        #for sample in media.getSamples(sound):
        counter = 0     
        while counter < media.getLength(sound):
            sample = media.getSampleObjectAt(sound, counter)
            largest = max(largest, abs(media.getSample(sample)), media.getSample(sample))
            counter += 1

        amplification = 32767.0 / largest

        counter = 0     
        while counter < media.getLength(sound):
            sample = media.getSampleObjectAt(sound, counter)
            louder =  amplification * media.getSample(sample)  
            media.setSample(sample, louder)
            counter += 1
                
        original = media.makeSound(f)
        
        counter = 0     
        while counter < media.getLength(sound):
            if( int(media.getSampleValueAt(sound,counter)) != int(media.getSampleValueAt(original,counter)*amplification)):
                self.fail("Sample %s not normalized properly" % counter)
                    #print "%s != %s at %s" % (media.getSampleValueAt(sound,counter), (media.getSampleValueAt(original,counter)*amplification), counter)
            counter += 1
示例#2
0
    def testNormalize(self):
        '''Test Normalize Volume'''

        largest = 0
        f = 'Blip.wav'
        media.setTestMediaFolder()
        sound = media.makeSound(f)

        #for sample in media.getSamples(sound):
        counter = 0
        while counter < media.getLength(sound):
            sample = media.getSampleObjectAt(sound, counter)
            largest = max(largest, abs(media.getSample(sample)),
                          media.getSample(sample))
            counter += 1

        amplification = 32767.0 / largest

        counter = 0
        while counter < media.getLength(sound):
            sample = media.getSampleObjectAt(sound, counter)
            louder = amplification * media.getSample(sample)
            media.setSample(sample, louder)
            counter += 1

        original = media.makeSound(f)

        counter = 0
        while counter < media.getLength(sound):
            if (int(media.getSampleValueAt(sound, counter)) != int(
                    media.getSampleValueAt(original, counter) *
                    amplification)):
                self.fail("Sample %s not normalized properly" % counter)
                #print "%s != %s at %s" % (media.getSampleValueAt(sound,counter), (media.getSampleValueAt(original,counter)*amplification), counter)
            counter += 1
    def testIncreaseVol(self):
        '''Test Increase Volume'''

        f = SOUNDS + 'Blip.wav'
        media.setTestMediaFolder()
        sound = media.makeSound(f)

        samples = media.getSamples(sound)
        i = 0

        while i < media.getLength(sound):
            # for sample in media.getSamples(sound):
            value = media.getSampleValueAt(sound, i)
            media.setSample(media.getSampleObjectAt(sound, i), (value * 2.0))
            i = i + 1

        original = media.makeSound(f)

        counter = 0
        while counter < media.getLength(sound):
            newval = int(
                round(media.getSampleValueAt(original, counter) * 2.0))
            if (newval > 32767):
                newval = 32767
            if(newval < -32768):
                newval = -32768
            if(media.getSampleValueAt(sound, counter) != newval):
                self.fail("Sample %s not increased properly" % counter)
            counter += 1
    def testIncreaseVol(self):
        '''Test Increase Volume'''

        f = SOUNDS + 'Blip.wav'
        media.setTestMediaFolder()
        sound = media.makeSound(f)

        samples = media.getSamples(sound)
        i = 0

        while i < media.getLength(sound):
            # for sample in media.getSamples(sound):
            value = media.getSampleValueAt(sound, i)
            media.setSample(media.getSampleObjectAt(sound, i), (value * 2.0))
            i = i + 1

        original = media.makeSound(f)

        counter = 0
        while counter < media.getLength(sound):
            newval = int(round(
                media.getSampleValueAt(original, counter) * 2.0))
            if (newval > 32767):
                newval = 32767
            if (newval < -32768):
                newval = -32768
            if (media.getSampleValueAt(sound, counter) != newval):
                self.fail("Sample %s not increased properly" % counter)
            counter += 1