Class: Vdsp::DoubleBiquad
Class Method Summary collapse
Instance Method Summary collapse
- #apply(x) ⇒ Object
- #coefficients ⇒ Object
- #coefficients=(coefficients) ⇒ Object
-
#initialize(alloc_sections) ⇒ Object
constructor
Vdsp::DoubleBiquad.
Methods included from Biquad
Constructor Details
#initialize(alloc_sections) ⇒ Object
Vdsp::DoubleBiquad
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 |
# File 'ext/vdsp/vdsp.c', line 993
VALUE rb_double_biquad_initialize(VALUE self, VALUE alloc_sections)
{
VdspBiquadNativeResource *p = ALLOC(VdspBiquadNativeResource);
p->type = 'd';
p->coefs.ptr = NULL;
p->delay.ptr = NULL;
p->setup.ptr = NULL;
p->sections = 0;
p->alloc_sections = 0;
VALUE resource = Data_Wrap_Struct(CLASS_OF(self), 0, vdsp_biquad_native_resource_delete, p);
rb_iv_set(self, "native_resource", resource);
long _alloc_sections = NUM2LONG(alloc_sections);
if (_alloc_sections<1) {
_alloc_sections = 1;
}
p->coefs.ptr = calloc(_alloc_sections*5, sizeof(double));
p->delay.ptr = calloc(_alloc_sections*2+2, sizeof(double));
p->alloc_sections = _alloc_sections;
return self;
}
|
Class Method Details
.create(coefficients) ⇒ Object
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 |
# File 'ext/vdsp/vdsp.c', line 1078
VALUE rb_double_biquad_create(VALUE cls, VALUE coefficients)
{
coefficients = rb_ary_new3(1, coefficients);
coefficients = rb_funcall(coefficients, rb_intern("flatten"), 0);
VALUE len = LONG2NUM(RARRAY_LEN(coefficients));
VALUE obj = rb_class_new_instance(1, &len, rb_cDoubleBiquad);
rb_double_biquad_set_coefficients(obj, coefficients);
return obj;
}
|
Instance Method Details
#apply(x) ⇒ Object
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 |
# File 'ext/vdsp/vdsp.c', line 1090
VALUE rb_double_biquad_apply(VALUE self, VALUE x)
{
//x = rb_funcall(x, rb_intern("to_da"), 0);
x = rb_funcall(rb_cDoubleArray, rb_intern("create"), 1, x);
VdspArrayNativeResource *_x = get_vdsp_array_native_resource(x);
VALUE lenv = LONG2NUM(_x->length);
VALUE y = rb_class_new_instance(1, &lenv, rb_cDoubleArray);
VdspArrayNativeResource *_y = get_vdsp_array_native_resource(y);
VdspBiquadNativeResource *_b = get_vdsp_biquad_native_resource(self);
vDSP_biquadD(_b->setup.d, _b->delay.d, _x->v.d, 1, _y->v.d, 1, _x->length);
return y;
}
|
#coefficients ⇒ Object
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 |
# File 'ext/vdsp/vdsp.c', line 1056
VALUE rb_double_biquad_get_coefficients(VALUE self)
{
VdspBiquadNativeResource *p = get_vdsp_biquad_native_resource(self);
VALUE ret = rb_ary_new2(p->sections);
VALUE rb_cBiquadCoefficient = rb_const_get(rb_mVdspBiquad, rb_intern("Coefficient"));
for (unsigned long i=0; i<p->sections; i++) {
VALUE argv[5] = {
DBL2NUM(p->coefs.d[i*5+0]),
DBL2NUM(p->coefs.d[i*5+1]),
DBL2NUM(p->coefs.d[i*5+2]),
DBL2NUM(p->coefs.d[i*5+3]),
DBL2NUM(p->coefs.d[i*5+4])
};
VALUE coef = rb_class_new_instance(5, argv, rb_cBiquadCoefficient);
rb_ary_push(ret, coef);
}
return ret;
}
|
#coefficients=(coefficients) ⇒ Object
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 |
# File 'ext/vdsp/vdsp.c', line 1017
VALUE rb_double_biquad_set_coefficients(VALUE self, VALUE coefficients)
{
VdspBiquadNativeResource *p = get_vdsp_biquad_native_resource(self);
coefficients = rb_ary_new3(1, coefficients);
coefficients = rb_funcall(coefficients, rb_intern("flatten"), 0);
VALUE rb_cBiquadCoefficient = rb_const_get(rb_mVdspBiquad, rb_intern("Coefficient"));
unsigned long sections = RARRAY_LEN(coefficients);
if (p->alloc_sections<sections) {
rb_raise(rb_eArgError, "over sections: sections=%ld alloc_sections=%ld", sections, p->alloc_sections);
}
for (unsigned long i=0; i<sections; i++) {
VALUE coefficient = RARRAY_AREF(coefficients, i);
if (!rb_obj_is_kind_of(coefficient, rb_cBiquadCoefficient)) {
rb_raise(rb_eArgError, "Vdsp::Biquad::Coefficient required");
}
}
for (unsigned long i=0; i<sections; i++) {
VALUE coefficient = RARRAY_AREF(coefficients, i);
p->coefs.d[i*5+0] = NUM2DBL(rb_funcall(coefficient, rb_intern("b0"), 0));
p->coefs.d[i*5+1] = NUM2DBL(rb_funcall(coefficient, rb_intern("b1"), 0));
p->coefs.d[i*5+2] = NUM2DBL(rb_funcall(coefficient, rb_intern("b2"), 0));
p->coefs.d[i*5+3] = NUM2DBL(rb_funcall(coefficient, rb_intern("a1"), 0));
p->coefs.d[i*5+4] = NUM2DBL(rb_funcall(coefficient, rb_intern("a2"), 0));
}
if (p->setup.d) {
vDSP_biquad_DestroySetupD(p->setup.d);
}
p->setup.d = vDSP_biquad_CreateSetupD(p->coefs.d, sections);
p->sections = sections;
return self;
}
|