code: def signal_frame(
      signal, index, frame_size, hop_size, origin=0, pad=0
  ):
      """
      This function returns frame at `index` of the `signal`.
  
      Parameters
      ----------
      signal : numpy array
          Signal.
      index : int
          Index of the frame to return.
      frame_size : int
          Size of each frame in samples.
      hop_size : float
          Hop size in samples between adjacent frames.
      origin : int
          Location of the window center relative to the signal position.
      pad : int, float or str, optional
          Pad parts of the frame not covered by the signal with this value.
          The literal 'repeat' can be used to indicate that the first/last value
          should be repeated.
  
      Returns
      -------
      frame : numpy array
          Requested frame of the signal.
  
      Notes
      -----
      The reference sample of the first frame (index == 0) refers to the first
      sample of the `signal`, and each following frame is placed `hop_size`
      samples after the previous one.
  
      The window is always centered around this reference sample. Its location
      relative to the reference sample can be set with the `origin` parameter.
      Arbitrary integer values can be given:
  
      - zero centers the window on its reference sample
      - negative values shift the window to the right
      - positive values shift the window to the left
  
      An `origin` of half the size of the `frame_size` results in windows located
      to the left of the reference sample, i.e. the first frame starts at the
      first sample of the signal.
  
      The part of the frame which is not covered by the signal is padded with
      zeros.
  
      This function is totally independent of the length of the signal. Thus,
      contrary to common indexing, the index '-1' refers NOT to the last frame
      of the signal, but instead the frame left of the first frame is returned.
  
      """
      # cast variables to int
      frame_size = int(frame_size)
      # length of the signal
      num_samples = len(signal)
      # seek to the correct position in the audio signal
      ref_sample = int(index * hop_size)
      # position the window
      start = ref_sample - frame_size // 2 - int(origin)
      stop = start + frame_size
      # return the requested portion of the signal
      # Note: use NumPy's advanced indexing (i.e. trailing comma) in order to
      #       avoid a memory leak (issue #321). This returns a copy of the data,
      #       however, returning a simple copy of the relevant portion of the
      #       signal also leaks memory
      # Update: removing this hack again, since it seems that it is not needed
      #         any more with recent NumPy versions
      if start >= 0 and stop <= num_samples:
          # normal read operation, return appropriate section
          return signal[start:stop]
  
      # part of the frame falls outside the signal, padding needed
      # Note: np.pad(signal[from: to], (pad_left, pad_right), mode='constant')
      #       always returns a ndarray, not the subclass (and is slower);
      #       usually np.zeros_like(signal[:frame_size]) is exactly what we want
      #       (i.e. zeros of frame_size length and the same type/class as the
      #       signal and not just the dtype), but since we have no guarantee that
      #       the signal is that long, we have to use the np.repeat workaround
      frame = np.repeat(signal[:1], frame_size, axis=0)
  
      # determine how many samples need to be padded from left/right
      left, right = 0, 0
      if start < 0:
          left = min(stop, 0) - start
          # repeat beginning of signal
          frame[:left] = np.repeat(signal[:1], left, axis=0)
          if pad != "repeat":
              frame[:left] = pad
          start = 0
      if stop > num_samples:
          right = stop - max(start, num_samples)
          # repeat end of signal
          frame[-right:] = np.repeat(signal[-1:], right, axis=0)
          if pad != "repeat":
              frame[-right:] = pad
          stop = num_samples
  
      # position signal inside frame
      frame[left : frame_size - right] = signal[
          min(start, num_samples) : max(stop, 0)
      ]
      # return the frame
      return frame
  
imports: from __future__ import absolute_import, division, print_function
  import warnings
  import numpy
  from ..processors import BufferProcessor, Processor
  from ..utils import integer_types
label_desc: Use image node_id 15 for calling a global function with example usage: signal_frame(signal, index, frame_size, hop_size, origin, pad) and returns: frame, signal