noyes 0.9.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/VERSION +1 -1
  2. data/bin/nrec +5 -0
  3. data/lib/{c_impl → cext}/array_list.c +25 -25
  4. data/lib/cext/bent_cent_marker.c +55 -0
  5. data/lib/{c_impl/n_array_list.c → cext/c_array_list.c} +12 -12
  6. data/lib/cext/c_array_list.h +18 -0
  7. data/lib/{c_impl/n_bent_cent_marker.c → cext/c_bent_cent_marker.c} +13 -11
  8. data/lib/{c_impl/n_dft.c → cext/c_dft.c} +3 -3
  9. data/lib/{c_impl/n_discrete_cosine_transform.c → cext/c_discrete_cosine_transform.c} +5 -5
  10. data/lib/{c_impl/n_hamming_window.c → cext/c_hamming_window.c} +5 -5
  11. data/lib/{c_impl/n_live_cmn.c → cext/c_live_cmn.c} +5 -5
  12. data/lib/{c_impl/n_log_compressor.c → cext/c_log_compressor.c} +5 -5
  13. data/lib/cext/c_matrix.c +90 -0
  14. data/lib/{c_impl/n_mel_filter.c → cext/c_mel_filter.c} +13 -11
  15. data/lib/cext/c_mfcc_16x8.c +57 -0
  16. data/lib/{c_impl/noyes.h → cext/c_noyes.h} +50 -47
  17. data/lib/{c_impl/n_power_spec.c → cext/c_power_spec.c} +6 -6
  18. data/lib/{c_impl/n_preemphasis.c → cext/c_preemphasis.c} +4 -4
  19. data/lib/{c_impl/n_segmenter.c → cext/c_segmenter.c} +17 -11
  20. data/lib/cext/c_speech_trimmer.c +126 -0
  21. data/lib/{c_impl → cext}/discrete_cosine_transform.c +18 -20
  22. data/lib/{c_impl → cext}/hamming_window.c +11 -13
  23. data/lib/{c_impl → cext}/live_cmn.c +11 -14
  24. data/lib/{c_impl → cext}/log_compressor.c +11 -14
  25. data/lib/{c_impl → cext}/mel_filter.c +13 -17
  26. data/lib/cext/mfcc_16x8.c +36 -0
  27. data/lib/{c_impl → cext}/power_spectrum.c +10 -12
  28. data/lib/{c_impl → cext}/preemphasis.c +10 -13
  29. data/lib/{c_impl/noyes_c.c → cext/r_noyes.c} +12 -12
  30. data/lib/{c_impl/rnoyes.h → cext/r_noyes.h} +6 -6
  31. data/lib/{c_impl → cext}/segmenter.c +10 -13
  32. data/lib/{c_impl → cext}/speech_trimmer.c +23 -23
  33. data/lib/common/noyes_dsl.rb +3 -0
  34. data/lib/common/ruby_ext.rb +9 -0
  35. data/lib/noyes.rb +13 -0
  36. data/lib/noyes_c.rb +23 -1
  37. data/lib/noyes_java.rb +5 -0
  38. data/lib/ruby_impl/compression.rb +214 -0
  39. data/lib/ruby_impl/dct.rb +2 -2
  40. data/lib/ruby_impl/live_cmn.rb +4 -4
  41. data/lib/ruby_impl/mel_filter.rb +9 -9
  42. data/lib/ruby_impl/segment.rb +13 -2
  43. data/lib/ruby_impl/speech_trimmer.rb +3 -1
  44. data/ship/noyes.jar +0 -0
  45. metadata +36 -34
  46. data/lib/c_impl/bent_cent_marker.c +0 -36
  47. data/lib/c_impl/fast_8k_mfcc.c +0 -39
  48. data/lib/c_impl/n_array_list.h +0 -18
  49. data/lib/c_impl/n_fast_8k_mfcc.c +0 -55
  50. data/lib/c_impl/n_matrix.c +0 -72
  51. data/lib/c_impl/n_speech_trimmer.c +0 -96
  52. /data/lib/{c_impl → cext}/extconf.rb +0 -0
@@ -1,17 +1,15 @@
1
- #include "noyes.h"
2
- #include "rnoyes.h"
1
+ #include "c_noyes.h"
2
+ #include "r_noyes.h"
3
3
  #include "math.h"
4
4
 
5
- static int id_push;
6
-
7
5
  VALUE cMelFilter;
