Class: Seal::Source

Inherits:
Object
  • Object
show all
Defined in:
src/rubyext.c,
src/rubyext.c

Overview

Interfaces for manipulating sources. Sources are abstract representations of sound sources which emit sound in a Euclidean space. The sound comes from its attached buffer or stream. Its properties combined with those of the listener singleton object determine how the sound should be rendered.

Defined Under Namespace

Modules: State, Type

Instance Method Summary (collapse)

Constructor Details

- (Object) Seal::Source.new

Initializes a new source.

There is a limit on the number of allocated sources. This method raises an error if it is exceeding the limit.



562
563
564
565
566
567
568
569
# File 'src/rubyext.c', line 562

static
VALUE
init_src(VALUE rsrc)
{
    check_seal_err(seal_init_src(DATA_PTR(rsrc)));

    return rsrc;
}

Instance Method Details

- (Boolean) auto Also known as: auto?

Determines if source is automatically updated. The default is true.

Returns:

  • (Boolean)


924
925
926
927
928
929
# File 'src/rubyext.c', line 924

static
VALUE
is_src_auto(VALUE rsrc)
{
    return get_obj_char(rsrc, seal_is_src_auto);
}

- (Boolean) auto=(true)

Sets whether source should be automatically updated asynchronously by a background thread. If this thread is running, user calls to #update does nothing. If auto update is disabled after it is enabled, it will take effect the next time the source gets played.

Returns:

  • (Boolean)


911
912
913
914
915
916
# File 'src/rubyext.c', line 911

static
VALUE
set_src_auto(VALUE rsrc, VALUE value)
{
    return set_obj_char(rsrc, value, seal_set_src_auto);
}

- (Object) buffer

Gets the buffer of source. The default is nil.



692
693
694
695
696
697
# File 'src/rubyext.c', line 692

static
VALUE
get_src_buf(VALUE rsrc)
{
    return rb_iv_get(rsrc, "@buffer");
}

- (Object) buffer=(buffer) - (nil) buffer=(nil)

Associates buffer with source so that the source is ready to play the audio contained in buffer. Can be applied only to sources in the initial or stopped states and that are not of streaming type. If successful, the source will become or remain as Type::STATIC.

If nil is specified, the source will give up the buffer it has and will reset the source to Type::UNDETERMINED and the source state to State::STOPPED. It will not free the buffer.

Overloads:

  • - (nil) buffer=(nil)

    Returns:

    • (nil)


669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
# File 'src/rubyext.c', line 669

static
VALUE
set_src_buf(VALUE rsrc, VALUE rbuf)
{
    seal_buf_t* buf;

    if (NIL_P(rbuf)) {
        src_op(rsrc, seal_detach_src_audio);
    } else {
        Data_Get_Struct(rbuf, seal_buf_t, buf);
        check_seal_err(seal_set_src_buf(DATA_PTR(rsrc), buf));
    }
    rb_iv_set(rsrc, "@buffer", rbuf);

    return rbuf;
}

- (Fixnum) chunk_size

Gets the size, in byte, of source's streaming chunk. The default is 36864.

Returns:

  • (Fixnum)


1044
1045
1046
1047
1048
1049
# File 'src/rubyext.c', line 1044

static
VALUE
get_src_chunk_size(VALUE rsrc)
{
    return get_obj_int(rsrc, seal_get_src_chunk_size);
}

- (Boolean) chunk_size=(fixnum)

Sets the maximum size, in byte, of the audio chunk which buffers the audio data constantly fetched from an audio stream. Using small chunks may cause playback to occur before the required audio chunk is ready, which in turn causes unexpected stop of playback. fixnum must be in the interval [9216, 16773120] and must be a multiple of 9216; non-multiple value will be adjusted to the closest smaller multiple automatically.

Returns:

  • (Boolean)


1030
1031
1032
1033
1034
1035
# File 'src/rubyext.c', line 1030

