Skip to content

class SF::SoundBufferRecorder
inherits SF::SoundRecorder #

Specialized SoundRecorder which stores the captured audio data into a sound buffer

SF::SoundBufferRecorder allows to access a recorded sound through a SF::SoundBuffer, so that it can be played, saved to a file, etc.

It has the same simple interface as its base class (start(), stop()) and adds a function to retrieve the recorded sound buffer (buffer()).

As usual, don't forget to call the available?() function before using this class (see SF::SoundRecorder for more details about this).

Usage example:

if SF::SoundBufferRecorder.available?
  # Record some audio data
  recorder = SF::SoundBufferRecorder.new
  recorder.start
  # [...]
  recorder.stop

  # Get the buffer containing the captured audio data
  buffer = recorder.buffer

  # Save it to a file (for example...)
  buffer.save_to_file("my_record.ogg")
end

See also: SF::SoundRecorder

Constructors#

Methods#

#buffer : SoundBuffer#

Get the sound buffer containing the captured audio data

The sound buffer is valid only after the capture has ended. This function provides a read-only access to the internal sound buffer, but it can be copied if you need to make any modification to it.

Returns: Read-only access to the sound buffer

View source

#finalize#

destructor

View source

#on_process_samples(samples : Array(Int16) | Slice(Int16)) : Bool#

Process a new chunk of recorded samples

  • samples - Pointer to the new chunk of recorded samples
  • sample_count - Number of samples pointed by samples

Returns: True to continue the capture, or false to stop it

View source

#on_start : Bool#

Start capturing audio data

Returns: True to start the capture, or false to abort it

View source

#on_stop#

Stop capturing audio data

View source