def doWind(length, hfq, vol, reverse=False): key = (length, _logRoundUp(hfq), vol, reverse) if key in _resonanceCache: if random.random() < _CACHE_PROBABILITY: return _repitch(key[1], hfq, readSwappedCache(_resonanceCache[key])) with SFMemoryZone(): # Put in a little extra and then trim it off reliably. upRatio = key[1] * 1.01 / float(hfq) out = _distant_wind(length * upRatio, hfq, qCorrect, limit, seed) out = sf.Power(out, power) if saturate: os = sf.Saturate(sf.LinearVolume(sf.FixSize(+out), 2.0)) out = sf.Mix(sf.LinearVolume(out, 1.0 - saturate), sf.LinearVolume(os, saturate)) out = sf.Realise(out) out = sf.LinearVolume(sf.FixSize(out), vol) if reverse: out = sf.Reverse(out) ret = compress(out) if _PERFORM_CACHE: # Store no more than the length we need which we work out as the # inverse scale of that used to make the signal. This should # always give enough signal so out of bounds does not happen. toCache = _repitch(hfq, key[1], ret, sf.Length(ret) / upRatio) # FIXME: Figure out how to make this long enough. # See call to _distant_wind above. _resonanceCache[key] = writeSawppedCache(toCache) return toCache.keep() else: return ret.keep() return ret
def doWind(lenth, hfq, vol, reverse=False): with SFMemoryZone(): out = _distant_wind(length, hfq, qCorrect, limit, seed) out = sf.Power(out, power) if saturate: os = sf.Saturate(sf.NumericVolume(sf.FixSize(+out), 2.0)) out = sf.Mix(sf.NumericVolume(out, 1.0-saturate), sf.NumericVolume(os, saturate)) out = sf.Realise(out) out = sf.NumericVolume(sf.FixSize(out), vol) if reverse: out = sf.Reverse(out) return compress(out).keep()
def additive_resonance(power, qCorrect, saturate, rollOff, post, limit, seed, flat, harmonics, length, freq): lowComp = freq < 128 if lowComp: freq *= 2.0 length *= 0.5 @sf_parallel def doWind(lenth, hfq, vol, reverse=False): with SFMemoryZone(): out = _distant_wind(length, hfq, qCorrect, limit, seed) out = sf.Power(out, power) if saturate: os = sf.Saturate(sf.NumericVolume(sf.FixSize(+out), 2.0)) out = sf.Mix(sf.NumericVolume(out, 1.0-saturate), sf.NumericVolume(os, saturate)) out = sf.Realise(out) out = sf.NumericVolume(sf.FixSize(out), vol) if reverse: out = sf.Reverse(out) return compress(out).keep() harms = [] base = compress(sf.Silence(length)) sigs = [] for harm in harmonics: hfreq = harm * freq if hfreq > 18000.0: break harms.append(harm) vol = 1.0 / (pow(harm, rollOff)) if flat: sfw = doWind(length, hfreq, vol) srv = doWind(length, hfreq, vol, reverse=True) sigs += [sfw, srv] else: sigs += [doWind(lenth, hfq, vol)] if len(sigs) > 3: sigs += [base] base = sf.Realise(sf.Mix(sigs)) sigs = [] print 'Done Wind' base = decompress(base) ret = None if lowComp: base=sf.DirectRelength(base, 0.5) freq *= 0.5 length *= 2.0 ret = sf.Realise(sf.FixSize(sf.Clean(base))) else: ret = sf.Realise(sf.FixSize(polish(base,freq))) return post(ret, length, freq) if post else ret
def additive_resonance(power, qCorrect, saturate, rollOff, post, limit, seed, flat, harmonics, length, freq): lowComp = freq < 128 if lowComp: freq *= 2.0 length *= 0.5 def doWind(length, hfq, vol, reverse=False): key = (length, _logRoundUp(hfq), vol, reverse) if key in _resonanceCache: if random.random() < _CACHE_PROBABILITY: return _repitch(key[1], hfq, readSwappedCache(_resonanceCache[key])) with SFMemoryZone(): # Put in a little extra and then trim it off reliably. upRatio = key[1] * 1.01 / float(hfq) out = _distant_wind(length * upRatio, hfq, qCorrect, limit, seed) out = sf.Power(out, power) if saturate: os = sf.Saturate(sf.LinearVolume(sf.FixSize(+out), 2.0)) out = sf.Mix(sf.LinearVolume(out, 1.0 - saturate), sf.LinearVolume(os, saturate)) out = sf.Realise(out) out = sf.LinearVolume(sf.FixSize(out), vol) if reverse: out = sf.Reverse(out) ret = compress(out) if _PERFORM_CACHE: # Store no more than the length we need which we work out as the # inverse scale of that used to make the signal. This should # always give enough signal so out of bounds does not happen. toCache = _repitch(hfq, key[1], ret, sf.Length(ret) / upRatio) # FIXME: Figure out how to make this long enough. # See call to _distant_wind above. _resonanceCache[key] = writeSawppedCache(toCache) return toCache.keep() else: return ret.keep() return ret harms = [] base = compress(sf.Silence(length)) sigs = [] for harm in harmonics: hfreq = harm * freq if hfreq > 18000.0: break harms.append(harm) vol = 1.0 / (pow(harm, rollOff)) if flat: sfw = doWind(length, hfreq, vol) srv = doWind(length, hfreq, vol, reverse=True) sigs += [sfw, srv] else: sigs += [doWind(lenth, hfq, vol)] if len(sigs) > 3: sigs += [base] base = sf.Realise(sf.Mix(sigs)) sigs = [] base = decompress(base) ret = None if lowComp: base = sf.DirectRelength(base, 0.5) freq *= 0.5 length *= 2.0 ret = sf.Realise(sf.FixSize(sf.Clean(base))) else: ret = sf.Realise(sf.FixSize(polish(base, freq))) return post(ret, freq) if post else ret