Class: RSoxEffectsChain

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

Instance Method Summary collapse

Instance Method Details

#add(*args) ⇒ Object

{{{



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'ext/rsox.c', line 276

VALUE rsoxeffectschain_add(int argc, VALUE *argv, VALUE self) {/*{{{*/
  sox_effects_chain_t *c_chain;
  sox_effect_t *c_effect;
  sox_format_t *c_input, *c_output, *c_tmp_format;
  VALUE name, options, tmp, input, output;
  sox_effect_handler_t const *c_handler;
  char *c_options[10], *c_name;
  int i, j, t;
  rsox_block_with_id_t *block_param;

  rb_scan_args(argc, argv, "1*", &name, &options);

  c_name = StringValuePtr(name);

  if (strncmp(c_name, "block", 5) == 0) {
    if (!rb_block_given_p())
      rb_raise(rb_eArgError, "no block given");

    c_handler = rsox_rubyblock_handler();
    c_effect = sox_create_effect(c_handler);

    block_param  = (rsox_block_with_id_t *)c_effect->priv;
    block_param->block = rb_block_proc();
    block_param->func  = rb_intern("call");
  } else {
    c_handler = sox_find_effect(StringValuePtr(name));
    if (c_handler == NULL)
      rb_raise(rb_eArgError, "no such effect: %s", StringValuePtr(name));
    c_effect = sox_create_effect(c_handler);

    for (i = j = 0; i < RARRAY_LEN(options); i++) {
      if (TYPE(RARRAY_PTR(options)[i]) == T_DATA) {
        Data_Get_Struct(RARRAY_PTR(options)[i], sox_format_t, c_tmp_format);
        c_options[j++] = (char *)c_tmp_format;
      } else {
        tmp = rb_check_string_type(RARRAY_PTR(options)[i]);
        c_options[j++] = NIL_P(tmp) ? NULL : RSTRING_PTR(tmp);
      }
    }

    i = sox_effect_options(c_effect, j, j > 0 ? c_options : NULL);
    if (i != SOX_SUCCESS)
      rb_raise(rb_eArgError, "wrong arguments (%d)", j);
  }

  Data_Get_Struct(self, sox_effects_chain_t, c_chain);
  Data_Get_Struct(rb_iv_get(self, "@input"),  sox_format_t, c_input);
  Data_Get_Struct(rb_iv_get(self, "@output"), sox_format_t, c_output);

  i = sox_add_effect(c_chain, c_effect, &c_input->signal, &c_output->signal);

  return INT2NUM(i);
}/

#flow(*args) ⇒ Object

{{{



408
409
410
411
412
413
414
# File 'ext/rsox.c', line 408

VALUE rsoxeffectschain_flow(int argc, VALUE *argv, VALUE self) {/*{{{*/
  sox_effects_chain_t *c_chain;

  Data_Get_Struct(self, sox_effects_chain_t, c_chain);

  return INT2NUM(sox_flow_effects(c_chain, NULL, NULL));
}/