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)
- - (Object) filename readonly
Class Method Summary (collapse)
-
+ (Array<String>) decoders
Get the names of the sample decoders.
-
+ (SDL2::Mixer::Chunk) load(path)
Load a sample from file.
Instance Method Summary (collapse)
-
- (nil) destroy
Deallocate the sample memory.
-
- (Boolean) destroy?
Return true if the memory is deallocated by #destroy.
-
- (String) inspect
Inspection string.
-
- (Integer) volume
Get the volume of the sample.
-
- (vol) volume=(vol)
Set the volume of the sample.
Instance Attribute Details
- (Object) filename (readonly)
Class Method Details
+ (Array<String>) decoders
Get the names of the sample decoders.
824 825 826 827 828 829 830 831 832 |
# File 'mixer.c', line 824
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;
}
|
+ (SDL2::Mixer::Chunk) load(path)
808 809 810 811 812 813 814 815 816 817 |
# File 'mixer.c', line 808
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
- (nil) destroy
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.
842 843 844 845 846 847 848 |
# File 'mixer.c', line 842
static VALUE Chunk_destroy(VALUE self)
{
Chunk* c = Get_Chunk(self);
if (c->chunk) Mix_FreeChunk(c->chunk);
c->chunk = NULL;
return Qnil;
}
|
- (Boolean) destroy?
Return true if the memory is deallocated by #destroy.
- (String) inspect
Returns inspection string
877 878 879 880 881 882 883 884 885 886 887 |
# File 'mixer.c', line 877
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));
}
|
- (Integer) volume
Get the volume of the sample.
857 858 859 860 |
# File 'mixer.c', line 857
static VALUE Chunk_volume(VALUE self)
{
return INT2NUM(Mix_VolumeChunk(Get_Mix_Chunk(self), -1));
}
|
- (vol) volume=(vol)
871 872 873 874 |
# File 'mixer.c', line 871
static VALUE Chunk_set_volume(VALUE self, VALUE vol)
{
return INT2NUM(Mix_VolumeChunk(Get_Mix_Chunk(self), NUM2INT(vol)));
}
|