Class: Audio::LiveOutputC

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

Direct Known Subclasses

FileOutputC, LiveOutput

Defined Under Namespace

Classes: BadOption, DeviceData, DeviceError, DriverError, Error, NoDriver, NotFile, NotLive, UnknownError

Instance Method Summary collapse

Instance Method Details

#closeObject

device setup



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'ext/audio/output.c', line 23

VALUE
rao_close(VALUE obj)
{
  ao_struct *aos;

  if (rb_iv_get(obj, "@device") == Qnil){
    return Qfalse;
  }

  Data_Get_Struct(rb_iv_get(obj, "@device"),
		  ao_struct, aos);
  close_device(aos);
  rb_ary_delete(rb_cv_get(cAO_Live, "@@devices"), rb_intern("@device"));
  /*rb_iv_set(obj, "@device", Qnil);*/
  return Qtrue;
}

#closed?Boolean

デバイスが既に閉じられているか確認する。

return

true or false

Returns:

  • (Boolean)


154
155
156
157
158
159
160
161
162
163
164
# File 'ext/audio/device.c', line 154

VALUE
raodev_closed(VALUE obj)
{
  ao_struct *aos;
  Data_Get_Struct(rb_ivar_get(obj, rb_intern("@device")),
		  ao_struct, aos);
  if (aos->device == NULL){
    return Qtrue;
  }
  return Qfalse;
}

#play(output_samples) ⇒ Object

受け取ったサンプルを再生する。 threadが有効の場合、受け取ったサンプルを 再生キューに追加する。 (デバイスがファイル出力の場合はファイルに書き出す) 一度に渡せる量はunsigned int(32bit)の範囲まで。

arg1

buffer(String)

return

Fixnum



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'ext/audio/device.c', line 54

VALUE
raodev_play(VALUE obj, VALUE output_samples)
{
  sample_t  *sample;
  ao_struct *aos;
  aos_gvl    aosg;

  Check_Type(output_samples, T_STRING);
  if (rb_ivar_get(obj, rb_intern("@device")) == Qnil){
    rb_raise(cAO_eAOError, "Device already closed.");
  }
  Data_Get_Struct(rb_ivar_get(obj, rb_intern("@device")),
		  ao_struct, aos);
  if ((sample = malloc(sizeof(sample_t))) == NULL){
    rb_raise(cAO_eAOError, "Memory allocation failure.");
  }
  sample->bytes = RSTRING_LENINT(output_samples);
  if ((sample->buffer = malloc(sample->bytes)) == NULL){
    rb_raise(cAO_eAOError, "Memory allocation failure.");
  }
  memcpy(sample->buffer, StringValuePtr(output_samples), sample->bytes);

  if (aos->thread == 1){
    enqueue(aos, sample);
  } else {
    aosg.aos = aos;
    aosg.sample = *sample;
#ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
    rb_thread_call_without_gvl2(nogvl_ao_play, &aosg, NULL, NULL);
#else
    nogvl_ao_play(&aosg);
#endif
    free(sample->buffer);
  }
  return obj;
}

#playing?Boolean

デバイスがオーディオを出力中か確認する。 (threadを有効にしていない場合、常にfalse)

return

true or false

Returns:

  • (Boolean)


173
174
175
176
177
178
179
180
181
182
183
# File 'ext/audio/device.c', line 173

VALUE
raodev_playing(VALUE obj)
{
  ao_struct *aos;
  Data_Get_Struct(rb_ivar_get(obj, rb_intern("@device")),
		  ao_struct, aos);
  if (aos->thread == 1 && aos->status == 2){
    return Qtrue;
  }
  return Qfalse;
}

#waitingObject

再生キューの待ち数を返す。 (threadを有効にしていない場合、常に0)

return

Integer



192
193
194
195
196
197
198
199
# File 'ext/audio/device.c', line 192

VALUE
raodev_waiting(VALUE obj)
{
  ao_struct *aos;
  Data_Get_Struct(rb_ivar_get(obj, rb_intern("@device")),
		  ao_struct, aos);
  return INT2FIX(aos->qsize);
}