<jupyter_start><jupyter_text>Timbre Painting in DDSP  Basic Upsampler<jupyter_code>%load_ext autoreload
%autoreload 2

# Extract some f0
from ddsp.synths import BasicUpsampler
import numpy as np
from matplotlib import pyplot as plt
from ddsp.colab.jupyter_utils import show_audio

sample_rate = 16000
n_samples = 4*sample_rate
synth = BasicUpsampler(n_samples)

f0_hz = np.linspace(400, 800, 100).reshape([1,-1,1])
amplitudes = np.abs(np.sin(np.linspace(0, 2*np.pi, 100))).reshape([1,-1,1])

wav = synth.get_signal(amplitudes, f0_hz)
show_audio(wav, focus_points=[0.45, 0.8], focus_windows=[2000, 2000])<jupyter_output><empty_output><jupyter_text>Basic Upsampler + ParallelWaveGANUpsampler<jupyter_code>from ddsp.training.decoders import TimbrePaintingDecoder

decoder = TimbrePaintingDecoder(name='tpd', input_keys=('amplitudes', 'f0_hz'))
batch = {
    'f0_hz': f0_hz,
    'amplitudes': amplitudes
}
controls = decoder(batch)

wav = controls['audio_tensor'].numpy().squeeze()
show_audio(wav, focus_points=[0.05, 0.95], focus_windows=[2000, 2000])<jupyter_output><empty_output><jupyter_text>Discriminator<jupyter_code>from ddsp.training import discriminator

critic = discriminator.ParallelWaveGANDiscriminator(input_keys=['audio_tensor', 'f0_hz', 'amplitudes'])
critic_score = critic(controls)

critic_score<jupyter_output><empty_output><jupyter_text>Gan Autoencoder<jupyter_code>import ddsp
from ddsp.training import models, preprocessing, decoders, discriminator
from ddsp import synths



dag = [(synths.TensorToAudio(), ['audio_tensor'])]

ae = models.Autoencoder(
    preprocessor=None,
    encoder=None,
    decoder=decoders.TimbrePaintingDecoder(name='tpd', input_keys=('amplitudes', 'f0_hz')),
    processor_group=ddsp.processors.ProcessorGroup(dag=dag, name='processor_group'),
    discriminator=discriminator.ParallelWaveGANDiscriminator(input_keys=['discriminator_audio', 'f0_hz', 'amplitudes']),
    losses=[]
)

batch = {
    'f0_hz': f0_hz,
    'amplitudes': amplitudes,
    'audio': np.random.normal(0,1,size=n_samples)
}
outputs = ae(batch)

outputs.keys()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13070342205323193, 'fraction_numerical': 0.03184410646387833, 'mean_word_length': 7.807531380753138, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '585456', 'license': 'Apache-2.0', 'n_tokens_mistral': 861, 'n_tokens_neox': 792, 'n_words': 124, 'path': 'ddsp/colab/experiments/02_initialize_gan.ipynb', 'repo_name': 'nielsrolf/ddsp', 'size': '2104'}