Пример #1
0
    def _sampleCalculator(self, channels, pos, sampwidth, factors, attenuator):
        """
        Return the sample value, applying a factor and an attenuator.

        @param channels (Channel[]) the list of channels
        @param pos (int) the position of the sample to calculate
        @param sampwidth (int) the sample width
        @param factors (float[]) the list of factors to apply to each sample of a channel (1 channel = 1 factor)
        @param attenuator (float) a factor to apply to each sum of samples
        @return the value of the sample calculated (float)

        """
        #variables to compare the value of the result sample to avoid clipping
        minval = audioutils.get_minval(sampwidth)
        maxval = audioutils.get_maxval(sampwidth)

        #the result sample is the sum of each sample with the application of the factors
        sum = 0
        for factor,channel in zip(factors,channels):
            data = channel.frames[pos:pos+sampwidth]
            data = unpack_data(data, sampwidth)
            # without a cast, sum is a float!
            sum += data[0]*factor*attenuator

        #truncate the values if there is clipping
        if sum < 0:
            return max(sum,minval)
        elif sum > 0:
            return min(sum,maxval)
        return 0
Пример #2
0
if verbose > 0:
    p = TextProgress()
    p.set_new()
    p.set_header("Getting the factor to avoid clipping")

if verbose > 1:
    print "\nBegin getting factor at %s"%time.strftime('%d/%m/%y %H:%M:%S',time.localtime())

if p: p.update(0.1, "Left")
maxleft  = mixerleft.get_max()
if p: p.update(0.5, "Right")
maxright = mixerright.get_max()

if p: p.update(0.9, "Attenuator estimation")
maxval   = max(maxleft, maxright)
maxvalth = audioutils.get_maxval( sampleswidth )

if maxval > maxvalth:
    attenuator = float(maxvalth)/maxval*0.95
else:
    attenuator = 1

if verbose > 0:
    p.update(1, "")
    del p
if verbose > 1:
    print "\nEnd getting factor at %s"%time.strftime('%d/%m/%y %H:%M:%S',time.localtime())

# what's for????
#attenuator = 1