static
VALUE
set_src_chunk_size(VALUE rsrc, VALUE value)
{
    return set_obj_int(rsrc, value, seal_set_src_chunk_size);
}

- (Object) feed(effect_slot, index)

Feeds an effect_slot with the output of source so the output is filtered based on the effect attached to effect_slot. Later calls to this method with a different effect slot and the same source and index will override the old association. index is the zero-based index for the effect. Each different effect slot that source is feeding must have a unique corresponding index. The max is Seal.per_src_effect_limit - 1.



760
761
762
763
764
765
766
767
768
769
770
# File 'src/rubyext.c', line 760

static
VALUE
feed_efs(VALUE rsrc, VALUE rslot, VALUE rindex)
{
    seal_src_t* src;

    Data_Get_Struct(rsrc, seal_src_t, src);
    check_seal_err(seal_feed_efs(src, DATA_PTR(rslot), NUM2INT(rindex)));

    return rsrc;
}

- (Object) gain

Gets the gain of source. The default is 1.0.



895
896
897
898
899
900
# File 'src/rubyext.c', line 895

static
VALUE
get_src_gain(VALUE rsrc)
{
    return get_obj_float(rsrc, seal_get_src_gain);
}

- (Array) gain=(flt)

Sets the scalar amplitude multiplier of source in the interval [0.0, +inf.). 1.0 means that the sound is unattenuated; 0.5 means an attenuation of 6 dB; 0.0 means silence.

Returns:

  • (Array)


882
883
884
885
886
887
# File 'src/rubyext.c', line 882

static
VALUE
set_src_gain(VALUE rsrc, VALUE value)
{
    return set_obj_float(rsrc, value, seal_set_src_gain);
}

- (Boolean) looping Also known as: looping?

Determines if source is looping. The default is false (0).

Returns:

  • (Boolean)


979
980
981
982
983
984
# File 'src/rubyext.c', line 979

static
VALUE
is_src_looping(VALUE rsrc)
{
    return get_obj_char(rsrc, seal_is_src_looping);
}

- (Boolean) looping=(true)

Sets whether the playback of source is looping. A looping source will never enter State::STOPPED; it will immediate enter State::INITIAL and then State::Playing after it reaches the end of the last buffer.

Returns:

  • (Boolean)


966
967
968
969
970
971
# File 'src/rubyext.c', line 966

static
VALUE
set_src_looping(VALUE rsrc, VALUE value)
{
    return set_obj_char(rsrc, value, seal_set_src_looping);
}

- (Object) move

Moves the source (changes the position) based on the source velocity. This is a syntactic sugar for adding the velocity vector and position vector:

# Equivalent to `source.move`
source.position = source.position.zip(source.velocity).map do |a, b|
    a + b
end


648
649
650
651
652
653
# File 'src/rubyext.c', line 648

static
VALUE
move_src(VALUE rsrc, VALUE value)
{
    return src_op(rsrc, seal_move_src);
}

- (Object) pause

Pauses the playing of source. Applying to a playing source will change its state to State::PAUSED. Applying to an initial, paused or stopped source has no effect.



598
599
600
601
602
603
# File 'src/rubyext.c', line 598

static
VALUE
pause_src(VALUE rsrc)
{
    return src_op(rsrc, seal_pause_src);
}

- (Object) pitch

Gets the pitch of source. The default is 1.0.



867
868
869
870
871
872
# File 'src/rubyext.c', line 867

static
VALUE
get_src_pitch(VALUE rsrc)
{
    return get_obj_float(rsrc, seal_get_src_pitch);
}

- (Array) pitch=(flt)

Sets the pitch shift multiplier of source. 1.0 means identity; each reduction by 1/2 means a pitch shift of -12 semitones; each doubling means a pitch shift of 12 semitones. Use of 0.0 is undefined. The valid range is (0.0, +inf.).

Returns:

  • (Array)


854
855
856
857
858
859
# File 'src/rubyext.c', line 854

