Class: SFML::SoundStream
- Inherits:
-
Object
- Object
- SFML::SoundStream
- Defined in:
- ext/audio/sound_stream.c,
ext/audio/sound_stream.c
Overview
Base class for a custom audio source that generates or decodes its own
samples on demand. Subclasses must implement #on_get_data, returning an
Array of Integer samples or a packed String of int16 samples for the next
chunk (or +nil+/+false+ to signal end of stream), and may implement
#on_seek(time) to support seeking.
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 the stream produces.
-
#channel_map ⇒ Array<Symbol>
Returns the channel layout of the stream.
-
#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.
-
#effect_processor=(proc) ⇒ Proc
Installs a Proc that post-processes this source's audio in real time.
-
#initialize(*args) ⇒ SoundStream
constructor
SoundStream must be subclassed: the subclass is required to implement
#on_get_data, called from a foreign audio thread whenever more samples are needed, and may optionally implement#on_seek. -
#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 stream'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.
Constructor Details
#new(channel_count, sample_rate) ⇒ SoundStream #new(channel_count, sample_rate, channel_map) ⇒ SoundStream
SoundStream must be subclassed: the subclass is required to implement
#on_get_data, called from a foreign audio thread whenever more samples
are needed, and may optionally implement #on_seek. channel_map, if
given, is an Array of channel Symbols (see SoundChannel), one per channel.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'ext/audio/sound_stream.c', line 229
static VALUE SoundStream_initialize(int argc, VALUE* argv, VALUE self) {
VALUE rb_channel_count, rb_sample_rate, rb_channel_map;
sfSoundChannel* channel_map = NULL;
size_t channel_map_size = 0;
SoundStream* ptr;
long i;
TypedData_Get_Struct(self, SoundStream, &SoundStream_data_type, ptr);
rb_scan_args(argc, argv, "21", &rb_channel_count, &rb_sample_rate, &rb_channel_map);
if (!NIL_P(rb_channel_map)) {
if (!RB_TYPE_P(rb_channel_map, T_ARRAY)) {
rb_raise(rb_eArgError, "channel map must be an Array");
}
channel_map_size = (size_t)RARRAY_LEN(rb_channel_map);
channel_map = malloc(sizeof(sfSoundChannel) * channel_map_size);
for (i = 0; i < (long)channel_map_size; i++) {
channel_map[i] = sound_channel_from_rb(rb_ary_entry(rb_channel_map, i));
}
}
if (!rb_respond_to(self, rb_intern("on_get_data"))) {
free(channel_map);
rb_raise(rb_eNotImpError, "subclass must define #on_get_data");
}
ptr->source.handle = sfSoundStream_create(
SoundStream_on_get_data, SoundStream_on_seek, (unsigned int)NUM2INT(rb_channel_count),
(unsigned int)NUM2INT(rb_sample_rate), channel_map, channel_map_size, ptr);
free(channel_map);
if (ptr->source.handle == NULL) {
rb_raise(rb_eRuntimeError, "failed to create sound stream");
}
return self;
}
|
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 the stream produces.
277 278 279 |
# File 'ext/audio/sound_stream.c', line 277 static VALUE SoundStream_channel_count(VALUE self) { return UINT2NUM(sfSoundStream_getChannelCount(Get_SoundStream_Struct(self))); } |
#channel_map ⇒ Array<Symbol>
Returns the channel layout of the stream.
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'ext/audio/sound_stream.c', line 298
static VALUE SoundStream_channel_map(VALUE self) {
size_t count = 0;
sfSoundChannel* map = sfSoundStream_getChannelMap(Get_SoundStream_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.
#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.
#sample_rate ⇒ Integer
Returns the stream's sample rate in samples per second.
287 288 289 |
# File 'ext/audio/sound_stream.c', line 287 static VALUE SoundStream_sample_rate(VALUE self) { return UINT2NUM(sfSoundStream_getSampleRate(Get_SoundStream_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.