Class: SDL2::Mixer::Chunk

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameString (readonly)

Returns The file name of the file from which the sound is loaded.

Returns:

  • (String)

    The file name of the file from which the sound is loaded.

Class Method Details

.decodersArray<String>

Get the names of the sample decoders.

Returns:

  • (Array<String>)

    the names of decoders, such as: “WAVE”, “OGG”, etc.



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

Note:

SDL2::Mixer.open must be called before calling this method.

Load a sample from file.

This can load WAVE, AIFF, RIFF, OGG, and VOC files.

Parameters:

  • path (String)

    the fine name

Returns:

Raises:



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

#destroynil

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.

Returns:

  • (nil)


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.

Returns:

  • (Boolean)

#inspectString

Returns inspection string.

Returns:

  • (String)

    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));
}

#volumeInteger

Get the volume of the sample.

Returns:

See Also:



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

Set the volume of the sample.

Parameters:

  • vol (Integer)

    the new volume

Returns:

  • (vol)

See Also:



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)));
}