class SF::SoundBufferRecorder

Overview

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

Defined in:

audio/obj.cr

Constructors

Instance Method Summary

Instance methods inherited from class SF::SoundRecorder

channel_count : Int32 channel_count, channel_count=(channel_count : Int) channel_count=, device : String device, device=(name : String) : Bool device=, finalize finalize, on_process_samples(samples : Array(Int16) | Slice(Int16)) : Bool on_process_samples, on_start : Bool on_start, on_stop on_stop, processing_interval=(interval : Time) processing_interval=, sample_rate : Int32 sample_rate, start(sample_rate : Int = 44100) : Bool start, stop stop

Class methods inherited from class SF::SoundRecorder

available? : Bool available?, available_devices : Array(String) available_devices, default_device : String default_device

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def 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]
def finalize #

destructor


[View source]
def 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]
def on_start : Bool #

Start capturing audio data

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


[View source]
def on_stop #

Stop capturing audio data


[View source]