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

- (Object) filename (readonly)

Class Method Details

+ (Array<String>) decoders

Get the names of the sample decoders.

Returns:

  • (Array<String>)

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



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)

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:



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.

Returns:

  • (nil)


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.

Returns:

  • (Boolean)

- (String) inspect

Returns inspection string

Returns:

  • (String)

    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.

Returns:

See Also:



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)

Set the volume of the sample.

Parameters:

  • vol (Integer)

    the new volume

Returns:

  • (vol)

See Also:



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