Class: Ray::AudioSource

Inherits:
Object
  • Object
show all
Includes:
PP
Defined in:
ext/audio_source.c,
lib/ray/audio_source.rb,
ext/audio_source.c

Overview

Audio sources are objects able to produce sound, either by directly passing them to a buffer or by streaming audio data.

This class holds generic methods to manipulate a source.

Instance Method Summary collapse

Methods included from PP

#pretty_print_attributes

Instance Method Details

#attenuationObject

See Also:



146
147
148
149
150
# File 'ext/audio_source.c', line 146

static
VALUE ray_audio_source_attenuation(VALUE self) {
  say_audio_source *source = ray_rb2audio_source(self);
  return rb_float_new(say_audio_source_get_attenuation(source));
}

#attenuation=(attenuation) ⇒ Object

Sets the attenuation of a sound

When set to 0, the sound will not be attenuated at all. 100 makes attenuation very quick.

Parameters:

  • atenuation (Float)

    New attenuation factor of the sound



161
162
163
164
165
166
# File 'ext/audio_source.c', line 161

static
VALUE ray_audio_source_set_attenuation(VALUE self, VALUE att) {
  rb_check_frozen(self);
  say_audio_source_set_attenuation(ray_rb2audio_source(self), NUM2DBL(att));
  return att;
}

#min_distanceObject

See Also:



120
121
122
123
124
# File 'ext/audio_source.c', line 120

static
VALUE ray_audio_source_min_distance(VALUE self) {
  say_audio_source *source = ray_rb2audio_source(self);
  return rb_float_new(say_audio_source_get_min_distance(source));
}

#min_distance=(dist) ⇒ Object

Sets the sounds minimal distance

The minimal distance is the distance beyound which a source’s volume will start decreasing. It is defaulted to one.

Parameters:

  • dist (Float)

    The new default value



135
136
137
138
139
140
141
142
143
# File 'ext/audio_source.c', line 135

static
VALUE ray_audio_source_set_min_distance(VALUE self, VALUE dist) {
  rb_check_frozen(self);

  say_audio_source *source = ray_rb2audio_source(self);
  say_audio_source_set_min_distance(source, NUM2DBL(dist));

  return dist;
}

#pitchObject

See Also:

  • ptich=


45
46
47
48
49
# File 'ext/audio_source.c', line 45

static
VALUE ray_audio_source_pitch(VALUE self) {
  say_audio_source *source = ray_rb2audio_source(self);
  return rb_float_new(say_audio_source_get_pitch(source));
}

#pitch=(pitch) ⇒ Object

Sets the pitch of the sound

Pitch makes the sound more acute or grave, and affcets playing speed. It is defaulted to 1.

Parameters:

  • pitch (Float)

    The new pitch value



60
61
62
63
64
65
66
67
68
# File 'ext/audio_source.c', line 60

static
VALUE ray_audio_source_set_pitch(VALUE self, VALUE pitch) {
  rb_check_frozen(self);

  say_audio_source *source = ray_rb2audio_source(self);
  say_audio_source_set_pitch(source, NUM2DBL(pitch));

  return pitch;
}

#posObject

See Also:



71
72
73
74
75
# File 'ext/audio_source.c', line 71

static
VALUE ray_audio_source_pos(VALUE self) {
  say_audio_source *source = ray_rb2audio_source(self);
  return ray_vector3_to_rb(say_audio_source_get_pos(source));
}

#pos=(pos) ⇒ Object

Sets the position of the sound

Parameters:



82
83
84
85
86
87
88
89
90
# File 'ext/audio_source.c', line 82

static
VALUE ray_audio_source_set_pos(VALUE self, VALUE pos) {
  rb_check_frozen(self);

  say_audio_source *source = ray_rb2audio_source(self);
  say_audio_source_set_pos(source, ray_convert_to_vector3(pos));

  return pos;
}

#pretty_print(q, other_attr = []) ⇒ Object



5
6
7
8
9
# File 'lib/ray/audio_source.rb', line 5

def pretty_print(q, other_attr = [])
  attr = ["pos", "relative?", "min_distance", "attenuation",
          "pitch", "status", "volume"]
  pretty_print_attributes q, attr + other_attr
end

#relative=(rel) ⇒ Object

Sets whether the sound position is relative to the listener’s

This is false by default, meaning the position is absolute.

Parameters:

  • rel (true, false)

    True to make the sound become relative



109
110
111
112
113
114
115
116
117
# File 'ext/audio_source.c', line 109

static
VALUE ray_audio_source_set_relative(VALUE self, VALUE val) {
  rb_check_frozen(self);

  say_audio_source *source = ray_rb2audio_source(self);
  say_audio_source_set_relative(source, RTEST(val));

  return val;
}

#relative?Boolean

Returns:

  • (Boolean)

See Also:



95
96
97
98
99
# File 'ext/audio_source.c', line 95

static
VALUE ray_audio_source_is_relative(VALUE self) {
  say_audio_source *source = ray_rb2audio_source(self);
  return say_audio_source_get_relative(source) ? Qtrue : Qfalse;
}

#statusSymbol

Playing status

The status can be :playing, :paused, or :stopped.

Returns:

  • (Symbol)

    Playing status



175
176
177
178
179
180
181
182
183
184
# File 'ext/audio_source.c', line 175

static
VALUE ray_audio_source_status(VALUE self) {
  switch (say_audio_source_get_status(ray_rb2audio_source(self))) {
  case SAY_STATUS_PAUSED:  return RAY_SYM("paused");
  case SAY_STATUS_PLAYING: return RAY_SYM("playing");
  case SAY_STATUS_STOPPED: return RAY_SYM("stopped");
  }

  return Qnil; /* should never happen */
}

#volumeObject

See Also:



19
20
21
22
23
# File 'ext/audio_source.c', line 19

static
VALUE ray_audio_source_volume(VALUE self) {
  say_audio_source *source = ray_rb2audio_source(self);
  return rb_float_new(say_audio_source_get_volume(source));
}

#volume=(vol) ⇒ Object

Sets the volume of the source

The volume is a number between 0 and 100. When it is set to 100, the volume is maximal.

Parameters:

  • vol (Float)

    The new volume of the source



34
35
36
37
38
39
40
41
42
# File 'ext/audio_source.c', line 34

static
VALUE ray_audio_source_set_volume(VALUE self, VALUE value) {
  rb_check_frozen(self);

  say_audio_source *source = ray_rb2audio_source(self);
  say_audio_source_set_volume(source, NUM2DBL(value));

  return value;
}