code: def magnitude_to_decibel(
      x, ref_value=1.0, amin=1e-5, dynamic_range=80.0
  ):
      """A function that converts magnitude to decibel scaling.
      In essence, it runs `10 * log10(x)`, but with some other utility operations.
  
      Similar to `librosa.power_to_db` with `ref=1.0` and `top_db=dynamic_range`
  
      Args:
          x (`Tensor`): float tensor. Can be batch or not. Something like magnitude of STFT.
          ref_value (`float`): an input value that would become 0 dB in the result.
              For spectrogram magnitudes, ref_value=1.0 usually make the decibel-scaled output to be around zero
              if the input audio was in [-1, 1].
          amin (`float`): the noise floor of the input. An input that is smaller than `amin`, it's converted to `amin`.
          dynamic_range (`float`): range of the resulting value. E.g., if the maximum magnitude is 30 dB,
              the noise floor of the output would become (30 - dynamic_range) dB
  
      Returns:
          log_spec (`Tensor`): a decibel-scaled version of `x`.
  
      Note:
          In many deep learning based application, the input spectrogram magnitudes (e.g., abs(STFT)) are decibel-scaled
          (=logarithmically mapped) for a better performance.
  
      Example:
          ::
  
              input_shape = (2048, 1)  # mono signal
              model = Sequential()
              model.add(kapre.Frame(frame_length=1024, hop_length=512, input_shape=input_shape))
              # now the shape is (batch, n_frame=3, frame_length=1024, ch=1)
  
      """
  
      def _log10(x):
          return tf.math.log(x) / tf.math.log(
              tf.constant(10, dtype=x.dtype)
          )
  
      if K.ndim(x) > 1:  # we assume x is batch in this case
          max_axis = tuple(range(K.ndim(x))[1:])
      else:
          max_axis = None
  
      if amin is None:
          amin = 1e-5
  
      amin = tf.cast(amin, dtype=x.dtype)
      log_spec = 10.0 * _log10(tf.math.maximum(x, amin))
      log_spec = log_spec - 10.0 * _log10(
          tf.math.maximum(amin, ref_value)
      )
  
      log_spec = tf.math.maximum(
          log_spec,
          tf.math.reduce_max(log_spec, axis=max_axis, keepdims=True)
          - dynamic_range,
      )
  
      return log_spec
  
file_path: kapre/kapre/backend.py
imports: from tensorflow.keras import backend
  import tensorflow
  import numpy
  import librosa
label_desc: Use image node_id 3 for calling a global function with example usage: magnitude_to_decibel(x, ref_value, amin, dynamic_range) and returns: log_spec, unknown