static
VALUE
set_src_pitch(VALUE rsrc, VALUE value)
{
    return set_obj_float(rsrc, value, seal_set_src_pitch);
}

- (Object) play

Starts to play source. Applying to a playing source will restart the playback from the beginning thus reset the sampling offset too. If the source is a streaming source, restarting the playback will automatically rewind the stream to the beginning. Applying to an initial or stopped source will start start playing and change its state to State::PLAYING. Applying to a paused source will resume playing and change its state to State::PLAYING.



583
584
585
586
587
588
# File 'src/rubyext.c', line 583

static
VALUE
play_src(VALUE rsrc)
{
    return src_op(rsrc, seal_play_src);
}

- (Array) position

Gets the position of source. The default is ( 0.0, 0.0, 0.0 ).

Returns:

  • (Array)


810
811
812
813
814
815
# File 'src/rubyext.c', line 810

static
VALUE
get_src_pos(VALUE rsrc)
{
    return get_obj_3float(rsrc, seal_get_src_pos);
}

- (Object) position=

Sets the position of source in a right-handed Cartesian coordinate system. Use of NaN and infinity is undefined.



797
798
799
800
801
802
# File 'src/rubyext.c', line 797

static
VALUE
set_src_pos(VALUE rsrc, VALUE value)
{
    return set_obj_3float(rsrc, value, seal_set_src_pos);
}

- (Fixnum) queue_size

Gets the size, in byte, of source's streaming queue. The default is 3.

Returns:

  • (Fixnum)


1012
1013
1014
1015
1016
1017
# File 'src/rubyext.c', line 1012

static
VALUE
get_src_queue_size(VALUE rsrc)
{
    return get_obj_int(rsrc, seal_get_src_queue_size);
}

- (Boolean) queue_size=(fixnum)

Sets the size of the streaming queue internally used by source. The queue maintains a multiple buffering mechanism when streaming the audio data. Multiple bufferring allows buffers in the queue to be processed while the one at the front of the queue is still being played. A queue of size 2 (double buffering) may still be inefficient in CPU-, and I/O-bound situations while triple, or even quad buffering generally produces better sound quality in non-memory-bound situations. fixnum must be in the interval [2, 63].

Returns:

  • (Boolean)


999
1000
1001
1002
1003
1004
# File 'src/rubyext.c', line 999

static
VALUE
set_src_queue_size(VALUE rsrc, VALUE value)
{
    return set_obj_int(rsrc, value, seal_set_src_queue_size);
}

- (Boolean) relative Also known as: relative?

Determines if source is relative. The default is false.

Returns:

  • (Boolean)


951
952
953
954
955
956
# File 'src/rubyext.c', line 951

static
VALUE
is_src_relative(VALUE rsrc)
{
    return get_obj_char(rsrc, seal_is_src_relative);
}

- (Boolean) relative=(true)

Sets whether source's position, velocity, cone and direction are all relative to the listener position.

Returns:

  • (Boolean)


938
939
940
941
942
943
# File 'src/rubyext.c', line 938

static
VALUE
set_src_relative(VALUE rsrc, VALUE value)
{
    return set_obj_char(rsrc, value, seal_set_src_relative);
}

- (Object) rewind

Rewinds source to the beginning. Applying to a playing, paused or stopped source will change its state to State::INITIAL. Applying to an initial source has no effect. The sampling offset will be reset to the beginning. Other attributes are preserved.



629
630
631
632
633
634
# File 'src/rubyext.c', line 629

static
VALUE
rewind_src(VALUE rsrc)
{
    return src_op(rsrc, seal_rewind_src);
}

- (Object) state

Gets the state of source.



1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# File 'src/rubyext.c', line 1079

static
VALUE
get_src_state(VALUE rsrc)
{
    seal_src_state_t state;

    check_seal_err(seal_get_src_state(DATA_PTR(rsrc), &state));
    switch (state) {
    case SEAL_PLAYING:
        return name2sym(PLAYING_SYM);
    case SEAL_PAUSED:
        return name2sym(PAUSED_SYM);
    case SEAL_STOPPED:
        return name2sym(STOPPED_SYM);
    default:
        return name2sym(INITIAL_SYM);
    }
}

