Method: FMOD::Sound#lock

Defined in:
lib/fmod/sound.rb

#lock(offset, length) {|ptr1, ptr2| ... } ⇒ self #lock(offset, length) ⇒ Array(Pointer, Pointer)

Returns a pointer to the beginning of the sample data for a sound.

With this function you get access to the RAW audio data, for example 8, 16, 24 or 32-bit PCM data, mono or stereo data. You must take this into consideration when processing the data within the pointer.

Overloads:

  • #lock(offset, length) {|ptr1, ptr2| ... } ⇒ self

    If called with a block, yields the pointers to the first and second sections of locked data before unlocking and returning self.

    Yields:

    • (ptr1, ptr2)

      Yields two pointers to the block.

    Yield Parameters:

    • ptr1 (Pointer)

      Pointer to the first part of the locked data, and its size set to the number of locked bytes.

    • ptr2 (Pointer)

      The second pointer will point to the second part of the locked data. This will be NULL if the data locked hasn’t wrapped at the end of the buffer, and its size will be 0.

    Returns:

    • (self)
  • #lock(offset, length) ⇒ Array(Pointer, Pointer)

    If called without a block, returns the pointers in an array, and #unlock must be called.

    Returns:

    • (Array(Pointer, Pointer))

      An array containing two pointers.

      The first pointer will point to the first part of the locked data, and its size set to the number of locked bytes.

      The second pointer will point to the second part of the locked data. This will be NULL if the data locked hasn’t wrapped at the end of the buffer, and its size will be 0.

Parameters:

  • offset (Integer)

    Offset in bytes to the position to lock in the sample buffer.

  • length (Integer)

    Number of bytes you want to lock in the sample buffer.

See Also:



317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/fmod/sound.rb', line 317

def lock(offset, length)
  p1, p2, s1, s2 = int_ptr, int_ptr, "\0" * TYPE_INT, "\0" * TYPE_INT
  FMOD.invoke(:Sound_Lock, self, offset, length, p1, p2, s1, s2)
  ptr1 = Pointer.new(p1.unpack1('J'), s1.unpack1('L'))
  ptr2 = Pointer.new(p2.unpack1('J'), s2.unpack1('L'))
  if block_given?
    yield ptr1, ptr2
    FMOD.invoke(:Sound_Unlock, self, ptr1, ptr2, ptr1.size, ptr2.size)
    return self
  end
  [ptr1, ptr2]
end