Class: Ray::SoundBuffer

Inherits:
Object
  • Object
show all
Extended by:
ResourceSet
Defined in:
lib/ray/sound_buffer.rb,
ext/sound_buffer.c

Instance Method Summary collapse

Methods included from ResourceSet

[], add_set, clear, missing_pattern, reject!, select!, set_hash

Constructor Details

#initialize(io_or_string) ⇒ Object

Loads the sound buffer out of an IO object or a string.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'ext/sound_buffer.c', line 27

static
VALUE ray_sound_buffer_init(VALUE self, VALUE arg) {
  say_sound_buffer *buf = ray_rb2sound_buffer(self);

  if (rb_respond_to(arg, RAY_METH("read"))) {
    arg = rb_funcall(arg, RAY_METH("read"), 0);

    if (!say_sound_buffer_load_from_memory(buf, RSTRING_LEN(arg),
                                           StringValuePtr(arg))) {
      rb_raise(rb_eRangeError, "%s", say_error_get_last());
    }
  }
  else {
    if (!say_sound_buffer_load_from_file(buf, StringValuePtr(arg))) {
      rb_raise(rb_eRangeError, "%s", say_error_get_last());
    }
  }

  return self;
}

Instance Method Details

#channel_countInteger

Returns amount of channels in the sound.

Returns:

  • (Integer)

    amount of channels in the sound



55
56
57
58
# File 'ext/sound_buffer.c', line 55

static
VALUE ray_sound_buffer_channel_count(VALUE self) {
  return INT2FIX(say_sound_buffer_get_channel_count(ray_rb2sound_buffer(self)));
}

#durationFloat

Returns duration of the sound in seconds.

Returns:

  • (Float)

    duration of the sound in seconds



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

static
VALUE ray_sound_buffer_duration(VALUE self) {
  return rb_float_new(say_sound_buffer_get_duration(ray_rb2sound_buffer(self)));
}

#sample_rateInteger

Returns sample rate.

Returns:

  • (Integer)

    sample rate



61
62
63
64
# File 'ext/sound_buffer.c', line 61

static
VALUE ray_sound_buffer_sample_rate(VALUE self) {
  return INT2FIX(say_sound_buffer_get_sample_rate(ray_rb2sound_buffer(self)));
}