sfml3.rb

Class: SFML::SoundBufferRecorder

Inherits:
Object
  • Object
show all
Defined in:
ext/audio/sound_buffer_recorder.c,
ext/audio/sound_buffer_recorder.c

Overview

Records audio from a capture device directly into a SoundBuffer. For custom processing of captured samples as they arrive, subclass SoundRecorder instead.

Instance Method Summary collapse

Constructor Details

#new ⇒ SoundBufferRecorder

Creates a recorder that captures into a SoundBuffer.

Raises:

  • (RuntimeError) —

    if no capture device is available



56
57
58
# File 'ext/audio/sound_buffer_recorder.c', line 56

static VALUE SoundBufferRecorder_initialize(VALUE self) {
    return self;
}

Instance Method Details

#buffer ⇒ SoundBuffer

Returns the buffer holding the audio recorded so far.

Returns:

Returns:

  • (SoundBuffer) —

    the buffer containing the audio recorded so far



99
100
101
102
# File 'ext/audio/sound_buffer_recorder.c', line 99

static VALUE SoundBufferRecorder_buffer(VALUE self) {
    return sound_buffer_from_borrowed(
        sfSoundBufferRecorder_getBuffer(Get_SoundBufferRecorder_Struct(self)));
}

#channel_count ⇒ Integer

Returns the number of capture channels.

Returns:

  • (Integer)

Returns:

  • (Integer)


133
134
135
# File 'ext/audio/sound_buffer_recorder.c', line 133

static VALUE SoundBufferRecorder_channel_count(VALUE self) {
    return UINT2NUM(sfSoundBufferRecorder_getChannelCount(Get_SoundBufferRecorder_Struct(self)));
}

#channel_count=(value) ⇒ Integer

Must be called while not recording.

Returns:

  • (Integer)

Returns:

  • (Integer) —

    value



144
145
146
147
148
# File 'ext/audio/sound_buffer_recorder.c', line 144

static VALUE SoundBufferRecorder_set_channel_count(VALUE self, VALUE rb_count) {
    sfSoundBufferRecorder_setChannelCount(Get_SoundBufferRecorder_Struct(self),
                                          (unsigned int)NUM2INT(rb_count));
    return rb_count;
}

#device ⇒ String

Returns the name of the capture device in use.

Returns:

  • (String)

Returns:

  • (String) —

    the name of the capture device in use



110
111
112
# File 'ext/audio/sound_buffer_recorder.c', line 110

static VALUE SoundBufferRecorder_device(VALUE self) {
    return rb_str_new_cstr(sfSoundBufferRecorder_getDevice(Get_SoundBufferRecorder_Struct(self)));
}

#device=(value) ⇒ Boolean

Must be called while not recording. Get available names from SoundRecorder.available_devices.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether the device was set successfully



122
123
124
125
# File 'ext/audio/sound_buffer_recorder.c', line 122

static VALUE SoundBufferRecorder_set_device(VALUE self, VALUE rb_name) {
    return BOOL2RB(sfSoundBufferRecorder_setDevice(Get_SoundBufferRecorder_Struct(self),
                                                   StringValueCStr(rb_name)));
}

#sample_rate ⇒ Integer

Returns the sample rate used for capture.

Returns:

  • (Integer)

Returns:

  • (Integer)


89
90
91
# File 'ext/audio/sound_buffer_recorder.c', line 89

static VALUE SoundBufferRecorder_sample_rate(VALUE self) {
    return UINT2NUM(sfSoundBufferRecorder_getSampleRate(Get_SoundBufferRecorder_Struct(self)));
}

#start(sample_rate) ⇒ Boolean

Starts capturing audio at the given sample rate.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether recording started successfully



67
68
69
70
# File 'ext/audio/sound_buffer_recorder.c', line 67

static VALUE SoundBufferRecorder_start(VALUE self, VALUE rb_sample_rate) {
    return BOOL2RB(sfSoundBufferRecorder_start(Get_SoundBufferRecorder_Struct(self),
                                               (unsigned int)NUM2INT(rb_sample_rate)));
}

#stop ⇒ self

Stops capturing audio.

Returns:

  • (self)

Returns:

  • (self)


78
79
80
81
# File 'ext/audio/sound_buffer_recorder.c', line 78

static VALUE SoundBufferRecorder_stop(VALUE self) {
    sfSoundBufferRecorder_stop(Get_SoundBufferRecorder_Struct(self));
    return self;
}