Class: AudioGlue::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_glue/builder.rb

Overview

Builds audio from a template instance.

Examples:

# Instantiate the builder with an adapter:
builder = AudioGlue::Builder.new(AudioGlue::PlainSoxAdapter.new)

# Create the template instance:
template = HiTemplate.new(:with_smalltalk => true)

# Build the output audio:
builder.build(template) # => audio as a binary string

Instance Method Summary collapse

Constructor Details

#initialize(adapter) ⇒ Builder

Returns a new instance of Builder.

Parameters:



15
16
17
# File 'lib/audio_glue/builder.rb', line 15

def initialize(adapter)
  @adapter = adapter
end

Instance Method Details

#build(template, opts = {}) ⇒ String

Build an audio file and return the result as a binary string.

Parameters:

Options Hash (opts):

  • :format (Symbol, String)
  • :rate (Integer, String)
  • :channels (Integer, String)

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
# File 'lib/audio_glue/builder.rb', line 29

def build(template, opts = {})
  format, rate, channels = opts[:format], opts[:rate], opts[:channels]

  packet =  template.build_snippet_packet
  packet.format   = format   if format
  packet.rate     = rate     if rate
  packet.channels = channels if channels

  @adapter.build(packet)
end