Exemplo n.º 1
0
    def get_signal(self, amplitudes, harmonic_distribution, f0_hz):
        """Synthesize audio with additive synthesizer from controls.

    Args:
      amplitudes: Amplitude tensor of shape [batch, n_frames, 1]. Expects
        float32 that is strictly positive.
      harmonic_distribution: Tensor of shape [batch, n_frames, n_harmonics].
        Expects float32 that is strictly positive and normalized in the last
        dimension.
      f0_hz: The fundamental frequency in Hertz. Tensor of shape [batch,
        n_frames, 1].

    Returns:
      signal: A tensor of harmonic waves of shape [batch, n_samples].
    """
        signal = core.harmonic_synthesis(
            frequencies=f0_hz,
            amplitudes=amplitudes,
            harmonic_distribution=harmonic_distribution,
            n_samples=self.n_samples,
            sample_rate=self.sample_rate)
        return signal
Exemplo n.º 2
0
  def test_harmonic_synthesis_is_accurate_one_frequency(self,
                                                        batch_size,
                                                        fundamental_frequency,
                                                        amplitude,
                                                        n_frames):
    """Tests generating a single sine wave with different frame parameters.

    Generates sine waveforms with tensorflow and numpy and tests that they are
    the same. Test over a range of inputs provided by the parameterized
    inputs.

    Args:
      batch_size: Size of the batch to synthesize.
      fundamental_frequency: Base frequency of the oscillator in Hertz.
      amplitude: Amplitude of each harmonic in the waveform.
      n_frames: Number of amplitude envelope frames.
    """
    frequencies = fundamental_frequency * np.ones([batch_size, n_frames, 1])
    amplitudes = amplitude * np.ones([batch_size, n_frames, 1])

    frequencies_np = fundamental_frequency * np.ones([batch_size,
                                                      self.n_samples, 1])
    amplitudes_np = amplitude * np.ones([batch_size, self.n_samples, 1])

    # Create np test signal.
    wav_np = create_wave_np(batch_size, frequencies_np, amplitudes_np,
                            self.seconds, self.n_samples)

    with self.cached_session() as sess:
      wav_tf = sess.run(core.harmonic_synthesis(
          frequencies,
          amplitudes,
          n_samples=self.n_samples,
          sample_rate=self.sample_rate))
    pad = self.n_samples // n_frames  # Ignore edge effects.
    self.assertAllClose(wav_np[pad:-pad], wav_tf[pad:-pad])