sfml3.rb

Class: SFML::Sound

Inherits:
Object
  • Object
show all
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

Constructor Details

#new(buffer) ⇒ Sound

Creates a sound that plays the given buffer.

Raises:

  • (ArgumentError) —

    if buffer is not a SoundBuffer



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.

Returns:

  • (Float)

#attenuation=(value) ⇒ Float

Sets the distance-attenuation factor.

Returns:

  • (Float)

#buffer ⇒ SoundBuffer

Returns the buffer currently attached to this sound.

Returns:

Returns:

  • (SoundBuffer) —

    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).

Returns:

Returns:

Raises:

  • (ArgumentError) —

    if value is not a SoundBuffer



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.

Returns:

#cone=(value) ⇒ SoundSourceCone

Sets the source's directional attenuation cone.

Returns:

#copy ⇒ Sound

Creates an independent copy of the sound that shares its buffer.

Returns:

Returns:

  • (Sound) —

    an independent copy that shares the same SoundBuffer



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.

Returns:

#direction=(value) ⇒ Vector3

Sets the direction the source is facing.

Returns:

#directional_attenuation_factor ⇒ Float

Returns the factor controlling directional attenuation.

Returns:

  • (Float)

#directional_attenuation_factor=(value) ⇒ Float

Sets the factor controlling directional attenuation.

Returns:

  • (Float)

#doppler_factor ⇒ Float

Returns the factor by which the Doppler effect is scaled.

Returns:

  • (Float)

#doppler_factor=(value) ⇒ Float

Sets the factor by which the Doppler effect is scaled.

Returns:

  • (Float)

#effect_processor=(proc) ⇒ Proc

Installs a Proc that post-processes this source's audio in real time.

Returns:

  • (Proc) —

    proc

#looping=(value) ⇒ Boolean

Enables or disables looping.

Returns:

  • (Boolean)

#looping? ⇒ Boolean

Returns true if playback loops back to the start on completion.

Returns:

  • (Boolean)

#max_distance ⇒ Float

Returns the maximum distance of the distance-attenuation model.

Returns:

  • (Float)

#max_distance=(value) ⇒ Float

Sets the maximum distance of the distance-attenuation model.

Returns:

  • (Float)

#max_gain ⇒ Float

Returns the maximum gain of the distance-attenuation model.

Returns:

  • (Float)

#max_gain=(value) ⇒ Float

Sets the maximum gain of the distance-attenuation model.

Returns:

  • (Float)

#min_distance ⇒ Float

Returns the minimum distance of the distance-attenuation model.

Returns:

  • (Float)

#min_distance=(value) ⇒ Float

Sets the minimum distance of the distance-attenuation model.

Returns:

  • (Float)

#min_gain ⇒ Float

Returns the minimum gain of the distance-attenuation model.

Returns:

  • (Float)

#min_gain=(value) ⇒ Float

Sets the minimum gain of the distance-attenuation model.

Returns:

  • (Float)

#pan ⇒ Float

Returns the source's stereo pan.

Returns:

  • (Float) —

    stereo pan, -1 (left) to 1 (right)

#pan=(value) ⇒ Float

Sets the source's stereo pan.

Returns:

  • (Float)

#pause ⇒ self

Pauses playback, keeping the current playing offset.

Returns:

  • (self)

#pitch ⇒ Float

Returns the pitch scaling factor.

Returns:

  • (Float)

#pitch=(value) ⇒ Float

Sets the pitch scaling factor.

Returns:

  • (Float)

#play ⇒ self

Starts playback, or resumes it when paused.

Returns:

  • (self)

#playing_offset ⇒ Time

Returns the current playing offset.

Returns:

#playing_offset=(value) ⇒ Time

Seeks to the given playing offset.

Returns:

#position ⇒ Vector3

Returns the source's position in 3D space.

Returns:

#position=(value) ⇒ Vector3

Sets the source's position in 3D space.

Returns:

#relative_to_listener=(value) ⇒ Boolean

Makes the source relative to, or independent of, the listener.

Returns:

  • (Boolean)

#relative_to_listener? ⇒ Boolean

Returns true if the source is positioned relative to the listener.

Returns:

  • (Boolean)

#spatialization_enabled=(value) ⇒ Boolean

Enables or disables 3D spatialization.

Returns:

  • (Boolean)

#spatialization_enabled? ⇒ Boolean

Returns true if 3D spatialization is enabled.

Returns:

  • (Boolean)

#status ⇒ Symbol

Returns the current playback status.

Returns:

  • (Symbol) —

    one of :stopped, :paused, :playing

#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.

Returns:

  • (self)

#velocity ⇒ Vector3

Returns the source's velocity, used for Doppler calculations.

Returns:

#velocity=(value) ⇒ Vector3

Sets the source's velocity for Doppler calculations.

Returns:

#volume ⇒ Float

Returns the source's volume.

Returns:

  • (Float) —

    0 to 100

#volume=(value) ⇒ Float

Sets the source's volume.

Returns:

  • (Float)