code: def generate_notes_v2(
      n_batch=1,
      n_timesteps=125,
      n_harmonics=100,
      n_mags=65,
      min_note_length=5,
      max_note_length=25,
      p_silent=0.1,
      p_vibrato=0.5,
      get_controls=True,
  ):
      """Generate more expressive self-supervision signal of discrete notes."""
      harm_amp = np.zeros([n_batch, n_timesteps, 1])
      harm_dist = np.zeros([n_batch, n_timesteps, n_harmonics])
      f0_midi = np.zeros([n_batch, n_timesteps, 1])
      mags = np.zeros([n_batch, n_timesteps, n_mags])
  
      for b in range(n_batch):
          t_start = 0
          while t_start < n_timesteps:
              note_length = uniform_int(
                  min_note_length, max_note_length
              )
              t_end = min(t_start + note_length, n_timesteps)
              note_length = t_end - t_start
  
              # Silent?
              silent = flip(p_silent)
              if silent:
                  # Amplitudes.
                  ha_slice = harm_amp[b, t_start:t_end, :]
                  ha_slice -= 10.0
  
              else:
                  # Amplitudes.
                  amp_start = uniform_float(-1.0, 3.0)
                  amp_end = uniform_float(-1.0, 3.0)
                  amp_blend = random_blend(
                      note_length, amp_start, amp_end
                  )
                  ha_slice = harm_amp[b, t_start:t_end, :]
                  ha_slice += amp_blend[:, np.newaxis]
  
                  # Add some noise.
                  ha_slice += uniform_float(0.0, 0.1) * np.random.randn(
                      *ha_slice.shape
                  )
  
                  # Harmonic Distribution.
                  low_pass = flip(0.8)
                  rand_phase = uniform_float(0.0, 0.4)
                  harm_dist_start = random_harm_dist(
                      n_harmonics,
                      low_pass=low_pass,
                      rand_phase=rand_phase,
                  )[np.newaxis, :]
                  harm_dist_end = random_harm_dist(
                      n_harmonics,
                      low_pass=low_pass,
                      rand_phase=rand_phase,
                  )[np.newaxis, :]
                  blend = random_blend(note_length, 1.0, 0.0)[
                      :, np.newaxis
                  ]
                  harm_dist_blend = (
                      harm_dist_start * blend
                      + harm_dist_end * (1.0 - blend)
                  )
                  hd_slice = harm_dist[b, t_start:t_end, :]
                  hd_slice += harm_dist_blend
  
                  # Add some noise.
                  hd_slice += uniform_float(0.0, 0.5) * np.random.randn(
                      *hd_slice.shape
                  )
  
                  # Fundamental Frequency.
                  f0 = uniform_float(24.0, 84.0)
                  if flip(p_vibrato):
                      vib_start = uniform_float(0.0, 1.0)
                      vib_end = uniform_float(0.0, 1.0)
                      vib_periods = uniform_float(
                          0.0, note_length * 2.0 / min_note_length
                      )
                      vib_blend = random_blend(
                          note_length, vib_start, vib_end
                      )
                      vib = vib_blend * np.sin(
                          np.linspace(
                              0.0,
                              2.0 * np.pi * vib_periods,
                              note_length,
                          )
                      )
                      f0_note = f0 + vib
                  else:
                      f0_note = f0 * np.ones([note_length])
  
                  f0_slice = f0_midi[b, t_start:t_end, :]
                  f0_slice += f0_note[:, np.newaxis]
  
                  # Add some noise.
                  f0_slice += uniform_float(0.0, 0.1) * np.random.randn(
                      *f0_slice.shape
                  )
  
              # Filtered Noise.
              low_pass = flip(0.8)
              rand_phase = uniform_float(0.0, 0.4)
              mags_start = random_harm_dist(
                  n_mags, low_pass=low_pass, rand_phase=rand_phase
              )[np.newaxis, :]
              mags_end = random_harm_dist(
                  n_mags, low_pass=low_pass, rand_phase=rand_phase
              )[np.newaxis, :]
              blend = random_blend(note_length, 1.0, 0.0)[:, np.newaxis]
              mags_blend = mags_start * blend + mags_end * (1.0 - blend)
  
              mags_slice = mags[b, t_start:t_end, :]
              mags_slice += mags_blend
  
              # Add some noise.
              mags_slice += uniform_float(0.0, 0.2) * np.random.randn(
                  *mags_slice.shape
              )
  
              # # Scale.
              mags_slice -= uniform_float(1.0, 10.0)
  
              t_start = t_end
  
      if get_controls:
          harm_amp = ddsp.core.exp_sigmoid(harm_amp)
          harm_amp /= uniform_float(
              1.0, [2.0, uniform_float(2.0, 10.0)][flip(0.2)]
          )
  
      # Frequencies.
      f0_hz = ddsp.core.midi_to_hz(f0_midi)
  
      if get_controls:
          harm_dist = tf.nn.softmax(harm_dist)
          harm_dist = ddsp.core.remove_above_nyquist(f0_hz, harm_dist)
          harm_dist = ddsp.core.safe_divide(
              harm_dist,
              tf.reduce_sum(harm_dist, axis=-1, keepdims=True),
          )
  
      if get_controls:
          mags = ddsp.core.exp_sigmoid(mags)
  
      sin_amps, sin_freqs = ddsp.core.harmonic_to_sinusoidal(
          harm_amp, harm_dist, f0_hz
      )
  
      controls = {
          "harm_amp": harm_amp,
          "harm_dist": harm_dist,
          "f0_hz": f0_hz,
          "sin_amps": sin_amps,
          "sin_freqs": sin_freqs,
          "noise_magnitudes": mags,
      }
      return controls
  
file_path: ddsp/ddsp/training/data_preparation/synthetic_data.py
imports: import warnings
  import ddsp
  import gin
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 10 for calling a global function with example usage: generate_notes_v2(n_batch, n_timesteps, n_harmonics, n_mags, min_note_length, max_note_length, p_silent, p_vibrato, get_controls) and returns: controls