Class: SDL2::Mixer::Chunk
- Inherits:
-
Object
- Object
- SDL2::Mixer::Chunk
- Defined in:
- mixer.c,
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.
921 922 923 924 925 926 927 928 929 |
# File 'mixer.c', line 921
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
905 906 907 908 909 910 911 912 913 914 |
# File 'mixer.c', line 905
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.
939 940 941 942 943 944 945 |
# File 'mixer.c', line 939
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
974 975 976 977 978 979 980 981 982 983 984 |
# File 'mixer.c', line 974
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.
954 955 956 957 |
# File 'mixer.c', line 954
static VALUE Chunk_volume(VALUE self)
{
return INT2NUM(Mix_VolumeChunk(Get_Mix_Chunk(self), -1));
}
|
#volume=(vol) ⇒ vol
968 969 970 971 |
# File 'mixer.c', line 968
static VALUE Chunk_set_volume(VALUE self, VALUE vol)
{
return INT2NUM(Mix_VolumeChunk(Get_Mix_Chunk(self), NUM2INT(vol)));
}
|