Пример #1
0
def src_callback_new(callback, converter_type, channels):
    """Initialisation for the callback based API.

    Parameters
    ----------
    callback : function
        Called whenever new frames are to be read. Must return a NumPy array
        of shape (num_frames, channels).
    converter_type : int
        Converter to be used.
    channels : int
        Number of channels.

    Returns
    -------
    state
        An anonymous pointer to the internal state of the converter.
    handle
        A CFFI handle to the callback data.
    error : int
        Error code.

    """
    cb_data = {'callback': callback, 'channels': channels}
    handle = ffi.new_handle(cb_data)
    error = ffi.new('int*')
    state = _lib.src_callback_new(_src_input_callback, converter_type,
                                  channels, error, handle)
    if state == ffi.NULL:
        return None, handle, error[0]
    return state, handle, error[0]
Пример #2
0
def src_process(state, input_data, output_data, ratio, end_of_input=0):
    """Standard processing function.

    Returns non zero on error.
    """
    input_frames, _ = _check_data(input_data)
    output_frames, _ = _check_data(output_data)
    data = ffi.new('SRC_DATA*')
    data.input_frames = input_frames
    data.output_frames = output_frames
    data.src_ratio = ratio
    data.data_in = ffi.cast('float*', ffi.from_buffer(input_data))
    data.data_out = ffi.cast('float*', ffi.from_buffer(output_data))
    data.end_of_input = end_of_input
    error = _lib.src_process(state, data)
    return error, data.input_frames_used, data.output_frames_gen
Пример #3
0
def src_simple(input_data, output_data, ratio, converter_type, channels):
    """Perform a single conversion from an input buffer to an output buffer.

    Simple interface for performing a single conversion from input buffer to
    output buffer at a fixed conversion ratio. Simple interface does not require
    initialisation as it can only operate on a single buffer worth of audio.
    """
    input_frames, _ = _check_data(input_data)
    output_frames, _ = _check_data(output_data)
    data = ffi.new('SRC_DATA*')
    data.input_frames = input_frames
    data.output_frames = output_frames
    data.src_ratio = ratio
    data.data_in = ffi.cast('float*', ffi.from_buffer(input_data))
    data.data_out = ffi.cast('float*', ffi.from_buffer(output_data))
    error = _lib.src_simple(data, converter_type, channels)
    return error, data.input_frames_used, data.output_frames_gen
Пример #4
0
def src_new(converter_type, channels):
    """Initialise a new sample rate converter.

    Parameters
    ----------
    converter_type : int
        Converter to be used.
    channels : int
        Number of channels.

    Returns
    -------
    state
        An anonymous pointer to the internal state of the converter.
    error : int
        Error code.
    """
    error = ffi.new('int*')
    state = _lib.src_new(converter_type, channels, error)
    return state, error[0]
Пример #5
0
 def src_get_version(cls):
     return ffi.new('char[]', 'libsamplerate-0.1.9 (c) ...')