- (Object) stop

Stops the playing of source. Applying to a playing or paused source will change its state to State::STOPPED. Applying to an initial or stopped source has no effect. Resets the sampling offset.



613
614
615
616
617
618
# File 'src/rubyext.c', line 613

static
VALUE
stop_src(VALUE rsrc)
{
    return src_op(rsrc, seal_stop_src);
}

- (Object) stream

Gets the stream of source. The default is nil.



742
743
744
745
746
747
# File 'src/rubyext.c', line 742

static
VALUE
get_src_stream(VALUE rsrc)
{
    return rb_iv_get(rsrc, "@stream");
}

- (Object) stream=(stream) - (Object) stream=(nil)

Associates (opened) stream with source so that audio data can be continuously fetched from a file rather than loading everything to memory at once. Can be applied to sources in any playing state but not on static sources. When replacing an attached stream, the new stream must have the same audio format as the old one. Also be aware of the fact that in this case there could still be some chunks of the old stream at the front of the streaming queue waiting to be played. If successful, the source will become or remain as Type::STREAMING. The streaming queue will be filled after this call returns; after the queue starts to be played, #update should be called to refill the queue.

If nil is specified, the source will give up the stream it has and will reset the source to Type::UNDETERMINED and the source state to State::STOPPED. It will not free the stream.



719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'src/rubyext.c', line 719

static
VALUE
set_src_stream(VALUE rsrc, VALUE rstream)
{
    seal_stream_t* stream;

    if (NIL_P(rstream)) {
        src_op(rsrc, seal_detach_src_audio);
    } else {
        Data_Get_Struct(rstream, seal_stream_t, stream);
        check_seal_err(seal_set_src_stream(DATA_PTR(rsrc), stream));
    }
    rb_iv_set(rsrc, "@stream", rstream);

    return rstream;
}

- (Object) type

Gets the type of source.



1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
# File 'src/rubyext.c', line 1056

static
VALUE
get_src_type(VALUE rsrc)
{
    seal_src_type_t type;

    check_seal_err(seal_get_src_type(DATA_PTR(rsrc), &type));
    switch (type) {
    case SEAL_STATIC:
        return name2sym(STATIC_SYM);
    case SEAL_STREAMING:
        return name2sym(STREAMING_SYM);
    default:
        return name2sym(UNDETERMINED_SYM);
    }
}

- (Object) update

Updates a streaming source by filling up the audio queue until it is full. If source is not up-to-date, the playback will end before the end of the stream is reached. Does nothing if source is not a streaming source. Also does nothing if auto update is on. When auto update is off, it is the caller's responsibility to handle cases where the consumer (OpenAL) consumes faster than the producer (the caller) produces and causes the playback to stop. Automatic sources automatically resume playing in such cases.



784
785
786
787
788
# File 'src/rubyext.c', line 784

static
VALUE update_src(VALUE rsrc)
{
    return src_op(rsrc, seal_update_src);
}

- (Array) velocity

Gets the velocity of source. The default is ( 0.0, 0.0, 0.0 ).

Returns:

  • (Array)


838
839
840
841
842
843
# File 'src/rubyext.c', line 838

static
VALUE
get_src_vel(VALUE rsrc)
{
    return get_obj_3float(rsrc, seal_get_src_vel);
}

- (Object) velocity=

Sets the velocity of source in a right-handed Cartesian coordinate system. The velocity of the source does not affect its position but is a factor used during the Doppler effect emulation. Use of NaN is undefined.



825
826
827
828
829
830
# File 'src/rubyext.c', line 825

static
VALUE
set_src_vel(VALUE rsrc, VALUE value)
{
    return set_obj_3float(rsrc, value, seal_set_src_vel);
}