Synthesize¶
The synthesize module includes classes that can produce audio. Some, like
SineSynthesize
can produce simple signals from scratch that are often
useful for test-cases, while others are able to invert common frequency-domain
transforms, like the MDCTSynthesizer
Short-Time Transform Synthesizers¶
-
class
zounds.synthesize.
FFTSynthesizer
[source]¶ Inverts the short-time fourier transform, e.g. the output of the
FFT
processing node.Here’s an example that extracts a short-time fourier transform, and then inverts it.
import zounds STFT = zounds.stft( resample_to=zounds.SR11025(), store_fft=True) @zounds.simple_in_memory_settings class Sound(STFT): pass # produce some additive sine waves sine_synth = zounds.SineSynthesizer(zounds.SR22050()) samples = sine_synth.synthesize( zounds.Seconds(4), freqs_in_hz=[220, 400, 880]) # process the sound, including a short-time fourier transform feature _id = Sound.process(meta=samples.encode()) snd = Sound(_id) # invert the frequency-domain feature to reover the original audio fft_synth = zounds.FFTSynthesizer() recon = fft_synth.synthesize(snd.fft) print recon.__class__ # AudioSamples instance with reconstructed audio
See also
-
class
zounds.synthesize.
DCTSynthesizer
(windowing_func=<zounds.spectral.sliding_window.IdentityWindowingFunc object>)[source]¶ Inverts the short-time discrete cosine transform (type II), e.g., the output of the
DCT
processing nodeHere’s an example that extracts a short-time discrete cosine transform, and then inverts it.
import zounds Resampled = zounds.resampled(resample_to=zounds.SR11025()) @zounds.simple_in_memory_settings class Sound(Resampled): windowed = zounds.ArrayWithUnitsFeature( zounds.SlidingWindow, needs=Resampled.resampled, wscheme=zounds.HalfLapped(), wfunc=zounds.OggVorbisWindowingFunc(), store=False) dct = zounds.ArrayWithUnitsFeature( zounds.DCT, needs=windowed, store=True) # produce some additive sine waves sine_synth = zounds.SineSynthesizer(zounds.SR22050()) samples = sine_synth.synthesize( zounds.Seconds(4), freqs_in_hz=[220, 400, 880]) # process the sound, including a short-time fourier transform feature _id = Sound.process(meta=samples.encode()) snd = Sound(_id) # invert the frequency-domain feature to reover the original audio dct_synth = zounds.DCTSynthesizer() recon = dct_synth.synthesize(snd.dct) print recon.__class__ # AudioSamples instance with reconstructed audio
See also
-
class
zounds.synthesize.
DCTIVSynthesizer
(windowing_func=<zounds.spectral.sliding_window.IdentityWindowingFunc object>)[source]¶ Inverts the short-time discrete cosine transform (type IV), e.g., the output of the
DCTIV
processing node.Here’s an example that extracts a short-time DCT-IV transform, and inverts it.
import zounds Resampled = zounds.resampled(resample_to=zounds.SR11025()) @zounds.simple_in_memory_settings class Sound(Resampled): windowed = zounds.ArrayWithUnitsFeature( zounds.SlidingWindow, needs=Resampled.resampled, wscheme=zounds.HalfLapped(), wfunc=zounds.OggVorbisWindowingFunc(), store=False) dct = zounds.ArrayWithUnitsFeature( zounds.DCTIV, needs=windowed, store=True) # produce some additive sine waves sine_synth = zounds.SineSynthesizer(zounds.SR22050()) samples = sine_synth.synthesize( zounds.Seconds(4), freqs_in_hz=[220, 400, 880]) # process the sound, including a short-time fourier transform feature _id = Sound.process(meta=samples.encode()) snd = Sound(_id) # invert the frequency-domain feature to reover the original audio dct_synth = zounds.DCTIVSynthesizer() recon = dct_synth.synthesize(snd.dct) print recon.__class__ # AudioSamples instance with reconstructed audio
See also
-
class
zounds.synthesize.
MDCTSynthesizer
[source]¶ Inverts the modified discrete cosine transform, e.g., the output of the
MDCT
processing node.Here’s an example that extracts a short-time MDCT transform, and inverts it.
import zounds Resampled = zounds.resampled(resample_to=zounds.SR11025()) @zounds.simple_in_memory_settings class Sound(Resampled): windowed = zounds.ArrayWithUnitsFeature( zounds.SlidingWindow, needs=Resampled.resampled, wscheme=zounds.HalfLapped(), wfunc=zounds.OggVorbisWindowingFunc(), store=False) mdct = zounds.ArrayWithUnitsFeature( zounds.MDCT, needs=windowed, store=True) # produce some additive sine waves sine_synth = zounds.SineSynthesizer(zounds.SR22050()) samples = sine_synth.synthesize( zounds.Seconds(4), freqs_in_hz=[220, 400, 880]) # process the sound, including a short-time fourier transform feature _id = Sound.process(meta=samples.encode()) snd = Sound(_id) # invert the frequency-domain feature to reover the original audio mdct_synth = zounds.MDCTSynthesizer() recon = mdct_synth.synthesize(snd.mdct) print recon.__class__ # AudioSamples instance with reconstructed audio
See also
Frequency-Adaptive Transform Synthesizers¶
-
class
zounds.synthesize.
FrequencyAdaptiveDCTSynthesizer
(scale, samplerate)[source]¶ Invert a frequency-adaptive transform, e.g., one produced by the
zounds.spectral.FrequencyAdaptiveTransform
processing node which has used a discrete cosine transform in its transform parameter.Parameters: - scale (FrequencyScale) – The scale used to produce the frequency-adaptive transform
- samplerate (SampleRate) – The audio samplerate of the audio that was originally transformed
Here’s an example of how you might first extract a frequency-adaptive representation, and then invert it:
import zounds import scipy import numpy as np samplerate = zounds.SR11025() Resampled = zounds.resampled(resample_to=samplerate) scale = zounds.GeometricScale( 100, 5000, bandwidth_ratio=0.089, n_bands=100) scale.ensure_overlap_ratio(0.5) @zounds.simple_in_memory_settings class Sound(Resampled): long_windowed = zounds.ArrayWithUnitsFeature( zounds.SlidingWindow, wscheme=zounds.SampleRate( frequency=zounds.Milliseconds(500), duration=zounds.Seconds(1)), wfunc=zounds.OggVorbisWindowingFunc(), needs=Resampled.resampled) dct = zounds.ArrayWithUnitsFeature( zounds.DCT, scale_always_even=True, needs=long_windowed) freq_adaptive = zounds.FrequencyAdaptiveFeature( zounds.FrequencyAdaptiveTransform, transform=scipy.fftpack.idct, window_func=np.hanning, scale=scale, needs=dct, store=True) # produce some additive sine waves sine_synth = zounds.SineSynthesizer(zounds.SR22050()) samples = sine_synth.synthesize( zounds.Seconds(10), freqs_in_hz=[220, 440, 880]) # process the sound, including a short-time fourier transform feature _id = Sound.process(meta=samples.encode()) snd = Sound(_id) # invert the sound synth = zounds.FrequencyAdaptiveDCTSynthesizer(scale, samplerate) recon = synth.synthesize(snd.freq_adaptive) print recon # AudioSamples instance with the reconstructed sound
-
class
zounds.synthesize.
FrequencyAdaptiveFFTSynthesizer
(scale, samplerate)[source]¶ Invert a frequency-adaptive transform, e.g., one produced by the
zounds.spectral.FrequencyAdaptiveTransform
processing node which has used a fast fouriter transform in its transform parameter.Parameters: - scale (FrequencyScale) – The scale used to produce the frequency-adaptive transform
- samplerate (SampleRate) – The audio samplerate of the audio that was originally transformed
Here’s an example of how you might first extract a frequency-adaptive representation, and then invert it:
import zounds import numpy as np samplerate = zounds.SR11025() Resampled = zounds.resampled(resample_to=samplerate) scale = zounds.GeometricScale(100, 5000, bandwidth_ratio=0.089, n_bands=100) scale.ensure_overlap_ratio(0.5) @zounds.simple_in_memory_settings class Sound(Resampled): long_windowed = zounds.ArrayWithUnitsFeature( zounds.SlidingWindow, wscheme=zounds.SampleRate( frequency=zounds.Milliseconds(500), duration=zounds.Seconds(1)), wfunc=zounds.OggVorbisWindowingFunc(), needs=Resampled.resampled) fft = zounds.ArrayWithUnitsFeature( zounds.FFT, needs=long_windowed) freq_adaptive = zounds.FrequencyAdaptiveFeature( zounds.FrequencyAdaptiveTransform, transform=np.fft.irfft, window_func=np.hanning, scale=scale, needs=fft, store=True) # produce some additive sine waves sine_synth = zounds.SineSynthesizer(zounds.SR22050()) samples = sine_synth.synthesize( zounds.Seconds(10), freqs_in_hz=[220, 440, 880]) # process the sound, including a short-time fourier transform feature _id = Sound.process(meta=samples.encode()) snd = Sound(_id) # invert the sound synth = zounds.FrequencyAdaptiveFFTSynthesizer(scale, samplerate) recon = synth.synthesize(snd.freq_adaptive) print recon # AudioSamples instance with the reconstructed sound
Simple Signals¶
-
class
zounds.synthesize.
SineSynthesizer
(samplerate)[source]¶ Synthesize sine waves
Parameters: samplerate (Samplerate) – the samplerate at which the sine waves should be synthesized Examples
>>> import zounds >>> synth = zounds.SineSynthesizer(zounds.SR22050()) >>> samples = synth.synthesize( zounds.Seconds(1), freqs_in_hz=[220., 440.]) >>> samples AudioSamples([ 0. , 0.09384942, 0.18659419, ..., -0.27714552, -0.18659419, -0.09384942]) >>> len(samples) 22050
-
class
zounds.synthesize.
NoiseSynthesizer
(samplerate)[source]¶ Synthesize white noise
Parameters: samplerate (SampleRate) – the samplerate at which the ticks should be synthesized Examples
>>> import zounds >>> synth = zounds.NoiseSynthesizer(zounds.SR44100()) >>> samples = synth.synthesize(zounds.Seconds(2)) >>> samples AudioSamples([ 0.1137964 , -0.02613194, 0.30963904, ..., -0.71398137, -0.99840281, 0.74310827])
-
synthesize
(duration)[source]¶ Synthesize white noise
Parameters: duration (numpy.timedelta64) – The duration of the synthesized sound
-
-
class
zounds.synthesize.
TickSynthesizer
(samplerate)[source]¶ Synthesize short, percussive, periodic “ticks”
Parameters: samplerate (SampleRate) – the samplerate at which the ticks should be synthesized Examples
>>> import zounds >>> synth = zounds.TickSynthesizer(zounds.SR22050()) >>> samples = synth.synthesize( duration=zounds.Seconds(3), tick_frequency=zounds.Milliseconds(100)) >>> samples AudioSamples([ -3.91624993e-01, -8.96939666e-01, 4.18165378e-01, ..., -4.08054347e-04, -2.32257899e-04, 0.00000000e+00])
-
synthesize
(duration, tick_frequency)[source]¶ Synthesize periodic “ticks”, generated from white noise and an envelope
Parameters: - duration (numpy.timedelta64) – The total duration of the sound to be synthesized
- tick_frequency (numpy.timedelta64) – The frequency of the ticking sound
-
-
class
zounds.synthesize.
SilenceSynthesizer
(samplerate)[source]¶ Synthesize silence
Parameters: samplerate (SampleRate) – the samplerate at which the ticks should be synthesized Examples
>>> import zounds >>> synth = zounds.SilenceSynthesizer(zounds.SR11025()) >>> samples = synth.synthesize(zounds.Seconds(5)) >>> samples AudioSamples([ 0., 0., 0., ..., 0., 0., 0.])
-
synthesize
(duration)[source]¶ Synthesize silence
Parameters: duration (numpy.timedelta64) – The duration of the synthesized sound
-