Module: EasyAudio

Defined in:
lib/easy_audio.rb

Overview

Easy Audio is a library to simplify the Portaudio interface

Defined Under Namespace

Modules: Waveforms Classes: EasyStream, Stream, StreamPacket

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.easy_open(opts = {}) { ... } ⇒ Object

Quickly opens an EasyStream and calls EasyAudio::Stream#start.

Examples:

Process audio from input (microphone) and playback on output

EasyAudio.easy_open(in: true, out: true) { current_sample }

Play a sine wave.

EasyAudio.easy_open(&EasyAudio::Waveforms::SINE)

Play a square wave.

EasyAudio.easy_open(&EasyAudio::Waveforms::SQUARE)

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :freq (Float) — default: 440.0

    the frequency to generate #step values at.

  • :amp (Float) — default: 1.0

    the amplitude to scale values to.

  • :sample_rate (Fixnum) — default: 44100

    the sample rate to play at.

  • :frame_size (Fixnum) — default: 256

    the number of frames per buffer.

  • :in (Boolean)

    whether to use the default input device.

  • :out (Boolean)

    whether to use the default output device.

  • :in_chans (Fixnum) — default: 2

    the number of channels to process from the input device.

  • :out_chans (Fixnum) — default: 2

    the number of channels to process from the output device.

  • :latency (Float) — default: 0.0

    the default latency for processing.

Yields:

  • a process block that processes one frame at a time.

Yield Returns:

  • (Array<Float>)

    return an array of interlaced floating points for each channel in #output_channels.

See Also:



218
219
220
# File 'lib/easy_audio.rb', line 218

def easy_open(opts = {}, &block)
  EasyStream.new(opts, &block).tap {|s| s.start }
end

.open(opts = {}) {|buffer| ... } ⇒ Object

Quickly opens a Stream and calls EasyAudio::Stream#start.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :sample_rate (Fixnum) — default: 44100

    the sample rate to play at.

  • :frame_size (Fixnum) — default: 256

    the number of frames per buffer.

  • :in (Boolean)

    whether to use the default input device.

  • :out (Boolean)

    whether to use the default output device.

  • :in_chans (Fixnum) — default: 2

    the number of channels to process from the input device.

  • :out_chans (Fixnum) — default: 2

    the number of channels to process from the output device.

  • :latency (Float) — default: 0.0

    the default latency for processing.

Yields:

  • (buffer)

    runs the provided block against the sample buffer data

Yield Parameters:

Yield Returns:

  • (Array<Float>)

    return an array of interlaced floating points for each channel in #output_channels.



202
203
204
# File 'lib/easy_audio.rb', line 202

def open(opts = {}, &block)
  Stream.new(opts, &block).tap {|s| s.start }
end