Module: Awaaz::Extensions::Samplerate

Extended by:
FFI::Library
Defined in:
lib/awaaz/extensions/samplerate.rb

Overview

The Samplerate module provides Ruby bindings to the ‘libsamplerate` C library using the FFI (Foreign Function Interface).

This module enables high-quality audio resampling directly from Ruby.

Defined Under Namespace

Classes: SRC_DATA

Constant Summary collapse

SRC_SINC_BEST_QUALITY =

Best quality sinc-based sample rate converter.

0
SRC_SINC_MEDIUM_QUALITY =

Medium quality sinc-based converter.

1
SRC_SINC_FASTEST =

Fastest sinc-based converter (lower quality).

2
SRC_ZERO_ORDER_HOLD =

Zero-order hold converter (lowest quality, fastest).

3
SRC_LINEAR =

Linear interpolation converter (low quality, very fast).

4

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resample_option(option) ⇒ Integer

Maps a symbolic or numeric option to a libsamplerate converter type constant.

Examples:

Using symbols

Extensions::Samplerate.resample_option(:sinc_best_quality)
# => 0

Using integers

Extensions::Samplerate.resample_option(:linear)
# => 4

Parameters:

  • option (Integer, Symbol)

    Converter type, either as an integer constant or a symbol (:sinc_best_quality, :linear, etc.).

Returns:

  • (Integer)

    The corresponding converter type constant.

Raises:

  • (ArgumentError)

    If the option is not recognized.



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/awaaz/extensions/samplerate.rb', line 100

def resample_option(option)
  case option
  when 0, :sinc_best_quality then SRC_SINC_BEST_QUALITY
  when 1, :sinc_medium_quality then SRC_SINC_MEDIUM_QUALITY
  when 2, :sinc_fastest then SRC_SINC_FASTEST
  when 3, :zero_order_hold then SRC_ZERO_ORDER_HOLD
  when 4, :linear then SRC_LINEAR
  else
    raise ArgumentError, "Not found"
  end
end

Instance Method Details

#src_simpleObject

Performs a simple sample rate conversion.



59
# File 'lib/awaaz/extensions/samplerate.rb', line 59

attach_function :src_simple, [SRC_DATA.by_ref, :int, :int], :int

#src_strerrorString

Converts an error code to a human-readable error message.

Returns:

  • (String)

    Human-readable error message.



65
# File 'lib/awaaz/extensions/samplerate.rb', line 65

attach_function :src_strerror, [:int], :string