struct Slice(T)
- Slice(T)
- Struct
- Value
- Object
Overview
A Slice
is a Pointer
with an associated size.
While a pointer is unsafe because no bound checks are performed when reading from and writing to it,
reading from and writing to a slice involve bound checks.
In this way, a slice is a safe alternative to Pointer
.
A Slice can be created as read-only: trying to write to it
will raise. For example the slice of bytes returned by
String#to_slice
is read-only.
Included Modules
- Comparable(Slice(T))
- Indexable::Mutable(T)
Defined in:
lib/libremiliacr/src/remilib/extensions.crremiaudio/common.cr
Instance Method Summary
-
#[](index : Int, side : RemiAudio::Side) : T
Returns the sample at the given index for the given side.
-
#[]=(index : Int, side : RemiAudio::Side, value : T) : Nil
Sets the sample at the given index for the given side.
-
#deinterleave(destLeft : Slice(T), destRight : Slice(T)) : Nil
Treats this array as having interleaved left/right data, and splits the internal buffer into destLeft and destRight.
-
#deinterleave : Tuple(Slice(T), Slice(T))
Treats this array as having interleaved left/right data, and splits the internal buffer into two new
Array
instances. -
#eachLeftWithIndex(& : T -> )
Treats this slice as having interleaved left/right data, yielding each element that would appear on the left side to the block.
-
#eachRight(& : T -> )
Treats this slice as having interleaved left/right data, yielding each element that would appear on the right side to the block.
-
#eachWithSide(& : Tuple(T, RemiAudio::Side) -> )
Treats this slice as having interleaved left/right data, yielding each element along with its side.
-
#interleave(other : Slice(T), dest : Slice(T)) : Slice(T)
Interleaves this audio data with other, storing the results in dest.
-
#interleave(other : Slice(T)) : Slice(T)
Interleaves this audio data with other.
-
#mapSides!(& : Tuple(T, RemiAudio::Side) -> )
Invokes the given block for each sample in
self
, along with the side that sample is on. -
#sizePerSide : Int
Returns the side for one side of the internal buffer.
Instance Method Detail
Returns the sample at the given index for the given side. This treats
this slice as having interleaved left/right data, and so index
must be
less than half of the total size
, or less than #sizePerSide
.
Sets the sample at the given index for the given side. This treats this
slice as having interleaved left/right data, and so index
must be less
than half of the total size
, or less than #sizePerSide
.
Treats this array as having interleaved left/right data, and splits the internal buffer into destLeft and destRight. The size of destLeft and destRight must be exactly equal to the size of this instance. Additionally, this instance must have a size divisible by 2.
If the size checks fail, this raises a RemiAudioError
.
The size checks can be disabled by passing -Dremiaudio_wd40
to the
compiler at build time.
Treats this array as having interleaved left/right data, and splits the
internal buffer into two new Array
instances. This returns a Tuple
where the 0th element is the left side, and the other is the right side.
Treats this slice as having interleaved left/right data, yielding each
element that would appear on the left side to the block. Returns self
.
Treats this slice as having interleaved left/right data, yielding each
element that would appear on the right side to the block. Returns self
.
Treats this slice as having interleaved left/right data, yielding each
element along with its side. Returns self
.
Interleaves this audio data with other, storing the results in dest.
The size of other must be exactly the same as this instance's #size
, and
the size of dest must be exactly twice to the size of this instance, or an
RemiAudioError
is raised.
The size checks can be disabled by passing -Dremiaudio_wd40
to the
compiler at build time.
Interleaves this audio data with other. The size of other must be
exactly the same as this instance's #size
, or an RemiAudioError
is
raised.
The size check can be disabled by passing -Dremiaudio_wd40
to the compiler
at build time.
Invokes the given block for each sample in self
, along with the side that
sample is on. This replaces the sample with the value returned by the
block. Returns self
.
Returns the side for one side of the internal buffer. This treats this slice as having interleaved left/right data.