8
6
 
9
- static void mel_filter_free(void *p) {
10
- free_mel_filter(p);
7
+ static void _mel_filter_free(void *p) {
8
+ mel_filter_free(p);
11
9
  }
12
10
 
13
11
  static VALUE t_make_filter(VALUE self, VALUE(left), VALUE(center), VALUE(right), VALUE(init_freq), VALUE(delta)) {
14
- NMatrix1 *d = make_filter(NUM2DBL(left), NUM2DBL(center),
12
+ Carr *d = make_filter(NUM2DBL(left), NUM2DBL(center),
15
13
  NUM2DBL(right), NUM2DBL(init_freq), NUM2DBL(delta));
16
14
  if (d) {
17
15
  VALUE result = rb_ary_new2(2);
@@ -22,7 +20,7 @@ static VALUE t_make_filter(VALUE self, VALUE(left), VALUE(center), VALUE(right),
22
20
  rb_ary_store(filt, i-1, rb_float_new(d->data[i]));
23
21
  }
24
22
  rb_ary_store(result, 1, filt);
25
- free_nmatrix1(d);
23
+ carr_free(d);
26
24
  return result;
27
25
  }
28
26
  return Qnil;
@@ -38,7 +36,7 @@ static VALUE t_to_linear(VALUE self, VALUE f) {
38
36
 
39
37
  static VALUE t_make_bank_parameters(VALUE self, VALUE srate, VALUE nfft,
40
38
  VALUE nfilt, VALUE lowerf, VALUE upperf) {
41
- NMatrix *d = make_bank_parameters(NUM2INT(srate), NUM2INT(nfft),
39
+ Cmat *d = make_bank_parameters(NUM2INT(srate), NUM2INT(nfft),
42
40
  NUM2INT(nfilt), NUM2INT(lowerf), NUM2INT(upperf));
43
41
  if (d) {
44
42
  VALUE result = rb_ary_new2(d->rows);
@@ -50,7 +48,7 @@ static VALUE t_make_bank_parameters(VALUE self, VALUE srate, VALUE nfft,
50
48
  rb_ary_store(row, j, rb_float_new(d->data[i][j]));
51
49
  }
52
50
  }
53
- free_nmatrix(d);
51
+ cmat_free(d);
54
52
  return result;
55
53
  }
56
54
  return Qnil;
@@ -71,18 +69,19 @@ static VALUE t_init(VALUE self, VALUE args) {
71
69
  upperf = NUM2INT(rb_ary_entry(args, 4));
72
70
 
73
71
  MelFilter *s = new_mel_filter(srate, nfft, nfilt, lowerf, upperf);
74
- VALUE mel_filter = Data_Wrap_Struct(cMelFilter, 0, mel_filter_free, s);
72
+ VALUE mel_filter = Data_Wrap_Struct(cMelFilter, 0, _mel_filter_free, s);
75
73
  rb_iv_set(self, "@mel_filter", mel_filter);
76
74
 
77
75
  return self;
78
76
  }
79
77
 
80
78
  static VALUE t_left_shift(VALUE self, VALUE obj) {
81
- NMatrix *M = v_2_nmatrix(obj);
79
+ Cmat *M = r2cmat(obj);
82
80
  VALUE mel_filter = rb_iv_get(self, "@mel_filter");
83
81
  MelFilter *s;
84
82
  Data_Get_Struct(mel_filter, MelFilter, s);
85
- NMatrix *d = mel_filter_apply(s, M);
83
+ Cmat *d = mel_filter_apply(s, M);
84
+ cmat_free(M);
86
85
 
87
86
  if (d) {
88
87
  VALUE result = rb_ary_new2(d->rows);
@@ -94,13 +93,12 @@ static VALUE t_left_shift(VALUE self, VALUE obj) {
94
93
  rb_ary_store(row, j, rb_float_new(d->data[i][j]));
95
94
  }
96
95
  }
97
- free_nmatrix(d);
96
+ cmat_free(d);
98
97
  return result;
99
98
  }
100
99
  return Qnil;
101
100
  }
102
101
 
103
-
104
102
  void Init_mel_filter() {
105
103
  VALUE m_noyes_c = rb_define_module("NoyesC");
106
104
  cMelFilter = rb_define_class_under(m_noyes_c, "MelFilter", rb_cObject);
@@ -110,6 +108,4 @@ void Init_mel_filter() {
110
108
  rb_define_module_function(cMelFilter, "make_filter", t_make_filter, 5);
111
109
  rb_define_module_function(cMelFilter, "to_linear", t_to_linear, 1);
112
110
  rb_define_module_function(cMelFilter, "to_mel", t_to_mel, 1);
113
- id_push = rb_intern("push");
114
111
  }
115
-
@@ -0,0 +1,36 @@
1
+ #include "ruby.h"
2
+ #include "c_noyes.h"
3
+ #include "r_noyes.h"
4
+
5
+ VALUE cMfcc16x8;
6
+
7
+ static void _mfcc_16x8_free(Mfcc16x8 *p) {
8
+ mfcc_16x8_free(p);
9
+ }
10
+
11
+ static VALUE t_init(VALUE self, VALUE args) {
12
+ Mfcc16x8 *s = mfcc_16x8_new();
13
+ VALUE mfcc_16x8 = Data_Wrap_Struct(cMfcc16x8, 0, _mfcc_16x8_free, s);
14
+ rb_iv_set(self, "@mfcc_16x8", mfcc_16x8);
15
+
16
+ return self;
17
+ }
18
+
19
+ static VALUE t_left_shift(VALUE self, VALUE obj) {
20
+ Carr *M = r2carr(obj);
21
+ VALUE mfcc_16x8 = rb_iv_get(self, "@mfcc_16x8");
22
+ Mfcc16x8 *s;
23
+ Data_Get_Struct(mfcc_16x8, Mfcc16x8, s);
24
+ Cmat *N = mfcc_16x8_apply(s, M);
25
+ VALUE result = cmat2r(N);
26
+ cmat_free(N);
27
+ carr_free(M);
28
+ return result;
29
+ }
30
+
31
+ void Init_mfcc_16x8() {
32
+ VALUE m_noyes_c = rb_define_module("NoyesC");
33
+ cMfcc16x8 = rb_define_class_under(m_noyes_c, "Mfcc16x8", rb_cObject);
34
+ rb_define_method(cMfcc16x8, "initialize", t_init, -2);
35
+ rb_define_method(cMfcc16x8, "<<", t_left_shift, 1);
36
+ }
@@ -1,13 +1,11 @@
1
1
  #include "ruby.h"
2
- #include "noyes.h"
3
- #include "rnoyes.h"
4
-
5
- static int id_push;
2
+ #include "c_noyes.h"
3
+ #include "r_noyes.h"
6
4
 
7
5
  VALUE cPowerSpectrum;
8
6
 
9
- static void power_spectrum_free(void *p) {
10
- free_power_spectrum(p);
7
+ static void _power_spectrum_free(void *p) {
8
+ power_spectrum_free(p);
11
9
  }
12
10
 
13
11
  static VALUE t_init(VALUE self, VALUE args) {
@@ -17,19 +15,20 @@ static VALUE t_init(VALUE self, VALUE args) {
17
15
  nfft = NUM2INT(rb_ary_entry(args, 0));
18
16
  }
19
17
  PowerSpectrum *ps = new_power_spectrum(nfft);
20
- VALUE psv = Data_Wrap_Struct(cPowerSpectrum, 0, power_spectrum_free, ps);
18
+ VALUE psv = Data_Wrap_Struct(cPowerSpectrum, 0, _power_spectrum_free, ps);
21
19
  rb_iv_set(self, "@ps", psv);
22
20
  return self;
23
21
  }
24
22
 
25
23
  static VALUE t_left_shift(VALUE self, VALUE obj) {
26
- NMatrix *M = v_2_nmatrix(obj);
24
+ Cmat *M = r2cmat(obj);
27
25
  PowerSpectrum *ps;
28
26
  VALUE psv = rb_iv_get(self, "@ps");
29
27
  Data_Get_Struct(psv, PowerSpectrum, ps);
30
- NMatrix *N = power_spectrum_apply(ps, M);
31
- VALUE result = nmatrix_2_v(N);
32
- free_nmatrix(N);
28
+ Cmat *N = power_spectrum_apply(ps, M);
29
+ VALUE result = cmat2r(N);
30
+ cmat_free(N);
31
+ cmat_free(M);
33
32
  return result;
34
33
  }
35
34
 
@@ -38,5 +37,4 @@ void Init_power_spectrum() {
38
37
  cPowerSpectrum = rb_define_class_under(m_noyes_c, "PowerSpectrumFilter", rb_cObject);
39
38
  rb_define_method(cPowerSpectrum, "initialize", t_init, -2);
40
39
  rb_define_method(cPowerSpectrum, "<<", t_left_shift, 1);
41
- id_push = rb_intern("push");
42
40
  }
@@ -1,13 +1,11 @@
1
1
  #include "ruby.h"
2
- #include "noyes.h"
3
- #include "rnoyes.h"
4
-
5
- static int id_push;
2
+ #include "c_noyes.h"
3
+ #include "r_noyes.h"
6
4
 
7
5
  VALUE cPreemphasizer;
8
6
 
9
- static void preemphasizer_free(void *p) {
10
- free_preemphasizer(p);
7
+ static void _preemphasizer_free(void *p) {
8
+ preemphasizer_free(p);
11
9
  }
12
10
 
13
11
  static VALUE t_init(VALUE self, VALUE args) {
@@ -17,20 +15,20 @@ static VALUE t_init(VALUE self, VALUE args) {
17
15
  factor = NUM2DBL(rb_ary_entry(args, 0));
18
16
  }
19
17
  Preemphasizer *pre = new_preemphasizer(factor);
20
- VALUE prev = Data_Wrap_Struct(cPreemphasizer, 0, preemphasizer_free, pre);
18
+ VALUE prev = Data_Wrap_Struct(cPreemphasizer, 0, _preemphasizer_free, pre);
21
19
  rb_iv_set(self, "@preemphasizer", prev);
22
20
  return self;
23
21
  }
24
22
 
25
23
  static VALUE t_left_shift(VALUE self, VALUE obj) {
26
- NMatrix1 *M = v_2_nmatrix1(obj);
24
+ Carr *M = r2carr(obj);
27
25
  Preemphasizer *pre;
28
26
  VALUE prev = rb_iv_get(self, "@preemphasizer");
29
27
  Data_Get_Struct(prev, Preemphasizer, pre);
30
- NMatrix1 *N = preemphasizer_apply(pre, M);
31
- VALUE result = nmatrix1_2_v(N);
32
- free_nmatrix1(N);
33
- free_nmatrix1(M);
28
+ Carr *N = preemphasizer_apply(pre, M);
29
+ VALUE result = carr2r(N);
30
+ carr_free(N);
31
+ carr_free(M);
34
32
  return result;
35
33
  }
36
34
 
@@ -39,5 +37,4 @@ void Init_preemphasis() {
39
37
  cPreemphasizer = rb_define_class_under(m_noyes_c, "Preemphasizer", rb_cObject);
40
38
  rb_define_method(cPreemphasizer, "initialize", t_init, -2);
41
39
  rb_define_method(cPreemphasizer, "<<", t_left_shift, 1);
42
- id_push = rb_intern("push");
43
40
  }
@@ -1,9 +1,9 @@
1
- #include "noyes.h"
2
- #include "rnoyes.h"
1
+ #include "c_noyes.h"
2
+ #include "r_noyes.h"
3
3
 
4
4
  // Wrappers for matrix class
5
- NMatrix * v_2_nmatrix(VALUE value) {
6
- NMatrix *M = NULL;
5
+ Cmat * r2cmat(VALUE value) {
6
+ Cmat *M = NULL;
7
7
  int rows = RARRAY_LEN(value);
8
8
  int cols = 0;
9
9
  if (rows > 0) {
@@ -13,7 +13,7 @@ NMatrix * v_2_nmatrix(VALUE value) {
13
13
  rb_raise(rb_eTypeError, "Matrix one dimensional instead of two");
14
14
  }
15
15
  cols = RARRAY_LEN(colzero);
16
- M = new_nmatrix(rows,cols);
16
+ M = cmat_new(rows,cols);
17
17
  int i,j;
18
18
  for (i=0;i<rows;++i) {
19
19
  VALUE col = rb_ary_entry(value, i);
@@ -25,7 +25,7 @@ NMatrix * v_2_nmatrix(VALUE value) {
25
25
  return M;
26
26
  }
27
27
 
28
- VALUE nmatrix_2_v(NMatrix *M) {
28
+ VALUE cmat2r(Cmat *M) {
29
29
  VALUE v = Qnil;
30
30
  if (M) {
31
31
  v = rb_ary_new2(M->rows);
@@ -42,8 +42,8 @@ VALUE nmatrix_2_v(NMatrix *M) {
42
42
  return v;
43
43
  }
44
44
 
45
- NMatrix1 * v_2_nmatrix1(VALUE value) {
46
- NMatrix1 *M = NULL;
45
+ Carr * r2carr(VALUE value) {
46
+ Carr *M = NULL;
47
47
  int rows = RARRAY_LEN(value);
48
48
  if (rows > 0) {
49
49
  VALUE colzero = rb_ary_entry(value, 0);
@@ -51,7 +51,7 @@ NMatrix1 * v_2_nmatrix1(VALUE value) {
51
51
  if (!NIL_P(colzero)) {
52
52
  rb_raise(rb_eTypeError, "Matrix two dimensional instead of one");
53
53
  }
54
- M = new_nmatrix1(rows);
54
+ M = carr_new(rows);
55
55
  int i;
56
56
  for (i=0;i<rows;++i) {
57
57
  VALUE val = rb_ary_entry(value, i);
@@ -61,7 +61,7 @@ NMatrix1 * v_2_nmatrix1(VALUE value) {
61
61
  return M;
62
62
  }
63
63
 
64
- VALUE nmatrix1_2_v(NMatrix1 *M) {
64
+ VALUE carr2r(Carr *M) {
65
65
  VALUE v = Qnil;
66
66
  if (M) {
67
67
  v = rb_ary_new2(M->rows);
@@ -83,9 +83,9 @@ void Init_noyes_c() {
83
83
  Init_mel_filter();
84
84
  Init_log_compressor();
85
85
  Init_live_cmn();
86
- Init_fast_8k_mfcc();
86
+ Init_mfcc_16x8();
87
87
  Init_dct();
88
88
  Init_bent_cent_marker();
89
89
  Init_speech_trimmer();
90
- Init_n_list();
90
+ Init_clist();
91
91
  }
@@ -7,14 +7,14 @@ void Init_power_spectrum();
7
7
  void Init_mel_filter();
8
8
  void Init_log_compressor();
9
9
  void Init_live_cmn();
10
- void Init_fast_8k_mfcc();
10
+ void Init_mfcc_16x8();
11
11
  void Init_dct();
12
12
  void Init_bent_cent_marker();
13
13
  void Init_speech_trimmer();
14
- void Init_n_list();
14
+ void Init_clist();
15
15
 
16
- VALUE nmatrix_2_v(NMatrix *d);
17
- NMatrix * v_2_nmatrix(VALUE value);
16
+ VALUE cmat2r(Cmat *d);
17
+ Cmat * r2cmat(VALUE value);
18
18
 
19
- VALUE nmatrix1_2_v(NMatrix1 *d);
20
- NMatrix1 * v_2_nmatrix1(VALUE value);
19
+ VALUE carr2r(Carr *d);
20
+ Carr * r2carr(VALUE value);
@@ -1,13 +1,11 @@
1
1
  #include "ruby.h"
2
- #include "noyes.h"
3
- #include "rnoyes.h"
4
-
5
- static int id_push;
2
+ #include "c_noyes.h"
3
+ #include "r_noyes.h"
6
4
 
7
5
  VALUE cSegmenter;
8
6
 
9
- static void segmenter_free(void *p) {
10
- free_segmenter(p);
7
+ static void _segmenter_free(void *p) {
8
+ segmenter_free(p);
11
9
  }
12
10
  static VALUE t_init(VALUE self, VALUE args) {
13
11
  int winsz = 205;
@@ -21,21 +19,21 @@ static VALUE t_init(VALUE self, VALUE args) {
21
19
  }
22
20
 
23
21
  Segmenter *s = new_segmenter(winsz, winshift);
24
- VALUE segmenter = Data_Wrap_Struct(cSegmenter, 0, segmenter_free, s);
22
+ VALUE segmenter = Data_Wrap_Struct(cSegmenter, 0, _segmenter_free, s);
25
23
  rb_iv_set(self, "@segmenter", segmenter);
26
24
 
27
25
  return self;
28
26
  }
29
27
 
30
28
  static VALUE t_left_shift(VALUE self, VALUE obj) {
31
- NMatrix1 *M = v_2_nmatrix1(obj);
29
+ Carr *M = r2carr(obj);
32
30
  VALUE segmenter = rb_iv_get(self, "@segmenter");
33
31
  Segmenter *s;
34
32
  Data_Get_Struct(segmenter, Segmenter, s);
35
- NMatrix *N = segmenter_apply(s, M);
36
- VALUE result = nmatrix_2_v(N);
37
- free_nmatrix(N);
38
- free_nmatrix1(M);
33
+ Cmat *N = segmenter_apply(s, M);
34
+ VALUE result = cmat2r(N);
35
+ cmat_free(N);
36
+ carr_free(M);
39
37
  return result;
40
38
  }
41
39
 
@@ -44,5 +42,4 @@ void Init_segmenter() {
44
42
  cSegmenter = rb_define_class_under(m_noyes_c, "Segmenter", rb_cObject);
45
43
  rb_define_method(cSegmenter, "initialize", t_init, -2);
46
44
  rb_define_method(cSegmenter, "<<", t_left_shift, 1);
47
- id_push = rb_intern("push");
48
45
  }
@@ -1,30 +1,31 @@
1
1
  #include "ruby.h"
2
- #include "noyes.h"
3
- #include "rnoyes.h"
4
-
5
- static int id_push;
2
+ #include "c_noyes.h"
3
+ #include "r_noyes.h"
6
4
 
7
5
  VALUE cSpeechTrimmer;
8
6
 
9
- static void speech_trimmer_free(void *p) {
10
- free_speech_trimmer(p);
7
+ static void _speech_trimmer_free(void *p) {
8
+ speech_trimmer_free(p);
11
9
  }
12
10
 
13
11
  static VALUE t_init(VALUE self, VALUE args) {
14
12
  int len = RARRAY_LEN(args);
15
13
  SpeechTrimmer *st;
16
- if (len == 1)
17
- st = new_speech_trimmer(NUM2INT(rb_ary_entry(args, 0)));
18
- else
19
- st = new_speech_trimmer(16000);
14
+ int frequency = 16000;
15
+ double threshold = 10;
16
+ if (len > 0)
17
+ frequency = NUM2INT(rb_ary_entry(args, 0));
18
+ if (len > 1)
19
+ frequency = rb_float_new(rb_ary_entry(args, 0));
20
20
 
21
- VALUE stv = Data_Wrap_Struct(cSpeechTrimmer, 0, speech_trimmer_free, st);
21
+ st = new_speech_trimmer(frequency, threshold);
22
+ VALUE stv = Data_Wrap_Struct(cSpeechTrimmer, 0, _speech_trimmer_free, st);
22
23
  rb_iv_set(self, "@speech_trimmer", stv);
23
24
  return self;
24
25
  }
25
26
 
26
27
  static VALUE t_enqueue(VALUE self, VALUE obj) {
27
- NMatrix1 *M = v_2_nmatrix1(obj);
28
+ Carr *M = r2carr(obj);
28
29
  SpeechTrimmer *st;
29
30
  Data_Get_Struct(rb_iv_get(self, "@speech_trimmer"), SpeechTrimmer, st);
30
31
  speech_trimmer_enqueue(st, M);
@@ -34,9 +35,9 @@ static VALUE t_enqueue(VALUE self, VALUE obj) {
34
35
  static VALUE t_dequeue(VALUE self) {
35
36
  SpeechTrimmer *st;
36
37
  Data_Get_Struct(rb_iv_get(self, "@speech_trimmer"), SpeechTrimmer, st);
37
- NMatrix1 *N =speech_trimmer_dequeue(st);
38
- VALUE result = nmatrix1_2_v(N);
39
- free_nmatrix1(N);
38
+ Carr *N =speech_trimmer_dequeue(st);
39
+ VALUE result = carr2r(N);
40
+ carr_free(N);
40
41
  return result;
41
42
  }
42
43
 
@@ -48,17 +49,17 @@ static VALUE t_eos(VALUE self) {
48
49
  }
49
50
 
50
51
  static VALUE t_left_shift(VALUE self, VALUE obj) {
51
- NMatrix1 *M = v_2_nmatrix1(obj);
52
+ Carr *M = r2carr(obj);
52
53
  SpeechTrimmer *st;
53
54
  Data_Get_Struct(rb_iv_get(self, "@speech_trimmer"), SpeechTrimmer, st);
54
- NMatrix *R = speech_trimmer_apply(st, M);
55
- if (!R) {
56
- free_nmatrix1(M);
55
+ Cmat *R = speech_trimmer_apply(st, M);
56
+ if (R == NULL) {
57
+ carr_free(M);
57
58
  return Qnil;
58
59
  }
59
- VALUE result = nmatrix_2_v(R);
60
- free_nmatrix1(M);
61
- free_nmatrix(R);
60
+ VALUE result = cmat2r(R);
61
+ carr_free(M);
62
+ cmat_free(R);
62
63
  return result;
63
64
  }
64
65
 
@@ -70,5 +71,4 @@ void Init_speech_trimmer() {
70
71
  rb_define_method(cSpeechTrimmer, "dequeue", t_dequeue, 0);
71
72
  rb_define_method(cSpeechTrimmer, "eos?", t_eos, 0);
72
73
  rb_define_method(cSpeechTrimmer, "<<", t_left_shift, 1);
73
- id_push = rb_intern("push");
74
74
  }
@@ -59,4 +59,7 @@ module Noyes
59
59
  class Segmenter
60
60
  include NoyesFilterDSL
61
61
  end
62
+ class Compression
63
+ include NoyesFilterDSL
64
+ end
62
65
  end
@@ -17,3 +17,12 @@ module CMath
17
17
  a < b ? a : b
18
18
  end
19
19
  end
20
+
21
+ # log2 apparently exists in ruby 1.9.x, but not ruby 1.8.x
22
+ if !Math.respond_to? :log2
23
+ module Math
24
+ def Math.log2 n
25
+ log(n)/log(2)
26
+ end
27
+ end
28
+ end
data/lib/noyes.rb CHANGED
@@ -10,5 +10,18 @@ require 'ruby_impl/discrete_fourier_transform'
10
10
  require 'ruby_impl/power_spec'
11
11
  require 'ruby_impl/preemphasis'
12
12
  require 'ruby_impl/segment'
13
+ require 'ruby_impl/compression'
13
14
  require 'ruby_impl/bent_cent_marker'
14
15
  require 'ruby_impl/speech_trimmer'
16
+
17
+ # The Noyes module encapsulates all pure Ruby implemenations of the Noyes
18
+ # library. At present there is also an equivalent NoyesC and NoyesJava modules
19
+ # that encapsulate C and Java implementations, respectively. This, it is
20
+ # possible to choose an implementation programmatically simply by choosing a
21
+ # module. It is even possible to mix and match components with different
22
+ # implementations. The only limitation on this is that Java implementations
23
+ # only work under JRuby and C implementation only work under everything else.
24
+ # So C and Java implementations cannot be used at the same time. That's a
25
+ # limitation of the current Ruby interpreters, not the Noyes library.
26
+ module Noyes
27
+ end
data/lib/noyes_c.rb CHANGED
@@ -1,2 +1,24 @@
1
1
  require "common"
2
- require "c_impl/noyes_c"
2
+ require "cext/noyes_c"
3
+
4
+ # The NoyesC module encapsulates the C implementation of the Noyes library.
5
+ # Functionally, it is identical to the Noyes and NoyesJava modules. The NoyesC
6
+ # implementation is composed of Ruby bindings, which are written in C and the
7
+ # core C routines. The core C routines are not dependent on the Ruby wrappers
8
+ # or any Ruby libraries. They can be compiled into pure C implementations
9
+ # without modification. The underlying pure C implementation files can be
10
+ # identified by the 'c_' prefix.
11
+ #
12
+ # The underlying C implementation closely parallels the Noyes API. For
13
+ # example, the following Ruby and C code are identical.
14
+ #
15
+ #
16
+ # pre = NoyesC::Preemphasizer.new 0.97
17
+ # preemphasized_data = pre << data
18
+ #
19
+ #
20
+ # Preemphasizer *pre = preemphasizer_new(0.97);
21
+ # Carr * preemphasized_data = preemphasizer_apply(data);
22
+ #
23
+ module Noyes
24
+ end
data/lib/noyes_java.rb CHANGED
@@ -14,3 +14,8 @@ require 'java_impl/segment'
14
14
  require 'java_impl/bent_cent_marker'
15
15
  require 'java_impl/speech_trimmer'
16
16
  require 'noyes.jar'
17
+
18
+ # The NoyesJava module encapsulates the Java implementation of the Noyes
19
+ # library. It is otherwise identical to the Noyes and NoyesC modules.
20
+ module NoyesJava
21
+ end