Class: WaitUp::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/wait_up/pipeline.rb

Overview

Wait Up pipeline class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, tempo) ⇒ Pipeline

Returns a new instance of Pipeline.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wait_up/pipeline.rb', line 8

def initialize(filename, tempo)
  @filename = filename
  @tempo = tempo

  play_bin.set_property 'uri', "file://#{File.absolute_path(filename)}"

  sink_bin.add audiosink
  sink_bin.add postconverter
  sink_bin.add speed_changer

  speed_changer.link_many [postconverter, audiosink]

  sink_pad = Gst::GhostPad.new 'sink', speed_changer.iterate_sink_pads.first
  sink_bin.add_pad sink_pad

  play_bin.set_property 'audio-sink', GObject::Value.wrap_instance(sink_bin)
  play_bin.set_state :paused
  play_bin.get_state(-1)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/wait_up/pipeline.rb', line 6

def filename
  @filename
end

#tempoObject (readonly)

Returns the value of attribute tempo.



6
7
8
# File 'lib/wait_up/pipeline.rb', line 6

def tempo
  @tempo
end

Instance Method Details

#audiosinkObject



46
47
48
# File 'lib/wait_up/pipeline.rb', line 46

def audiosink
  @audiosink ||= Gst::ElementFactory.make('autoaudiosink', 'audiosink')
end

#playObject



28
29
30
# File 'lib/wait_up/pipeline.rb', line 28

def play
  play_bin.set_state :playing
end

#play_binObject



32
33
34
# File 'lib/wait_up/pipeline.rb', line 32

def play_bin
  @play_bin ||= Gst::ElementFactory.make 'playbin', nil
end

#postconverterObject



50
51
52
# File 'lib/wait_up/pipeline.rb', line 50

def postconverter
  @postconverter ||= Gst::ElementFactory.make('audioconvert', 'postconverter')
end

#preconverterObject



54
55
56
# File 'lib/wait_up/pipeline.rb', line 54

def preconverter
  @preconverter ||= Gst::ElementFactory.make('audioconvert', 'preconverter')
end

#sink_binObject



36
37
38
# File 'lib/wait_up/pipeline.rb', line 36

def sink_bin
  @sink_bin ||= Gst::Bin.new('sinkbin')
end

#speed_changerObject



40
41
42
43
44
# File 'lib/wait_up/pipeline.rb', line 40

def speed_changer
  @speed_changer ||= Gst::ElementFactory.make('pitch', 'speed changer').tap do |element|
    element.set_property 'tempo', tempo
  end
end