Class: SDL2::Mixer::Chunk
- Inherits:
-
Object
- Object
- SDL2::Mixer::Chunk
- Defined in:
- ext/sdl2_ext/mixer.c,
ext/sdl2_ext/mixer.c
Overview
This class represents a sound sample, a kind of sound sources.
Chunk objects is playable on Channels.
Instance Attribute Summary collapse
-
#filename ⇒ String
readonly
The file name of the file from which the sound is loaded.
Class Method Summary collapse
-
.decoders ⇒ Array<String>
Get the names of the sample decoders.
-
.load(path) ⇒ SDL2::Mixer::Chunk
Load a sample from file.
Instance Method Summary collapse
-
#destroy ⇒ nil
Deallocate the sample memory.
-
#destroy? ⇒ Boolean
Return true if the memory is deallocated by #destroy.
-
#inspect ⇒ String
Inspection string.
-
#volume ⇒ Integer
Get the volume of the sample.
-
#volume=(vol) ⇒ vol
Set the volume of the sample.
Instance Attribute Details
#filename ⇒ String (readonly)
Returns The file name of the file from which the sound is loaded.
Class Method Details
.decoders ⇒ Array<String>
Get the names of the sample decoders.
920 921 922 923 924 925 926 927 928 |
# File 'ext/sdl2_ext/mixer.c', line 920
static VALUE Chunk_s_decoders(VALUE self)
{
int i;
int num_decoders = Mix_GetNumChunkDecoders();
VALUE ary = rb_ary_new();
for (i=0; i < num_decoders; ++i)
rb_ary_push(ary, rb_usascii_str_new_cstr(Mix_GetChunkDecoder(i)));
return ary;
}
|
.load(path) ⇒ SDL2::Mixer::Chunk
904 905 906 907 908 909 910 911 912 913 |
# File 'ext/sdl2_ext/mixer.c', line 904
static VALUE Chunk_s_load(VALUE self, VALUE fname)
{
Mix_Chunk* chunk = Mix_LoadWAV(StringValueCStr(fname));
VALUE c;
if (!chunk)
MIX_ERROR();
c = Chunk_new(chunk);
rb_iv_set(c, "@filename", fname);
return c;
}
|
Instance Method Details
#destroy ⇒ nil
Deallocate the sample memory.
Normally, the memory is deallocated by ruby’s GC, but you can surely deallocate the memory with this method at any time.
938 939 940 941 942 943 944 |
# File 'ext/sdl2_ext/mixer.c', line 938
static VALUE Chunk_destroy(VALUE self)
{
Chunk* c = Get_Chunk(self);
if (c->chunk) Mix_FreeChunk(c->chunk);
c->chunk = NULL;
return Qnil;
}
|
#destroy? ⇒ Boolean
Return true if the memory is deallocated by #destroy.
#inspect ⇒ String
Returns inspection string.
973 974 975 976 977 978 979 980 981 982 983 |
# File 'ext/sdl2_ext/mixer.c', line 973
static VALUE Chunk_inspect(VALUE self)
{
VALUE filename = rb_iv_get(self, "@filename");
if (RTEST(Chunk_destroy_p(self)))
return rb_sprintf("<%s: destroyed>", rb_obj_classname(self));
return rb_sprintf("<%s: filename=\"%s\" volume=%d>",
rb_obj_classname(self),
StringValueCStr(filename),
Mix_VolumeChunk(Get_Mix_Chunk(self), -1));
}
|
#volume ⇒ Integer
Get the volume of the sample.
953 954 955 956 |
# File 'ext/sdl2_ext/mixer.c', line 953
static VALUE Chunk_volume(VALUE self)
{
return INT2NUM(Mix_VolumeChunk(Get_Mix_Chunk(self), -1));
}
|
#volume=(vol) ⇒ vol
967 968 969 970 |
# File 'ext/sdl2_ext/mixer.c', line 967
static VALUE Chunk_set_volume(VALUE self, VALUE vol)
{
return INT2NUM(Mix_VolumeChunk(Get_Mix_Chunk(self), NUM2INT(vol)));
}
|