Class: Seal::Stream

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

Overview

Interfaces for manipulating streams used by streaming sources. Streams are usually necessary when the audio data is too massive to fit into main memory as a whole (such as a background music, which can eat up to dozens of megabytes of memory after decoding), in which case buffers are not suitable.

Streams often contain multi-channel audio (since most of the time they are used to play background music, and background music files are often multi-channel already), which means that they often contain sound that are not positioned, i.e., not processed by the 3D sound rendering pipeline. That fact is totally fine for background music since they are usually not associated to any object in the application. If positioned streams are needed and the audio file has multi-channel, the audio file need to be converted to mono-channel.

Instance Method Summary (collapse)

Constructor Details

- (Object) Seal::Stream.new(filename[, format]) - (Object) Seal::Stream.open(filename[, format])

Opens a audio stream from filename. format specifies the format of the audio file; automatic recognition of the audio format will be attempted if format is nil. See Seal::Format for possible values.



472
473
474
475
476
477
478
479
# File 'src/rubyext.c', line 472

static
VALUE
init_stream(int argc, VALUE* argv, VALUE rstream)
{
    input_audio(argc, argv, DATA_PTR(rstream), seal_open_stream);

    return rstream;
}

Instance Method Details

- (Fixnum) bit_depth

Gets the bit depth (bits per sample) of the audio contained in stream. The default is 16 when the stream is not opened.

Returns:

  • (Fixnum)


502
503
504
505
506
507
# File 'src/rubyext.c', line 502

static
VALUE
get_stream_bps(VALUE rstream)
{
    return INT2NUM(extract_stream(rstream)->attr.bit_depth);
}

- (Fixnum) channel_count

Gets the number of channels of the audio contained in stream. The default is 1 when the stream is not opened.

Returns:

  • (Fixnum)


516
517
518
519
520
521
# File 'src/rubyext.c', line 516

static
VALUE
get_stream_nchannels(VALUE rstream)
{
    return INT2NUM(extract_stream(rstream)->attr.nchannels);
}

- (Object) close

Closes stream.



544
545
546
547
548
549
550
551
# File 'src/rubyext.c', line 544

static
VALUE
close_stream(VALUE rstream)
{
    check_seal_err(seal_close_stream(DATA_PTR(rstream)));

    return rstream;
}

- (Fixnum) frequency

Gets the frequency (sample rate) of the audio contained in streamed. The default is 0 when the stream is not opened.

Returns:

  • (Fixnum)


488
489
490
491
492
493
# File 'src/rubyext.c', line 488

static
VALUE
get_stream_freq(VALUE rstream)
{
    return INT2NUM(extract_stream(rstream)->attr.freq);
}

- (Object) rewind

Rewinds stream to the beginning.



529
530
531
532
533
534
535
536
# File 'src/rubyext.c', line 529

static
VALUE
rewind_stream(VALUE rstream)
{
    seal_rewind_stream(DATA_PTR(rstream));

    return rstream;
}