def f(in_streams, out_streams, index, even, odd):
            def g(v):
                if (0 < index) and (index < N - 1):
                    if v % 2 == 0:
                        odd[index] = (even[index - 1] + even[index] +
                                      even[index + 1]) / 3.0
                    else:
                        even[index] = (odd[index - 1] + odd[index] +
                                       odd[index + 1]) / 3.0
                return v + 1

            def r(lst, state):
                if state < M:
                    return lst[0], state + 1
                else:
                    return _no_value, state

            for out_stream in out_streams:
                out_stream.extend([0])
            synch_stream = Stream('synch_stream')
            zip_map(r,
                    in_streams,
                    synch_stream,
                    state=0,
                    name='zip_map_' + str(index))
            map_element(g,
                        synch_stream,
                        out_streams[0],
                        name='grid' + str(index))
            run()
 def f_echo(in_streams, out_streams, delay):
     sound_made, attenuated = in_streams
     echo = Stream('echo')
     echo.extend([0] * delay)
     map_element(lambda v: v, attenuated, echo)
     # The zip_map output is the sound heard which is
     # the sound heard plus the echo.
     zip_map(sum, [sound_made, echo], out_streams[0])
Exemple #3
0
 def sum_echo_input(in_streams, out_streams):
     """
     Notes
     -----
     This function takes as input two streams: the input stream and the output of the 
     echo agent - i.e., the echo of the pitchshifted signal. It outputs
     one stream - the heard sound.
     """
     in_streams[1].extend(np.zeros(delay))
     zip_map(func=sum, in_streams=in_streams, out_stream=out_streams[0])
        def coordinate(in_streams, out_streams, total, num):
            x, sines, cosines, tangents = in_streams

            def f(lst):
                return lst[0] / lst[1]

            def g(lst):
                error_squared = (lst[0] - lst[1])**2
                return error_squared

            ratios = Stream('ratios')
            errors = Stream('errors')
            zip_map(f, [sines, cosines], ratios, name='sine / cosine')
            zip_map(g, [ratios, tangents], errors, name='compute error')
            print_stream(errors, 'error')
Exemple #5
0
def shimmer(original_sound_list, fs):
    """
    Paramters
    ---------
    original_sound_list: Input Sound
    fs: Sampling Frequency
    """

    delay = int(fs / 3)
    attenuation_vector = [0.6]
    input_stream = StreamArray('Input')
    heard = StreamArray('Output')
    pitch_out = StreamArray('PitchShift Output')

    echo = StreamArray(name='echo', initial_value=np.zeros(delay))
    # This below zip_map agent is the part that merges the output from Echo agent above and
    # The input stream
    zip_map(func=sum, in_streams=[input_stream, echo], out_stream=heard)

    # This below agent takes the output from the Pitch Shifter and then
    # Creates the Echo out of that sound that is fed as input to the zip_map agent above
    window_dot_product(in_stream=pitch_out,
                       out_stream=echo,
                       multiplicand_vector=attenuation_vector)

    window_size = 2**13
    h = 2**11
    n = 12
    factor = 2**(1.0 * n / 12.0)
    f = 1.0 / factor

    # Define the stretch agent
    y = StreamArray('y', dtype=np.int16)

    # The below is the Pitch Shift Agent
    stretch_object = Stretch(in_stream=heard,
                             out_stream=y,
                             factor=factor,
                             window_size=window_size,
                             h=h)

    sink_window(func=stretch_object.stretch,
                in_stream=heard,
                window_size=window_size + h,
                step_size=int(h * f))

    # Define the speedup agent.
    def f(window, out_stream):
        indices = np.arange(0, window_size, factor)
        out_stream.extend(
            np.int16(np.interp(indices, np.arange(window_size), window)) + 0.0)

    sink_window(func=f,
                in_stream=y,
                window_size=window_size,
                step_size=window_size,
                out_stream=pitch_out)

    input_stream.extend(original_sound_list)
    run()
    return recent_values(heard)
 def f(in_streams, out_streams, delay):
     sound_made, echo = in_streams
     echo.extend([0] * delay)
     # The zip_map output is the sound heard which is
     # the sound heard plus the echo.
     zip_map(sum, [sound_made, echo], out_streams[0])