def _diceWeight(self, gamma=None): """get an array of dice weighting weights a proportion of sum for all weights; this proportion is used to scale the contribtion of each die to the final sum >>> a = GameNoise(10) # get 4 dice b/c this is nearest power of 2 >>> a._diceWeight(0) [0.13807118488213274, 0.1952621441311885, 0.27614237513248824, 0.39052429585419057] >>> a._diceWeight(1) [0.25, 0.25, 0.25, 0.25] >>> a._diceWeight(2) [0.39052429585419057, 0.27614237513248824, 0.1952621441311885, 0.13807118488213271] >>> a._diceWeight(3) [0.53333334093655471, 0.26666666528426275, 0.1333333300501241, 0.066666663729058454] >>> a._diceWeight(4) [0.65670767595633661, 0.23218121869256828, 0.082088454707129804, 0.029022650643965243] """ # updates self.gamma self._updateGamma(gamma) # calc raw weights, reverse, and normalize diceWeight = [] for i in range(0, self.noDice): # dice index starts at 0 diceWeight.append(self._weightRawSingle(i, self.gamma)) # the higher the value of i, the less frequent the use of that weight # should be; if the left-most column of binary moves are the least # common, then the highest value i should be on the left; thus reverse diceWeight.reverse() # normalize weights so sum == 1 diceWeight = unit.unitNormProportion(diceWeight) return diceWeight
def durToAdsr(tStart, propAbsSwitch, dur, attack, decay, sustain, release, susScalar, min=0, max=1): """create an adsr envelope sustain scalar is a value, w/n the unit interval, of the difference between min and max >>> durToAdsr(0, 'absolute', 10, 2, 1, 2, 2, .5) [[0, 0.0], [2, 1.0], [3, 0.5], [5, 0.5], [7, 0.0], [9.999..., 0.0]] """ # will automatically sort min, max peak = unit.denorm(1, min, max) nadir = unit.denorm(0, min, max) susLevel = (peak - nadir) * unit.limit(susScalar) if propAbsSwitch not in ['absolute', 'proportional']: raise error.ParameterObjectSyntaxError('incorrect switch') if propAbsSwitch == 'absolute': timeUnitDenorm = [attack, decay, sustain, release] if sum(timeUnitDenorm) > dur: # force proportional propAbsSwitch = 'proportional' if propAbsSwitch == 'proportional': timeUnit = unit.unitNormProportion([attack, decay, sustain, release]) timeUnitDenorm = [x * dur for x in timeUnit] tEnd = tStart + dur t = tStart envelope = [] envelope.append([t, nadir]) t = t + _stepFilter(timeUnitDenorm[0]) # attack envelope.append([t, peak]) t = t + _stepFilter(timeUnitDenorm[1]) # decay envelope.append([t, susLevel]) t = t + _stepFilter(timeUnitDenorm[2]) # sustain envelope.append([t, susLevel]) if propAbsSwitch == 'proportional': t = tEnd - OFFSET # always measure to end envelope.append([t, nadir]) else: # absolute t = t + _stepFilter(timeUnitDenorm[3]) # sustain envelope.append([t, nadir]) t = tEnd - OFFSET # always measure to end envelope.append([t, nadir]) return envelope
def durToTrapezoid(tStart, propAbsSwitch, dur, rampUp, widthMax, rampDown, widthMin, min=0, max=1): """assume dir of peal is widthOn will automatically convert to proportion if abs sum extends past dur this is an trapezoid with only one ramp; may not have complete duration time; always leads on >>> durToTrapezoid(0, 'absolute', 10, 3, 3, 3, .5) [[0, 0.0], [3, 1.0], [6, 1.0], [9, 0.0], [9.999..., 0.0]] """ # will automatically sort min, max peak = unit.denorm(1, min, max) nadir = unit.denorm(0, min, max) if propAbsSwitch not in ['absolute', 'proportional']: raise error.ParameterObjectSyntaxError('incorrect switch') if propAbsSwitch == 'absolute': timeUnitDenorm = [rampUp, widthMax, rampDown, widthMin] if sum(timeUnitDenorm) > dur: # force proportional propAbsSwitch = 'proportional' if propAbsSwitch == 'proportional': timeUnit = unit.unitNormProportion( [rampUp, widthMax, rampDown, widthMin]) timeUnitDenorm = [x * dur for x in timeUnit] tEnd = tStart + dur t = tStart envelope = [] envelope.append([t, nadir]) t = t + _stepFilter(timeUnitDenorm[0]) # ramp envelope.append([t, peak]) t = t + _stepFilter(timeUnitDenorm[1]) # width envelope.append([t, peak]) t = t + _stepFilter(timeUnitDenorm[2]) # ramp envelope.append([t, nadir]) t = tEnd - OFFSET # always measure to end envelope.append([t, nadir]) return envelope
def durToAdsr(tStart, propAbsSwitch, dur, attack, decay, sustain, release, susScalar, min=0, max=1): """create an adsr envelope sustain scalar is a value, w/n the unit interval, of the difference between min and max >>> durToAdsr(0, 'absolute', 10, 2, 1, 2, 2, .5) [[0, 0.0], [2, 1.0], [3, 0.5], [5, 0.5], [7, 0.0], [9.999..., 0.0]] """ # will automatically sort min, max peak = unit.denorm(1, min, max) nadir = unit.denorm(0, min, max) susLevel = (peak-nadir) * unit.limit(susScalar) if propAbsSwitch not in ['absolute', 'proportional']: raise error.ParameterObjectSyntaxError, 'incorrect switch' if propAbsSwitch == 'absolute': timeUnitDenorm = [attack, decay, sustain, release] if sum(timeUnitDenorm) > dur: # force proportional propAbsSwitch = 'proportional' if propAbsSwitch == 'proportional': timeUnit = unit.unitNormProportion([attack, decay, sustain, release]) timeUnitDenorm = [x*dur for x in timeUnit] tEnd = tStart + dur t = tStart envelope = [] envelope.append([t, nadir]) t = t + _stepFilter(timeUnitDenorm[0]) # attack envelope.append([t, peak]) t = t + _stepFilter(timeUnitDenorm[1]) # decay envelope.append([t, susLevel]) t = t + _stepFilter(timeUnitDenorm[2]) # sustain envelope.append([t, susLevel]) if propAbsSwitch == 'proportional': t = tEnd - OFFSET # always measure to end envelope.append([t, nadir]) else: # absolute t = t + _stepFilter(timeUnitDenorm[3]) # sustain envelope.append([t, nadir]) t = tEnd - OFFSET # always measure to end envelope.append([t, nadir]) return envelope
def durToTrapezoid(tStart, propAbsSwitch, dur, rampUp, widthMax, rampDown, widthMin, min=0, max=1): """assume dir of peal is widthOn will automatically convert to proportion if abs sum extends past dur this is an trapezoid with only one ramp; may not have complete duration time; always leads on >>> durToTrapezoid(0, 'absolute', 10, 3, 3, 3, .5) [[0, 0.0], [3, 1.0], [6, 1.0], [9, 0.0], [9.999..., 0.0]] """ # will automatically sort min, max peak = unit.denorm(1, min, max) nadir = unit.denorm(0, min, max) if propAbsSwitch not in ['absolute', 'proportional']: raise error.ParameterObjectSyntaxError, 'incorrect switch' if propAbsSwitch == 'absolute': timeUnitDenorm = [rampUp, widthMax, rampDown, widthMin] if sum(timeUnitDenorm) > dur: # force proportional propAbsSwitch = 'proportional' if propAbsSwitch == 'proportional': timeUnit = unit.unitNormProportion([rampUp, widthMax, rampDown, widthMin]) timeUnitDenorm = [x*dur for x in timeUnit] tEnd = tStart + dur t = tStart envelope = [] envelope.append([t, nadir]) t = t + _stepFilter(timeUnitDenorm[0]) # ramp envelope.append([t, peak]) t = t + _stepFilter(timeUnitDenorm[1]) # width envelope.append([t, peak]) t = t + _stepFilter(timeUnitDenorm[2]) # ramp envelope.append([t, nadir]) t = tEnd - OFFSET # always measure to end envelope.append([t, nadir]) return envelope