I came up with an implementation that works well and, I think, is straightforward to use. The envelopes (three so far) are instanced, and then assigned to a a ProceduralSource when you create it. The sound sources have an "envelope" property, which allows you to easily change a waveform's envelope at any time. You can also assign any envelope instances to as many waveforms as you want. For example:
# Make some envelope instances: adsr = pyglet.media.procedural.ADSREnvelope(attack=0.1, decay=0.2, release= 0.4, sustain_amplitude=0.5) decay = pyglet.media.procedural.LinearDecayEnvelope(peak=1.0) # Decay from amplitude 1.0, to 0.0 # make and play a waveform with an envelope: sine = pyglet.media.procedural.Sine(1, frequency=220, envelope=adsr) sine.play() # change it's envelope: sine.envelope = decay sine.seek(0) sine.play() You can make one envelope instance, and assign it to as many different waveforms as you want. If no envelope is passed in on waveform creation, it defaults to "pyglet.media.procedural.FlatEnvelope(amplitude=1.0)". I'd appreciate feedback on this. If you want to play around with it, you can find it in the default branch of my pyglet fork here: https://bitbucket.org/treehousegames/pyglet/src On Sunday, December 11, 2016 at 7:34:26 PM UTC+9, Benjamin Moran wrote: > > That does look straightforward to have the source wrapped in an envelope, > but it might be a bit difficult with how the procedural sources are > currently implemented. They are subclasses of the sound Source, which > return AudioData is consumed directly by a Player. Wrapping them in an > envelope class would mean having to convert their output back into an > intermediate format, modifying it with the envelope, and then converting it > back into AudioData packets. This would likely be prohibitively slow... It > might be an interesting thing to try in another branch though, at some > point. > > For a start, I think I'll try to implement my previous idea in my fork, > and see how it works out. > > > On Sunday, December 11, 2016 at 12:05:34 PM UTC+9, [email protected] > wrote: >> >> Hmm, or maybe you could try the opposite. Instead of having the envelope >> be added to a source which then passes its own parameters back before >> playing, you could add the source to the envelope class and play it from >> there instead acting as a filter. Something like: >> >> adsr_envelope = procedural.ADSREnvelope(attack=0.05, decay=0.1, >> sustain_amplitude=0.7, release=0.3) >> sine_wave = procedural.Sine(duration=1, frequency=220) >> adsr_envelope.bind(sine_wave) >> adsr_envelope.play() >> >> So if you wanted to change envelopes you could unbind/rebind it to a >> different envelope instance, or change existing parameters, etc. >> > -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/pyglet-users. For more options, visit https://groups.google.com/d/optout.
