code: def crop_or_pad(waves, length, channels):
      """Crop or pad wave to have shape [N, length, channels].
  
      Args:
        waves: A 3D `Tensor` of NLC format.
        length: A Python scalar. The output wave size.
        channels: Number of output waves channels.
  
      Returns:
        A 3D `Tensor` of NLC format with shape [N, length, channels].
      """
      waves = tf.convert_to_tensor(waves)
      batch_size = int(waves.shape[0])
      waves_shape = tf.shape(waves)
  
      # Force audio length.
      pad = tf.maximum(0, length - waves_shape[1])
      right_pad = tf.to_int32(tf.to_float(pad) / 2.0)
      left_pad = pad - right_pad
      waves = tf.pad(waves, [[0, 0], [left_pad, right_pad], [0, 0]])
      waves = waves[:, :length, :]
  
      # Force number of channels.
      num_repeats = tf.to_int32(
          tf.ceil(tf.to_float(channels) / tf.to_float(waves_shape[2]))
      )
      waves = tf.tile(waves, [1, 1, num_repeats])[:, :, :channels]
  
      waves.set_shape([batch_size, length, channels])
      return waves
  
file_path: magenta/magenta/models/gansynth/lib/spectral_ops.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 9 for calling a global function with example usage: crop_or_pad(waves, length, channels) and returns: waves