class Mixer(): def __init__(self): self.voices = [] def __call__(self, time): value = ValueState(0.0, False) weight = 0.0 for voice in self.voices: weight += voice[0] value = value + voice[1](time) if weight > 0.0: value /= weight return value if __name__ == "__main__": from sys import stdin from sound import Sound from sinosc import SinOsc mixer = Mixer() mixer.voices.append([0.5, SinOsc(440.0)]) mixer.voices.append([0.5, SinOsc(330.0)]) sound = Sound() sound.generator = mixer sound.start() sound.play() stdin.readline() sound.shutdown()
class SinOscDef(Composer): def __init__(self, params=None): Composer.__init__(self, self) self.params = params def __call__(self, time=0.0, params=None): sinosc = SinOsc() if self.params is not None: for key in self.params: if key in sinosc.__dict__: setattr(sinosc, key, self.params[key]) if params is not None: for key in params: if key in sinosc.__dict__: setattr(sinosc, key, params[key]) return sinosc if __name__ == "__main__": from sys import stdin from sound import Sound osc_def = SinOscDef() sound = Sound() osc = osc_def(0.0, {"freq": 220.0}) sound.generator = osc sound.start() sound.play() stdin.readline() sound.shutdown()
if value_state: self.voices.remove(voice) if weight > 0.0: return total / weight return total if __name__ == "__main__": from sys import stdin from sound import Sound from sinosc import SinOscDef from adsr import ADRSDef sinosc = SinOscDef() adsr = ADRSDef({"a": 0.01, "d": 0.0, "s": 0.0, "r": 0.1, "dl": 1.0}) sound = Sound() generator = Generator(sinosc * adsr, [{ "l": 0.25, "p": { "freq": 440.0 } }, { "l": 0.25, "p": { "freq": 330.0 } }]) sound.generator = generator sound.start() sound.play() stdin.readline() sound.shutdown()