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) ⇒ void
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.
936 937 938 939 940 941 942 943 944 |
# File 'mixer.c', line 936
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
920 921 922 923 924 925 926 927 928 929 |
# File 'mixer.c', line 920
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.
954 955 956 957 958 959 960 |
# File 'mixer.c', line 954
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.
989 990 991 992 993 994 995 996 997 998 999 |
# File 'mixer.c', line 989
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.
969 970 971 972 |
# File 'mixer.c', line 969
static VALUE Chunk_volume(VALUE self)
{
return INT2NUM(Mix_VolumeChunk(Get_Mix_Chunk(self), -1));
}
|
#volume=(vol) ⇒ void
983 984 985 986 |
# File 'mixer.c', line 983
static VALUE Chunk_set_volume(VALUE self, VALUE vol)
{
return INT2NUM(Mix_VolumeChunk(Get_Mix_Chunk(self), NUM2INT(vol)));
}
|