Class: SFML::Sound
- Inherits:
-
Object
- Object
- SFML::Sound
- Defined in:
- ext/audio/sound.c,
ext/audio/sound.c
Overview
A sound playing directly from a SoundBuffer held fully in memory. Suited to short effects; for long files prefer Music, which streams instead.
Instance Method Summary collapse
-
#attenuation ⇒ Float
Returns the distance-attenuation factor.
-
#attenuation=(value) ⇒ Float
Sets the distance-attenuation factor.
-
#buffer ⇒ SoundBuffer
Returns the buffer currently attached to this sound.
-
#buffer=(value) ⇒ SoundBuffer
Attaches a new SoundBuffer.
-
#cone ⇒ SoundSourceCone
Returns the source's directional attenuation cone.
-
#cone=(value) ⇒ SoundSourceCone
Sets the source's directional attenuation cone.
-
#copy ⇒ Sound
Creates an independent copy of the sound that shares its buffer.
-
#direction ⇒ Vector3
Returns the direction the source is facing.
-
#direction=(value) ⇒ Vector3
Sets the direction the source is facing.
-
#directional_attenuation_factor ⇒ Float
Returns the factor controlling directional attenuation.
-
#directional_attenuation_factor=(value) ⇒ Float
Sets the factor controlling directional attenuation.
-
#doppler_factor ⇒ Float
Returns the factor by which the Doppler effect is scaled.
-
#doppler_factor=(value) ⇒ Float
Sets the factor by which the Doppler effect is scaled.
-
#effect_processor=(proc) ⇒ Proc
Installs a Proc that post-processes this source's audio in real time.
-
#new(buffer) ⇒ Sound
constructor
Creates a sound that plays the given buffer.
-
#looping=(value) ⇒ Boolean
Enables or disables looping.
-
#looping? ⇒ Boolean
Returns
trueif playback loops back to the start on completion. -
#max_distance ⇒ Float
Returns the maximum distance of the distance-attenuation model.
-
#max_distance=(value) ⇒ Float
Sets the maximum distance of the distance-attenuation model.
-
#max_gain ⇒ Float
Returns the maximum gain of the distance-attenuation model.
-
#max_gain=(value) ⇒ Float
Sets the maximum gain of the distance-attenuation model.
-
#min_distance ⇒ Float
Returns the minimum distance of the distance-attenuation model.
-
#min_distance=(value) ⇒ Float
Sets the minimum distance of the distance-attenuation model.
-
#min_gain ⇒ Float
Returns the minimum gain of the distance-attenuation model.
-
#min_gain=(value) ⇒ Float
Sets the minimum gain of the distance-attenuation model.
-
#pan ⇒ Float
Returns the source's stereo pan.
-
#pan=(value) ⇒ Float
Sets the source's stereo pan.
-
#pause ⇒ self
Pauses playback, keeping the current playing offset.
-
#pitch ⇒ Float
Returns the pitch scaling factor.
-
#pitch=(value) ⇒ Float
Sets the pitch scaling factor.
-
#play ⇒ self
Starts playback, or resumes it when paused.
-
#playing_offset ⇒ Time
Returns the current playing offset.
-
#playing_offset=(value) ⇒ Time
Seeks to the given playing offset.
-
#position ⇒ Vector3
Returns the source's position in 3D space.
-
#position=(value) ⇒ Vector3
Sets the source's position in 3D space.
-
#relative_to_listener=(value) ⇒ Boolean
Makes the source relative to, or independent of, the listener.
-
#relative_to_listener? ⇒ Boolean
Returns
trueif the source is positioned relative to the listener. -
#spatialization_enabled=(value) ⇒ Boolean
Enables or disables 3D spatialization.
-
#spatialization_enabled? ⇒ Boolean
Returns
trueif 3D spatialization is enabled. -
#status ⇒ Symbol
Returns the current playback status.
-
#stop ⇒ self
Stops playback and rewinds to the beginning.
-
#velocity ⇒ Vector3
Returns the source's velocity, used for Doppler calculations.
-
#velocity=(value) ⇒ Vector3
Sets the source's velocity for Doppler calculations.
-
#volume ⇒ Float
Returns the source's volume.
-
#volume=(value) ⇒ Float
Sets the source's volume.
Constructor Details
#new(buffer) ⇒ Sound
Creates a sound that plays the given buffer.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'ext/audio/sound.c', line 102
static VALUE Sound_initialize(VALUE self, VALUE rb_buffer) {
Sound* sound;
sfSound* handle;
if (!rb_obj_is_kind_of(rb_buffer, Get_Klass_SoundBuffer())) {
raise_invalid_argument_class(Get_Klass_SoundBuffer());
}
sound = (Sound*)Get_Sound_Struct(self);
handle = sfSound_create(Get_SoundBuffer_Struct(rb_buffer));
if (handle == NULL) {
rb_raise(rb_eRuntimeError, "failed to create sound");
}
sound->source.handle = handle;
sound->rb_buffer = rb_buffer;
return self;
}
|
Instance Method Details
#attenuation ⇒ Float
Returns the distance-attenuation factor.
#attenuation=(value) ⇒ Float
Sets the distance-attenuation factor.
#buffer ⇒ SoundBuffer
Returns the buffer currently attached to this sound.
143 144 145 |
# File 'ext/audio/sound.c', line 143
static VALUE Sound_get_buffer(VALUE self) {
return ((Sound*)Get_Sound_Struct(self))->rb_buffer;
}
|
#buffer=(value) ⇒ SoundBuffer
Attaches a new SoundBuffer. If a buffer is already attached and the sound is playing, it is stopped first, which may briefly block the calling thread (see #stop).
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'ext/audio/sound.c', line 173
static VALUE Sound_set_buffer(VALUE self, VALUE rb_buffer) {
Sound* sound = (Sound*)Get_Sound_Struct(self);
SoundSetBufferArgs args;
if (!rb_obj_is_kind_of(rb_buffer, Get_Klass_SoundBuffer())) {
raise_invalid_argument_class(Get_Klass_SoundBuffer());
}
args.handle = sound->source.handle;
args.buffer = Get_SoundBuffer_Struct(rb_buffer);
rb_thread_call_without_gvl(Sound_set_buffer_without_gvl, &args, RUBY_UBF_IO, NULL);
sound->rb_buffer = rb_buffer;
return rb_buffer;
}
|
#cone ⇒ SoundSourceCone
Returns the source's directional attenuation cone.
#cone=(value) ⇒ SoundSourceCone
Sets the source's directional attenuation cone.
#copy ⇒ Sound
Creates an independent copy of the sound that shares its buffer.
130 131 132 133 134 135 |
# File 'ext/audio/sound.c', line 130
static VALUE Sound_copy(VALUE self) {
Sound* sound = (Sound*)Get_Sound_Struct(self);
return Sound_wrap(Get_Klass_Sound(), sfSound_copy((const sfSound*)sound->source.handle),
sound->rb_buffer);
}
|
#direction ⇒ Vector3
Returns the direction the source is facing.
#direction=(value) ⇒ Vector3
Sets the direction the source is facing.
#directional_attenuation_factor ⇒ Float
Returns the factor controlling directional attenuation.
#directional_attenuation_factor=(value) ⇒ Float
Sets the factor controlling directional attenuation.
#doppler_factor ⇒ Float
Returns the factor by which the Doppler effect is scaled.
#doppler_factor=(value) ⇒ Float
Sets the factor by which the Doppler effect is scaled.
#effect_processor=(proc) ⇒ Proc
Installs a Proc that post-processes this source's audio in real time.
#looping=(value) ⇒ Boolean
Enables or disables looping.
#looping? ⇒ Boolean
Returns true if playback loops back to the start on completion.
#max_distance ⇒ Float
Returns the maximum distance of the distance-attenuation model.
#max_distance=(value) ⇒ Float
Sets the maximum distance of the distance-attenuation model.
#max_gain ⇒ Float
Returns the maximum gain of the distance-attenuation model.
#max_gain=(value) ⇒ Float
Sets the maximum gain of the distance-attenuation model.
#min_distance ⇒ Float
Returns the minimum distance of the distance-attenuation model.
#min_distance=(value) ⇒ Float
Sets the minimum distance of the distance-attenuation model.
#min_gain ⇒ Float
Returns the minimum gain of the distance-attenuation model.
#min_gain=(value) ⇒ Float
Sets the minimum gain of the distance-attenuation model.
#pan ⇒ Float
Returns the source's stereo pan.
#pan=(value) ⇒ Float
Sets the source's stereo pan.
#pause ⇒ self
Pauses playback, keeping the current playing offset.
#pitch ⇒ Float
Returns the pitch scaling factor.
#pitch=(value) ⇒ Float
Sets the pitch scaling factor.
#play ⇒ self
Starts playback, or resumes it when paused.
#playing_offset ⇒ Time
Returns the current playing offset.
#playing_offset=(value) ⇒ Time
Seeks to the given playing offset.
#position ⇒ Vector3
Returns the source's position in 3D space.
#position=(value) ⇒ Vector3
Sets the source's position in 3D space.
#relative_to_listener=(value) ⇒ Boolean
Makes the source relative to, or independent of, the listener.
#relative_to_listener? ⇒ Boolean
Returns true if the source is positioned relative to the listener.
#spatialization_enabled=(value) ⇒ Boolean
Enables or disables 3D spatialization.
#spatialization_enabled? ⇒ Boolean
Returns true if 3D spatialization is enabled.
#status ⇒ Symbol
Returns the current playback status.
#stop ⇒ self
Stops playback and rewinds to the beginning. May briefly block the calling thread if an audio-thread callback for this source is in flight.
#velocity ⇒ Vector3
Returns the source's velocity, used for Doppler calculations.
#velocity=(value) ⇒ Vector3
Sets the source's velocity for Doppler calculations.
#volume ⇒ Float
Returns the source's volume.
#volume=(value) ⇒ Float
Sets the source's volume.