Class: Ray::Sound

Inherits:
AudioSource
  • Object
show all
Defined in:
lib/ray/sound.rb,
ext/sound.c

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ Sound

Returns a new instance of Sound.



3
4
5
6
7
8
9
10
11
# File 'lib/ray/sound.rb', line 3

def initialize(arg = nil)
  case arg
  when String      then self.buffer = SoundBufferSet[arg]
  when SoundBuffer then self.buffer = arg
  when nil         then return
  else
    self.buffer = SoundBuffer.new(arg)
  end
end

Instance Method Details

#bufferRay::SoundBuffer?

Returns:



36
37
38
39
# File 'ext/sound.c', line 36

static
VALUE ray_sound_buffer(VALUE self) {
  return rb_iv_get(self, "@buffer");
}

#buffer=(buf) ⇒ Object

Sets a new buffer for the sound. Causes it to stop playing.

Parameters:



28
29
30
31
32
33
# File 'ext/sound.c', line 28

static
VALUE ray_sound_set_buffer(VALUE self, VALUE buf) {
  say_sound_set_buffer(ray_rb2sound(self), ray_rb2sound_buffer(buf));
  rb_iv_set(self, "@buffer", buf);
  return buf;
}

#durationFloat

Returns Duration of the sound. 0 when no buffer is attached to the sound.

Returns:

  • (Float)

    Duration of the sound. 0 when no buffer is attached to the sound.



74
75
76
77
# File 'ext/sound.c', line 74

static
VALUE ray_sound_duration(VALUE self) {
  return rb_float_new(say_sound_get_duration(ray_rb2sound(self)));
}

#looping=(val) ⇒ Object



48
49
50
51
52
# File 'ext/sound.c', line 48

static
VALUE ray_sound_set_looping(VALUE self, VALUE val) {
  say_sound_set_looping(ray_rb2sound(self), RTEST(val));
  return val;
}

#looping?true, false

Returns True if the sound is looping.

Returns:

  • (true, false)

    True if the sound is looping



42
43
44
45
# File 'ext/sound.c', line 42

static
VALUE ray_sound_is_looping(VALUE self) {
  return say_sound_is_looping(ray_rb2sound(self)) ? Qtrue : Qfalse;
}

#pauseObject

Pauses the sound. Can be resumed using play.



87
88
89
90
91
# File 'ext/sound.c', line 87

static
VALUE ray_sound_pause(VALUE self) {
  say_sound_pause(ray_rb2sound(self));
  return self;
}

#playObject

Plays the sound (or resume from a pause)



80
81
82
83
84
# File 'ext/sound.c', line 80

static
VALUE ray_sound_play(VALUE self) {
  say_sound_play(ray_rb2sound(self));
  return self;
}

#pretty_print(q) ⇒ Object



13
14
15
# File 'lib/ray/sound.rb', line 13

def pretty_print(q)
  super q, ["time", "duration", "looping?", "buffer"]
end

#seek(time) ⇒ Object Also known as: time=

Seeks to a specific time in the sound.

Parameters:

  • time (Float)

    Time in seconds



59
60
61
62
63
# File 'ext/sound.c', line 59

static
VALUE ray_sound_seek(VALUE self, VALUE time) {
  say_sound_seek(ray_rb2sound(self), NUM2DBL(time));
  return time;
}

#stopObject

Stops the sound



94
95
96
97
98
# File 'ext/sound.c', line 94

static
VALUE ray_sound_stop(VALUE self) {
  say_sound_stop(ray_rb2sound(self));
  return self;
}

#timeFloat

Returns current playing offset, in seconds.

Returns:

  • (Float)

    current playing offset, in seconds



66
67
68
69
# File 'ext/sound.c', line 66

static
VALUE ray_sound_time(VALUE self) {
  return rb_float_new(say_sound_get_time(ray_rb2sound(self)));
}