vdsp 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/vdsp/vdsp.c +80 -49
- data/ext/vdsp/vdsp.h +1 -0
- data/lib/vdsp/version.rb +1 -1
- data/vdsp.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2358672ca07fa482ca8592ac9e49d9c4eca38b7bc2b7d3a137765032fdf4cc8b
|
4
|
+
data.tar.gz: 9bc65fad63980a3fb482092feea369f89907870c46f30309cbe332f3bdf99744
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf33f3a43ffcabf3407daec1184b21253085e0d1bbf665c4206546f2612ca0b8ab5e3f186c594931102d704c1475da74372efb3d6f86c171a8f3ed1a81a99a0
|
7
|
+
data.tar.gz: d784d6291d25137935380e3bb719ae530482c785b471d2be91b97fe51fa2868695eb0b7b51383d8b03a2389fa1e6c1262c4f149a776d3bc7660aa77696c609e0
|
data/ext/vdsp/vdsp.c
CHANGED
@@ -91,19 +91,6 @@ VdspBiquadNativeResource* get_vdsp_biquad_native_resource(VALUE vb)
|
|
91
91
|
return p;
|
92
92
|
}
|
93
93
|
|
94
|
-
VdspBiquadSetup get_vdsp_biquad_setup(VALUE vb)
|
95
|
-
{
|
96
|
-
VdspBiquadNativeResource *p = get_vdsp_biquad_native_resource(vb);
|
97
|
-
return p->setup;
|
98
|
-
}
|
99
|
-
|
100
|
-
long get_vdsp_biquad_sections(VALUE vb)
|
101
|
-
{
|
102
|
-
VdspBiquadNativeResource *_b = get_vdsp_biquad_native_resource(vb);
|
103
|
-
return _b->sections;
|
104
|
-
}
|
105
|
-
|
106
|
-
|
107
94
|
|
108
95
|
// Vdsp::DoubleScalar
|
109
96
|
|
@@ -660,39 +647,65 @@ VALUE rb_double_array_svs(VALUE self)
|
|
660
647
|
|
661
648
|
VALUE rb_vdsp_biquad_sections(VALUE self)
|
662
649
|
{
|
663
|
-
|
650
|
+
VdspBiquadNativeResource *p = get_vdsp_biquad_native_resource(self);
|
651
|
+
return LONG2NUM(p->sections);
|
652
|
+
}
|
653
|
+
|
654
|
+
VALUE rb_vdsp_biquad_alloc_sections(VALUE self)
|
655
|
+
{
|
656
|
+
VdspBiquadNativeResource *p = get_vdsp_biquad_native_resource(self);
|
657
|
+
return LONG2NUM(p->alloc_sections);
|
664
658
|
}
|
665
659
|
|
666
660
|
|
667
661
|
// Vdsp::DoubleBiquad
|
668
662
|
|
669
|
-
VALUE rb_double_biquad_initialize(VALUE self, VALUE
|
663
|
+
VALUE rb_double_biquad_initialize(VALUE self, VALUE alloc_sections)
|
670
664
|
{
|
665
|
+
VdspBiquadNativeResource *p = ALLOC(VdspBiquadNativeResource);
|
666
|
+
p->type = 'd';
|
667
|
+
p->coefs.ptr = NULL;
|
668
|
+
p->delay.ptr = NULL;
|
669
|
+
p->setup.ptr = NULL;
|
670
|
+
p->sections = 0;
|
671
|
+
p->alloc_sections = 0;
|
672
|
+
|
673
|
+
VALUE resource = Data_Wrap_Struct(CLASS_OF(self), 0, vdsp_biquad_native_resource_delete, p);
|
674
|
+
rb_iv_set(self, "native_resource", resource);
|
675
|
+
|
676
|
+
long _alloc_sections = NUM2LONG(alloc_sections);
|
677
|
+
if (_alloc_sections<1) {
|
678
|
+
_alloc_sections = 1;
|
679
|
+
}
|
680
|
+
p->coefs.ptr = calloc(_alloc_sections*5, sizeof(double));
|
681
|
+
p->delay.ptr = calloc(_alloc_sections*2+2, sizeof(double));
|
682
|
+
p->alloc_sections = _alloc_sections;
|
683
|
+
|
684
|
+
return self;
|
685
|
+
}
|
686
|
+
|
687
|
+
VALUE rb_double_biquad_set_coefficients(VALUE self, VALUE coefficients)
|
688
|
+
{
|
689
|
+
VdspBiquadNativeResource *p = get_vdsp_biquad_native_resource(self);
|
690
|
+
|
671
691
|
coefficients = rb_ary_new3(1, coefficients);
|
672
692
|
coefficients = rb_funcall(coefficients, rb_intern("flatten"), 0);
|
673
693
|
|
674
694
|
VALUE rb_cBiquadCoefficient = rb_const_get(rb_mVdspBiquad, rb_intern("Coefficient"));
|
675
695
|
|
676
|
-
long sections = RARRAY_LEN(coefficients);
|
677
|
-
|
696
|
+
unsigned long sections = RARRAY_LEN(coefficients);
|
697
|
+
if (p->alloc_sections<sections) {
|
698
|
+
rb_raise(rb_eArgError, "over sections: sections=%ld alloc_sections=%ld", sections, p->alloc_sections);
|
699
|
+
}
|
700
|
+
|
701
|
+
for (unsigned long i=0; i<sections; i++) {
|
678
702
|
VALUE coefficient = RARRAY_AREF(coefficients, i);
|
679
703
|
if (!rb_obj_is_kind_of(coefficient, rb_cBiquadCoefficient)) {
|
680
704
|
rb_raise(rb_eArgError, "Vdsp::Biquad::Coefficient required");
|
681
705
|
}
|
682
706
|
}
|
683
707
|
|
684
|
-
|
685
|
-
p->type = 'd';
|
686
|
-
p->coefs.ptr = NULL;
|
687
|
-
p->delay.ptr = NULL;
|
688
|
-
p->setup.ptr = NULL;
|
689
|
-
p->sections = 0;
|
690
|
-
|
691
|
-
VALUE resource = Data_Wrap_Struct(CLASS_OF(self), 0, vdsp_biquad_native_resource_delete, p);
|
692
|
-
rb_iv_set(self, "native_resource", resource);
|
693
|
-
|
694
|
-
p->coefs.ptr = calloc(sections*5, sizeof(double));
|
695
|
-
for (long i=0; i<sections; i++) {
|
708
|
+
for (unsigned long i=0; i<sections; i++) {
|
696
709
|
VALUE coefficient = RARRAY_AREF(coefficients, i);
|
697
710
|
p->coefs.d[i*5+0] = NUM2DBL(rb_funcall(coefficient, rb_intern("b0"), 0));
|
698
711
|
p->coefs.d[i*5+1] = NUM2DBL(rb_funcall(coefficient, rb_intern("b1"), 0));
|
@@ -700,31 +713,17 @@ VALUE rb_double_biquad_initialize(VALUE self, VALUE coefficients)
|
|
700
713
|
p->coefs.d[i*5+3] = NUM2DBL(rb_funcall(coefficient, rb_intern("a1"), 0));
|
701
714
|
p->coefs.d[i*5+4] = NUM2DBL(rb_funcall(coefficient, rb_intern("a2"), 0));
|
702
715
|
}
|
703
|
-
|
716
|
+
|
717
|
+
if (p->setup.d) {
|
718
|
+
vDSP_biquad_DestroySetupD(p->setup.d);
|
719
|
+
}
|
704
720
|
p->setup.d = vDSP_biquad_CreateSetupD(p->coefs.d, sections);
|
705
721
|
p->sections = sections;
|
706
722
|
|
707
723
|
return self;
|
708
724
|
}
|
709
725
|
|
710
|
-
VALUE
|
711
|
-
{
|
712
|
-
//x = rb_funcall(x, rb_intern("to_da"), 0);
|
713
|
-
x = rb_funcall(rb_cDoubleArray, rb_intern("create"), 1, x);
|
714
|
-
VdspArrayNativeResource *_x = get_vdsp_array_native_resource(x);
|
715
|
-
|
716
|
-
VALUE lenv = LONG2NUM(_x->length);
|
717
|
-
VALUE y = rb_class_new_instance(1, &lenv, rb_cDoubleArray);
|
718
|
-
VdspArrayNativeResource *_y = get_vdsp_array_native_resource(y);
|
719
|
-
|
720
|
-
VdspBiquadNativeResource *_b = get_vdsp_biquad_native_resource(self);
|
721
|
-
|
722
|
-
vDSP_biquadD(_b->setup.d, _b->delay.d, _x->v.d, 1, _y->v.d, 1, _x->length);
|
723
|
-
|
724
|
-
return y;
|
725
|
-
}
|
726
|
-
|
727
|
-
VALUE rb_double_biquad_coefficients(VALUE self)
|
726
|
+
VALUE rb_double_biquad_get_coefficients(VALUE self)
|
728
727
|
{
|
729
728
|
VdspBiquadNativeResource *p = get_vdsp_biquad_native_resource(self);
|
730
729
|
VALUE ret = rb_ary_new2(p->sections);
|
@@ -746,6 +745,35 @@ VALUE rb_double_biquad_coefficients(VALUE self)
|
|
746
745
|
return ret;
|
747
746
|
}
|
748
747
|
|
748
|
+
VALUE rb_double_biquad_create(VALUE cls, VALUE coefficients)
|
749
|
+
{
|
750
|
+
coefficients = rb_ary_new3(1, coefficients);
|
751
|
+
coefficients = rb_funcall(coefficients, rb_intern("flatten"), 0);
|
752
|
+
|
753
|
+
VALUE len = LONG2NUM(RARRAY_LEN(coefficients));
|
754
|
+
VALUE obj = rb_class_new_instance(1, &len, rb_cDoubleBiquad);
|
755
|
+
rb_double_biquad_set_coefficients(obj, coefficients);
|
756
|
+
|
757
|
+
return obj;
|
758
|
+
}
|
759
|
+
|
760
|
+
VALUE rb_double_biquad_apply(VALUE self, VALUE x)
|
761
|
+
{
|
762
|
+
//x = rb_funcall(x, rb_intern("to_da"), 0);
|
763
|
+
x = rb_funcall(rb_cDoubleArray, rb_intern("create"), 1, x);
|
764
|
+
VdspArrayNativeResource *_x = get_vdsp_array_native_resource(x);
|
765
|
+
|
766
|
+
VALUE lenv = LONG2NUM(_x->length);
|
767
|
+
VALUE y = rb_class_new_instance(1, &lenv, rb_cDoubleArray);
|
768
|
+
VdspArrayNativeResource *_y = get_vdsp_array_native_resource(y);
|
769
|
+
|
770
|
+
VdspBiquadNativeResource *_b = get_vdsp_biquad_native_resource(self);
|
771
|
+
|
772
|
+
vDSP_biquadD(_b->setup.d, _b->delay.d, _x->v.d, 1, _y->v.d, 1, _x->length);
|
773
|
+
|
774
|
+
return y;
|
775
|
+
}
|
776
|
+
|
749
777
|
|
750
778
|
// Vdsp static method
|
751
779
|
|
@@ -2151,13 +2179,16 @@ void Init_vdsp()
|
|
2151
2179
|
// Vdsp::Biquad
|
2152
2180
|
rb_mVdspBiquad = rb_define_module_under(rb_mVdsp, "Biquad");
|
2153
2181
|
rb_define_method(rb_mVdspBiquad, "sections", rb_vdsp_biquad_sections, 0);
|
2182
|
+
rb_define_method(rb_mVdspBiquad, "alloc_sections", rb_vdsp_biquad_alloc_sections, 0);
|
2154
2183
|
|
2155
2184
|
// Vdsp::DoubleBiquad
|
2156
2185
|
rb_cDoubleBiquad = rb_define_class_under(rb_mVdsp, "DoubleBiquad", rb_cObject);
|
2157
2186
|
rb_include_module(rb_cDoubleBiquad, rb_mVdspBiquad);
|
2158
2187
|
rb_define_method(rb_cDoubleBiquad, "initialize", rb_double_biquad_initialize, 1);
|
2188
|
+
rb_define_singleton_method(rb_cDoubleBiquad, "create", rb_double_biquad_create, 1);
|
2189
|
+
rb_define_method(rb_cDoubleBiquad, "coefficients=", rb_double_biquad_set_coefficients, 1);
|
2190
|
+
rb_define_method(rb_cDoubleBiquad, "coefficients", rb_double_biquad_get_coefficients, 0);
|
2159
2191
|
rb_define_method(rb_cDoubleBiquad, "apply", rb_double_biquad_apply, 1);
|
2160
|
-
rb_define_method(rb_cDoubleBiquad, "coefficients", rb_double_biquad_coefficients, 0);
|
2161
2192
|
|
2162
2193
|
// Vdsp::UnsafeDouble
|
2163
2194
|
rb_mUnsafeDouble = rb_define_module_under(rb_mVdsp, "UnsafeDouble");
|
data/ext/vdsp/vdsp.h
CHANGED
data/lib/vdsp/version.rb
CHANGED
data/vdsp.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "vdsp/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "vdsp"
|
7
7
|
spec.version = Vdsp::VERSION
|
8
|
-
spec.authors = ["
|
8
|
+
spec.authors = ["Yoshida Tetsuya"]
|
9
9
|
spec.email = ["yoshida.eth0@gmail.com"]
|
10
10
|
|
11
11
|
spec.summary = %q{Perform basic arithmetic operations and common digital signal processing routines on large vectors.}
|