Class: SDL2::Mixer::Chunk

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

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.



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

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:



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

#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)


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.

Returns:

  • (Boolean)

#inspectString

Returns inspection string

Returns:

  • (String)

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

#volumeInteger

Get the volume of the sample.

Returns:

See Also:



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

Set the volume of the sample.

Parameters:

  • vol (Integer)

    the new volume

Returns:

  • (vol)

See Also:



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