Class: SFML::Music
- Inherits:
-
Object
- Object
- SFML::Music
- Defined in:
- ext/audio/music.c,
ext/audio/music.c
Overview
Music streamed from a file, memory buffer or InputStream rather than held fully decoded in memory, so it's suited to long tracks that would be wasteful to load whole as a SoundBuffer.
Class Method Summary collapse
-
.from_file(path) ⇒ Music
Creates a music stream that reads from an audio file.
-
.from_memory(data) ⇒ Music
Creates a music stream that reads from audio held in a String.
-
.from_stream(stream) ⇒ Music
Creates a music stream that reads from a custom InputStream.
Instance Method Summary collapse
-
#attenuation ⇒ Float
Returns the distance-attenuation factor.
-
#attenuation=(value) ⇒ Float
Sets the distance-attenuation factor.
-
#channel_count ⇒ Integer
Returns the number of audio channels in the music.
-
#channel_map ⇒ Array<Symbol>
Returns the channel layout of the music.
-
#cone ⇒ SoundSourceCone
Returns the source's directional attenuation cone.
-
#cone=(value) ⇒ SoundSourceCone
Sets the source's directional attenuation cone.
-
#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.
-
#duration ⇒ Time
Returns the total duration of the music.
-
#effect_processor=(proc) ⇒ Proc
Installs a Proc that post-processes this source's audio in real time.
-
#loop_points ⇒ Array, Time
Returns the loop points as an
[offset, length]pair. -
#loop_points=(value) ⇒ Array, Time
Sets the loop points as a two-element
[offset, length]pair. -
#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. -
#sample_rate ⇒ Integer
Returns the music's sample rate in samples per second.
-
#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.
Class Method Details
.from_file(path) ⇒ Music
Creates a music stream that reads from an audio file.
86 87 88 |
# File 'ext/audio/music.c', line 86
static VALUE Music_from_file(VALUE klass, VALUE rb_path) {
return Music_wrap(klass, sfMusic_createFromFile(StringValueCStr(rb_path)), Qnil);
}
|
.from_memory(data) ⇒ Music
Creates a music stream that reads from audio held in a String.
98 99 100 101 102 103 |
# File 'ext/audio/music.c', line 98
static VALUE Music_from_memory(VALUE klass, VALUE rb_data) {
StringValue(rb_data);
return Music_wrap(
klass, sfMusic_createFromMemory(RSTRING_PTR(rb_data), (size_t)RSTRING_LEN(rb_data)), Qnil);
}
|
.from_stream(stream) ⇒ Music
Creates a music stream that reads from a custom InputStream.
113 114 115 116 117 118 |
# File 'ext/audio/music.c', line 113
static VALUE Music_from_stream(VALUE klass, VALUE rb_stream) {
VALUE holder = Qnil;
sfInputStream* stream = input_stream_from_rb(rb_stream, &holder);
return Music_wrap(klass, sfMusic_createFromStream(stream), holder);
}
|
Instance Method Details
#attenuation ⇒ Float
Returns the distance-attenuation factor.
#attenuation=(value) ⇒ Float
Sets the distance-attenuation factor.
#channel_count ⇒ Integer
Returns the number of audio channels in the music.
136 137 138 |
# File 'ext/audio/music.c', line 136 static VALUE Music_channel_count(VALUE self) { return UINT2NUM(sfMusic_getChannelCount(Get_Music_Struct(self))); } |
#channel_map ⇒ Array<Symbol>
Returns the channel layout of the music.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'ext/audio/music.c', line 157
static VALUE Music_channel_map(VALUE self) {
size_t count = 0;
const sfSoundChannel* map = sfMusic_getChannelMap(Get_Music_Struct(self), &count);
VALUE rb_array;
size_t i;
if (map == NULL) {
return rb_ary_new();
}
rb_array = rb_ary_new_capa((long)count);
for (i = 0; i < count; i++) {
rb_ary_push(rb_array, ID2SYM(rb_intern(sound_channel_name(map[i]))));
}
return rb_array;
}
|
#cone ⇒ SoundSourceCone
Returns the source's directional attenuation cone.
#cone=(value) ⇒ SoundSourceCone
Sets the source's directional attenuation cone.
#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.
#duration ⇒ Time
Returns the total duration of the music.
126 127 128 |
# File 'ext/audio/music.c', line 126 static VALUE Music_duration(VALUE self) { return time_to_rb(sfMusic_getDuration(Get_Music_Struct(self))); } |
#effect_processor=(proc) ⇒ Proc
Installs a Proc that post-processes this source's audio in real time.
#loop_points ⇒ Array, Time
Returns the loop points as an [offset, length] pair.
184 185 186 187 188 |
# File 'ext/audio/music.c', line 184 static VALUE Music_loop_points(VALUE self) { sfTimeSpan span = sfMusic_getLoopPoints(Get_Music_Struct(self)); return rb_ary_new_from_args(2, time_to_rb(span.offset), time_to_rb(span.length)); } |
#loop_points=(value) ⇒ Array, Time
Sets the loop points as a two-element [offset, length] pair.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'ext/audio/music.c', line 198
static VALUE Music_set_loop_points(VALUE self, VALUE rb_span) {
sfTimeSpan span;
if (!RB_TYPE_P(rb_span, T_ARRAY) || RARRAY_LEN(rb_span) != 2) {
rb_raise(rb_eArgError, "loop points must be a two-element [offset, length] array");
}
span.offset = time_from_rb(rb_ary_entry(rb_span, 0));
span.length = time_from_rb(rb_ary_entry(rb_span, 1));
sfMusic_setLoopPoints(Get_Music_Struct(self), span);
return rb_span;
}
|
#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.
#sample_rate ⇒ Integer
Returns the music's sample rate in samples per second.
146 147 148 |
# File 'ext/audio/music.c', line 146 static VALUE Music_sample_rate(VALUE self) { return UINT2NUM(sfMusic_getSampleRate(Get_Music_Struct(self))); } |
#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.