Class: RGame::Core::Sample
- Inherits:
-
Object
- Object
- RGame::Core::Sample
- Defined in:
- lib/rgame/core/audio.rb,
ext/rgame_core/ruby/audio_ext.c
Overview
A short sound, decoded once and played many times over.
hit = RGame::Core::Sample.new(audio, 'assets/hit.ogg')
hit.volume = 0.5
hit.play
hit.play # layers a second voice over the first
Playing a sample that is already sounding starts another copy rather than restarting it, which is what makes footsteps and gunfire sound like themselves. There is no handle for a single play and no way to stop one; a sample is fire-and-forget. Volume belongs to the sample and applies to every voice it has out, including the ones already sounding.
Ogg Vorbis and WAV are the formats the engine reads. Anything else, or an unreadable file, raises Sample::LoadError.
Instance Method Summary collapse
- #initialize(audio, path) ⇒ Object constructor
- #play ⇒ Object
- #volume ⇒ Object
- #volume=(volume) ⇒ Object
Constructor Details
#initialize(audio, path) ⇒ Object
222 223 224 225 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 222
static VALUE sample_initialize(VALUE self, VALUE audio, VALUE path) {
return sound_initialize(self, audio, path, &sample_data_type, load_sample,
rb_const_get(cSample, rb_intern("LoadError")));
}
|
Instance Method Details
#play ⇒ Object
234 235 236 237 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 234
static VALUE sample_play(VALUE self) {
rgame_sample_play((rgame_sample *)sound_unwrap(self, &sample_data_type)->handle);
return self;
}
|
#volume ⇒ Object
239 240 241 242 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 239
static VALUE sample_volume(VALUE self) {
return DBL2NUM(
(double)rgame_sample_volume((rgame_sample *)sound_unwrap(self, &sample_data_type)->handle));
}
|
#volume=(volume) ⇒ Object
244 245 246 247 248 |
# File 'ext/rgame_core/ruby/audio_ext.c', line 244
static VALUE sample_set_volume(VALUE self, VALUE volume) {
rgame_sample_set_volume((rgame_sample *)sound_unwrap(self, &sample_data_type)->handle,
(float)NUM2DBL(volume));
return volume;
}
|