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.
- data/VERSION +1 -1
- data/bin/nrec +5 -0
- data/lib/{c_impl → cext}/array_list.c +25 -25
- data/lib/cext/bent_cent_marker.c +55 -0
- data/lib/{c_impl/n_array_list.c → cext/c_array_list.c} +12 -12
- data/lib/cext/c_array_list.h +18 -0
- data/lib/{c_impl/n_bent_cent_marker.c → cext/c_bent_cent_marker.c} +13 -11
- data/lib/{c_impl/n_dft.c → cext/c_dft.c} +3 -3
- data/lib/{c_impl/n_discrete_cosine_transform.c → cext/c_discrete_cosine_transform.c} +5 -5
- data/lib/{c_impl/n_hamming_window.c → cext/c_hamming_window.c} +5 -5
- data/lib/{c_impl/n_live_cmn.c → cext/c_live_cmn.c} +5 -5
- data/lib/{c_impl/n_log_compressor.c → cext/c_log_compressor.c} +5 -5
- data/lib/cext/c_matrix.c +90 -0
- data/lib/{c_impl/n_mel_filter.c → cext/c_mel_filter.c} +13 -11
- data/lib/cext/c_mfcc_16x8.c +57 -0
- data/lib/{c_impl/noyes.h → cext/c_noyes.h} +50 -47
- data/lib/{c_impl/n_power_spec.c → cext/c_power_spec.c} +6 -6
- data/lib/{c_impl/n_preemphasis.c → cext/c_preemphasis.c} +4 -4
- data/lib/{c_impl/n_segmenter.c → cext/c_segmenter.c} +17 -11
- data/lib/cext/c_speech_trimmer.c +126 -0
- data/lib/{c_impl → cext}/discrete_cosine_transform.c +18 -20
- data/lib/{c_impl → cext}/hamming_window.c +11 -13
- data/lib/{c_impl → cext}/live_cmn.c +11 -14
- data/lib/{c_impl → cext}/log_compressor.c +11 -14
- data/lib/{c_impl → cext}/mel_filter.c +13 -17
- data/lib/cext/mfcc_16x8.c +36 -0
- data/lib/{c_impl → cext}/power_spectrum.c +10 -12
- data/lib/{c_impl → cext}/preemphasis.c +10 -13
- data/lib/{c_impl/noyes_c.c → cext/r_noyes.c} +12 -12
- data/lib/{c_impl/rnoyes.h → cext/r_noyes.h} +6 -6
- data/lib/{c_impl → cext}/segmenter.c +10 -13
- data/lib/{c_impl → cext}/speech_trimmer.c +23 -23
- data/lib/common/noyes_dsl.rb +3 -0
- data/lib/common/ruby_ext.rb +9 -0
- data/lib/noyes.rb +13 -0
- data/lib/noyes_c.rb +23 -1
- data/lib/noyes_java.rb +5 -0
- data/lib/ruby_impl/compression.rb +214 -0
- data/lib/ruby_impl/dct.rb +2 -2
- data/lib/ruby_impl/live_cmn.rb +4 -4
- data/lib/ruby_impl/mel_filter.rb +9 -9
- data/lib/ruby_impl/segment.rb +13 -2
- data/lib/ruby_impl/speech_trimmer.rb +3 -1
- data/ship/noyes.jar +0 -0
- metadata +36 -34
- data/lib/c_impl/bent_cent_marker.c +0 -36
- data/lib/c_impl/fast_8k_mfcc.c +0 -39
- data/lib/c_impl/n_array_list.h +0 -18
- data/lib/c_impl/n_fast_8k_mfcc.c +0 -55
- data/lib/c_impl/n_matrix.c +0 -72
- data/lib/c_impl/n_speech_trimmer.c +0 -96
- /data/lib/{c_impl → cext}/extconf.rb +0 -0
@@ -11,27 +11,28 @@ typedef struct {
|
|
11
11
|
double **data;
|
12
12
|
int rows;
|
13
13
|
int cols;
|
14
|
-
}
|
14
|
+
} Cmat;
|
15
15
|
|
16
16
|
typedef struct {
|
17
17
|
double ***data;
|
18
18
|
int rows;
|
19
19
|
int cols;
|
20
20
|
int z;
|
21
|
-
}
|
21
|
+
} Cmat3;
|
22
22
|
|
23
23
|
typedef struct {
|
24
24
|
double *data;
|
25
25
|
int rows;
|
26
|
-
}
|
26
|
+
} Carr;
|
27
27
|
|
28
|
-
|
29
|
-
void
|
28
|
+
Cmat *cmat_new(int rows, int cols);
|
29
|
+
void cmat_free(Cmat *);
|
30
30
|
|
31
|
-
|
32
|
-
void
|
33
|
-
|
34
|
-
|
31
|
+
Carr *carr_new(int rows);
|
32
|
+
void carr_free(Carr *);
|
33
|
+
Carr ** mat2arrs(Cmat *M);
|
34
|
+
Cmat * arrs2mat(Carr **array, int size);
|
35
|
+
Carr *cmat_flatten(Cmat *M);
|
35
36
|
|
36
37
|
// Preemphasizer
|
37
38
|
typedef struct {
|
@@ -40,8 +41,8 @@ typedef struct {
|
|
40
41
|
} Preemphasizer;
|
41
42
|
|
42
43
|
Preemphasizer * new_preemphasizer(double factor);
|
43
|
-
void
|
44
|
-
|
44
|
+
void preemphasizer_free(Preemphasizer *self);
|
45
|
+
Carr *preemphasizer_apply(Preemphasizer *self, Carr *data);
|
45
46
|
|
46
47
|
// Segmenter
|
47
48
|
typedef struct {
|
@@ -52,8 +53,8 @@ typedef struct {
|
|
52
53
|
} Segmenter;
|
53
54
|
|
54
55
|
Segmenter * new_segmenter(int winsz, int winshift);
|
55
|
-
void
|
56
|
-
|
56
|
+
void segmenter_free(Segmenter *s);
|
57
|
+
Cmat * segmenter_apply(Segmenter* self, Carr *data);
|
57
58
|
|
58
59
|
// Hamming Window
|
59
60
|
typedef struct {
|
@@ -61,9 +62,9 @@ typedef struct {
|
|
61
62
|
size_t buflen;
|
62
63
|
} HammingWindow;
|
63
64
|
|
64
|
-
HammingWindow *
|
65
|
-
void
|
66
|
-
|
65
|
+
HammingWindow * hamming_window_new(int window_size);
|
66
|
+
void hamming_window_free(HammingWindow *s);
|
67
|
+
Cmat * hamming_window_apply(HammingWindow* self, Cmat *data);
|
67
68
|
|
68
69
|
// Power spectrum
|
69
70
|
typedef struct {
|
@@ -71,9 +72,9 @@ typedef struct {
|
|
71
72
|
} PowerSpectrum;
|
72
73
|
|
73
74
|
PowerSpectrum * new_power_spectrum(int nfft);
|
74
|
-
void
|
75
|
-
|
76
|
-
|
75
|
+
void power_spectrum_free(PowerSpectrum *);
|
76
|
+
Cmat *power_spectrum_apply(PowerSpectrum *self, Cmat *data);
|
77
|
+
Cmat * dft(double * data, int datalen, int size);
|
77
78
|
|
78
79
|
// Mel Filter
|
79
80
|
typedef struct {
|
@@ -85,11 +86,11 @@ typedef struct {
|
|
85
86
|
|
86
87
|
MelFilter * new_mel_filter(int srate, int nfft, int nfilt, int lowerf,
|
87
88
|
int upperf);
|
88
|
-
void
|
89
|
-
|
89
|
+
void mel_filter_free(MelFilter* mf);
|
90
|
+
Cmat *make_bank_parameters(double srate, int nfft, int nfilt,
|
90
91
|
double lowerf, double upperf);
|
91
|
-
|
92
|
-
|
92
|
+
Cmat * mel_filter_apply(MelFilter* self, Cmat * power_spectrum);
|
93
|
+
Carr * make_filter(double left, double center, double right,
|
93
94
|
double initFreq, double delta);
|
94
95
|
double melinv(double m);
|
95
96
|
double mel(double m);
|
@@ -99,9 +100,9 @@ typedef struct {
|
|
99
100
|
double log_zero;
|
100
101
|
} LogCompressor;
|
101
102
|
|
102
|
-
LogCompressor *
|
103
|
-
void
|
104
|
-
|
103
|
+
LogCompressor * log_compressor_new(double log_zero);
|
104
|
+
void log_compressor_free(LogCompressor *lc);
|
105
|
+
Cmat * log_compressor_apply(LogCompressor *self, Cmat *data);
|
105
106
|
|
106
107
|
// Discrete Cosine Transform
|
107
108
|
typedef struct {
|
@@ -110,9 +111,9 @@ typedef struct {
|
|
110
111
|
double **melcos;
|
111
112
|
} DiscreteCosineTransform;
|
112
113
|
|
113
|
-
DiscreteCosineTransform *
|
114
|
-
void
|
115
|
-
|
114
|
+
DiscreteCosineTransform * dct_new(int order, int ncol);
|
115
|
+
void dct_free(DiscreteCosineTransform *dct);
|
116
|
+
Cmat * dct_apply(DiscreteCosineTransform *self, Cmat *data);
|
116
117
|
|
117
118
|
typedef struct {
|
118
119
|
double * sums;
|
@@ -124,9 +125,9 @@ typedef struct {
|
|
124
125
|
int shift;
|
125
126
|
} LiveCMN;
|
126
127
|
|
127
|
-
LiveCMN *
|
128
|
-
void
|
129
|
-
|
128
|
+
LiveCMN * live_cmn_new(int dimensions, double init_mean, int window_size, int shift);
|
129
|
+
void live_cmn_free(LiveCMN *lcmn);
|
130
|
+
Cmat *live_cmn_apply(LiveCMN *self, Cmat *data);
|
130
131
|
|
131
132
|
// Silence removal with BentCentMarker and SpeechTrimmer
|
132
133
|
typedef struct {
|
@@ -138,12 +139,14 @@ typedef struct {
|
|
138
139
|
double threshold;
|
139
140
|
} BentCentMarker;
|
140
141
|
|
141
|
-
BentCentMarker *
|
142
|
-
|
143
|
-
double
|
144
|
-
|
142
|
+
BentCentMarker * bent_cent_marker_new(double threshold, double adjustment,
|
143
|
+
double average_number, double background,
|
144
|
+
double level, double min_signal);
|
145
|
+
void bent_cent_marker_free(BentCentMarker *self);
|
146
|
+
double bent_cent_marker_log_rms(BentCentMarker *self, Carr *data);
|
147
|
+
int bent_cent_marker_apply(BentCentMarker *self, Carr *data);
|
145
148
|
|
146
|
-
#include "
|
149
|
+
#include "c_array_list.h"
|
147
150
|
|
148
151
|
typedef struct {
|
149
152
|
int leader;
|
@@ -155,16 +158,16 @@ typedef struct {
|
|
155
158
|
int ecs;
|
156
159
|
BentCentMarker *bcm;
|
157
160
|
Segmenter *seg;
|
158
|
-
|
161
|
+
Clist *queue;
|
159
162
|
int eos_reached;
|
160
163
|
} SpeechTrimmer;
|
161
164
|
|
162
|
-
SpeechTrimmer * new_speech_trimmer();
|
163
|
-
void
|
164
|
-
void speech_trimmer_enqueue(SpeechTrimmer *self,
|
165
|
-
|
165
|
+
SpeechTrimmer * new_speech_trimmer(int frequency, double threshold);
|
166
|
+
void speech_trimmer_free(SpeechTrimmer *self);
|
167
|
+
void speech_trimmer_enqueue(SpeechTrimmer *self, Carr* pcm);
|
168
|
+
Carr * speech_trimmer_dequeue(SpeechTrimmer *self);
|
166
169
|
int speech_trimmer_eos(SpeechTrimmer *self);
|
167
|
-
|
170
|
+
Cmat * speech_trimmer_apply(SpeechTrimmer *self, Carr* pcm);
|
168
171
|
|
169
172
|
// Fast 8k mfcc
|
170
173
|
// This strings together all the algorithms necessary to make mfcc's from an 8k
|
@@ -178,11 +181,11 @@ typedef struct {
|
|
178
181
|
LogCompressor *log;
|
179
182
|
DiscreteCosineTransform *dct;
|
180
183
|
LiveCMN *cmn;
|
181
|
-
}
|
184
|
+
} Mfcc16x8;
|
182
185
|
|
183
|
-
|
184
|
-
void
|
185
|
-
|
186
|
+
Mfcc16x8* mfcc_16x8_new();
|
187
|
+
void mfcc_16x8_free(Mfcc16x8 *self);
|
188
|
+
Cmat *mfcc_16x8_apply(Mfcc16x8 *self, Carr *data);
|
186
189
|
|
187
190
|
#ifdef __cplusplus
|
188
191
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "c_noyes.h"
|
2
2
|
#include "stdlib.h"
|
3
3
|
#include "math.h"
|
4
4
|
|
@@ -9,19 +9,19 @@ PowerSpectrum * new_power_spectrum(int nfft) {
|
|
9
9
|
return ps;
|
10
10
|
}
|
11
11
|
|
12
|
-
void
|
12
|
+
void power_spectrum_free(PowerSpectrum * self) {
|
13
13
|
free(self);
|
14
14
|
}
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
Cmat *power_spectrum_apply(PowerSpectrum *self, Cmat *data) {
|
17
|
+
Cmat *ps = cmat_new(data->rows, self->n_uniq_fft_points);
|
18
18
|
int i,j;
|
19
19
|
for (i=0;i<data->rows;++i) {
|
20
|
-
|
20
|
+
Cmat * ffts = dft(data->data[i], data->cols, self->nfft);
|
21
21
|
for (j=0;j<self->n_uniq_fft_points;++j) {
|
22
22
|
ps->data[i][j] = pow(ffts->data[0][j],2) + pow(ffts->data[1][j],2);
|
23
23
|
}
|
24
|
-
|
24
|
+
cmat_free(ffts);
|
25
25
|
}
|
26
26
|
return ps;
|
27
27
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "c_noyes.h"
|
2
2
|
|
3
3
|
Preemphasizer * new_preemphasizer(double factor) {
|
4
4
|
Preemphasizer *self = malloc(sizeof(Preemphasizer));
|
@@ -7,12 +7,12 @@ Preemphasizer * new_preemphasizer(double factor) {
|
|
7
7
|
return self;
|
8
8
|
}
|
9
9
|
|
10
|
-
void
|
10
|
+
void preemphasizer_free(Preemphasizer *self) {
|
11
11
|
free(self);
|
12
12
|
}
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
Carr *preemphasizer_apply(Preemphasizer *self, Carr *data) {
|
15
|
+
Carr *res = carr_new(data->rows);
|
16
16
|
double current_prior = self->prior;
|
17
17
|
self->prior = data->data[data->rows-1];
|
18
18
|
int i;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "c_noyes.h"
|
2
2
|
#include "memory.h"
|
3
3
|
|
4
4
|
Segmenter * new_segmenter(int winsz, int winshift) {
|
@@ -10,7 +10,7 @@ Segmenter * new_segmenter(int winsz, int winshift) {
|
|
10
10
|
return s;
|
11
11
|
};
|
12
12
|
|
13
|
-
void
|
13
|
+
void segmenter_free(Segmenter *s) {
|
14
14
|
if (s->buf) {
|
15
15
|
free(s->buf);
|
16
16
|
}
|
@@ -18,7 +18,9 @@ void free_segmenter(Segmenter *s) {
|
|
18
18
|
free(s);
|
19
19
|
}
|
20
20
|
|
21
|
-
|
21
|
+
#define MIN_SEGMENTS 3
|
22
|
+
|
23
|
+
Cmat * segmenter_apply(Segmenter* self, Carr *data) {
|
22
24
|
double * combo;
|
23
25
|
int combolen = 0;
|
24
26
|
if (self->buf != NULL) {
|
@@ -31,23 +33,27 @@ NMatrix * segmenter_apply(Segmenter* self, NMatrix1 *data) {
|
|
31
33
|
combolen = data->rows;
|
32
34
|
memcpy(combo, data->data, combolen * sizeof(double));
|
33
35
|
}
|
34
|
-
if (combolen < self->winsz + self->winshift *
|
36
|
+
if (combolen < self->winsz + self->winshift * MIN_SEGMENTS ) {
|
35
37
|
self->buf = realloc(self->buf, combolen * sizeof(double));
|
36
38
|
memcpy(self->buf, combo, combolen*sizeof(double));
|
37
39
|
self->buflen = combolen;
|
38
40
|
return NULL;
|
39
41
|
} else {
|
40
|
-
self->buf
|
42
|
+
if (self->buf != NULL) {
|
43
|
+
free(self->buf);
|
44
|
+
self->buf = NULL;
|
45
|
+
}
|
41
46
|
}
|
42
|
-
|
47
|
+
|
48
|
+
int nseg = 1 + (combolen - self->winsz - (combolen - self->winsz)
|
49
|
+
% self->winshift) / self->winshift;
|
50
|
+
Cmat *M = cmat_new(nseg, self->winsz);
|
43
51
|
int i = 0;
|
44
|
-
|
45
|
-
|
46
|
-
memcpy(M->data[j++], combo + i, self->winsz * sizeof(double));
|
47
|
-
i+=self->winshift;
|
52
|
+
for (i=0;i<M->rows;++i) {
|
53
|
+
memcpy(M->data[i], combo + i*self->winshift, self->winsz * sizeof(double));
|
48
54
|
}
|
49
55
|
|
50
|
-
int bufsize = combolen-
|
56
|
+
int bufsize = combolen - M->rows * self->winshift;
|
51
57
|
if (bufsize > 0) {
|
52
58
|
// Copy the tail end of combo into buf.
|
53
59
|
self->buf = realloc(self->buf, bufsize * sizeof(double));
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#include "c_noyes.h"
|
2
|
+
#undef TRUE
|
3
|
+
#define TRUE 1
|
4
|
+
#undef FALSE
|
5
|
+
#define FALSE 0
|
6
|
+
|
7
|
+
SpeechTrimmer * new_speech_trimmer(int frequency, double threshold) {
|
8
|
+
SpeechTrimmer *self = malloc(sizeof(SpeechTrimmer));
|
9
|
+
self->leader = 5;
|
10
|
+
self->trailer = 5;
|
11
|
+
self->speech_started = FALSE;
|
12
|
+
self->bcm = bent_cent_marker_new(threshold, 0.003, 1.0, 100.0, 0.0, 0.0);
|
13
|
+
self->false_count = 0;
|
14
|
+
self->true_count = 0;
|
15
|
+
self->queue = clist_new();
|
16
|
+
self->eos_reached = FALSE;
|
17
|
+
self->scs = 20;
|
18
|
+
self->ecs = 50;
|
19
|
+
self->seg = new_segmenter(frequency/100, frequency/100);
|
20
|
+
return self;
|
21
|
+
}
|
22
|
+
|
23
|
+
void speech_trimmer_free(SpeechTrimmer *self) {
|
24
|
+
bent_cent_marker_free(self->bcm);
|
25
|
+
segmenter_free(self->seg);
|
26
|
+
|
27
|
+
int i;
|
28
|
+
for (i=0; i<clist_size(self->queue); ++i)
|
29
|
+
carr_free(clist_get(self->queue, i));
|
30
|
+
clist_free(self->queue);
|
31
|
+
|
32
|
+
free(self);
|
33
|
+
}
|
34
|
+
|
35
|
+
Cmat * speech_trimmer_apply(SpeechTrimmer *self, Carr* pcm) {
|
36
|
+
if (self->eos_reached)
|
37
|
+
return NULL;
|
38
|
+
|
39
|
+
Cmat *segment_matrix = segmenter_apply(self->seg, pcm);
|
40
|
+
if (segment_matrix == NULL)
|
41
|
+
return NULL;
|
42
|
+
|
43
|
+
Clist *speech_segments = clist_new();
|
44
|
+
int centisecond_count = segment_matrix->rows;
|
45
|
+
Carr **segments = mat2arrs(segment_matrix);
|
46
|
+
int speech_count = 0, i;
|
47
|
+
for (i=0; i<centisecond_count ;++i) {
|
48
|
+
speech_trimmer_enqueue(self, segments[i]);
|
49
|
+
Carr *centispeech = speech_trimmer_dequeue(self);
|
50
|
+
while (centispeech != NULL) {
|
51
|
+
clist_add(speech_segments, centispeech);
|
52
|
+
speech_count++;
|
53
|
+
centispeech = speech_trimmer_dequeue(self);
|
54
|
+
}
|
55
|
+
if (speech_trimmer_eos(self)) {
|
56
|
+
for (i+=1;i<centisecond_count; ++i)
|
57
|
+
carr_free(segments[i]);
|
58
|
+
break;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
free(segments);
|
62
|
+
|
63
|
+
if (speech_trimmer_eos(self) && speech_count == 0) {
|
64
|
+
for (i=0; i<clist_size(speech_segments); ++i)
|
65
|
+
carr_free(clist_get(speech_segments, i));
|
66
|
+
|
67
|
+
clist_free(speech_segments);
|
68
|
+
return NULL;
|
69
|
+
}
|
70
|
+
|
71
|
+
Cmat *result = arrs2mat((Carr**)speech_segments->data, speech_count);
|
72
|
+
free(speech_segments);
|
73
|
+
return result;
|
74
|
+
}
|
75
|
+
|
76
|
+
void speech_trimmer_enqueue(SpeechTrimmer *self, Carr* pcm) {
|
77
|
+
if (self->eos_reached) {
|
78
|
+
carr_free(pcm);
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
clist_add(self->queue, pcm);
|
82
|
+
if (bent_cent_marker_apply(self->bcm, pcm)) {
|
83
|
+
self->false_count = 0;
|
84
|
+
self->true_count += 1;
|
85
|
+
} else {
|
86
|
+
self->false_count += 1;
|
87
|
+
self->true_count = 0;
|
88
|
+
}
|
89
|
+
if (self->speech_started) {
|
90
|
+
if (self->false_count == self->ecs) {
|
91
|
+
self->eos_reached = TRUE;
|
92
|
+
int new_size = clist_size(self->queue) - self->ecs + self->trailer;
|
93
|
+
int i;
|
94
|
+
for (i=new_size; i<clist_size(self->queue); ++i)
|
95
|
+
carr_free(clist_get(self->queue, i));
|
96
|
+
|
97
|
+
clist_remove(self->queue, new_size, clist_size(self->queue));
|
98
|
+
}
|
99
|
+
} else if (self->true_count > self->scs) {
|
100
|
+
if (self->leader + self->scs < clist_size(self->queue)) {
|
101
|
+
int start = clist_size(self->queue) - self->leader - self->scs - 1;
|
102
|
+
int i;
|
103
|
+
for (i=0; i<start; ++i)
|
104
|
+
carr_free(clist_get(self->queue, i));
|
105
|
+
|
106
|
+
clist_remove(self->queue, 0, start);
|
107
|
+
}
|
108
|
+
self->speech_started = TRUE;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
Carr * speech_trimmer_dequeue(SpeechTrimmer *self) {
|
113
|
+
if (clist_size(self->queue) == 0)
|
114
|
+
return NULL;
|
115
|
+
if (self->eos_reached || (self->speech_started &&
|
116
|
+
clist_size(self->queue) > self->ecs)) {
|
117
|
+
Carr * N = clist_get(self->queue, 0);
|
118
|
+
clist_remove(self->queue, 0, 1);
|
119
|
+
return N;
|
120
|
+
}
|
121
|
+
return NULL;
|
122
|
+
}
|
123
|
+
|
124
|
+
int speech_trimmer_eos(SpeechTrimmer *self) {
|
125
|
+
return self->eos_reached;
|
126
|
+
}
|
@@ -1,13 +1,11 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
#include "
|
3
|
-
#include "
|
4
|
-
|
5
|
-
static int id_push;
|
2
|
+
#include "c_noyes.h"
|
3
|
+
#include "r_noyes.h"
|
6
4
|
|
7
5
|
VALUE cDiscreteCosineTransform;
|
8
6
|
|
9
|
-
static void
|
10
|
-
|
7
|
+
static void _dct_free(void *p) {
|
8
|
+
dct_free(p);
|
11
9
|
}
|
12
10
|
|
13
11
|
static VALUE t_init(VALUE self, VALUE args) {
|
@@ -18,20 +16,21 @@ static VALUE t_init(VALUE self, VALUE args) {
|
|
18
16
|
if (len > 1)
|
19
17
|
cols = NUM2INT(rb_ary_entry(args, 1));
|
20
18
|
|
21
|
-
DiscreteCosineTransform *dct =
|
22
|
-
VALUE dctv = Data_Wrap_Struct(cDiscreteCosineTransform, 0,
|
19
|
+
DiscreteCosineTransform *dct = dct_new(rows,cols);
|
20
|
+
VALUE dctv = Data_Wrap_Struct(cDiscreteCosineTransform, 0, _dct_free, dct);
|
23
21
|
rb_iv_set(self, "@dct", dctv);
|
24
22
|
return self;
|
25
23
|
}
|
26
24
|
|
27
25
|
static VALUE t_left_shift(VALUE self, VALUE obj) {
|
28
|
-
|
26
|
+
Cmat *M = r2cmat(obj);
|
29
27
|
DiscreteCosineTransform *dct;
|
30
28
|
VALUE dctv = rb_iv_get(self, "@dct");
|
31
29
|
Data_Get_Struct(dctv, DiscreteCosineTransform, dct);
|
32
|
-
|
33
|
-
VALUE result =
|
34
|
-
|
30
|
+
Cmat *N = dct_apply(dct, M);
|
31
|
+
VALUE result = cmat2r(N);
|
32
|
+
cmat_free(N);
|
33
|
+
cmat_free(M);
|
35
34
|
return result;
|
36
35
|
}
|
37
36
|
|
@@ -39,19 +38,19 @@ static VALUE t_melcos(VALUE self) {
|
|
39
38
|
DiscreteCosineTransform *dct;
|
40
39
|
VALUE dctv = rb_iv_get(self, "@dct");
|
41
40
|
Data_Get_Struct(dctv, DiscreteCosineTransform, dct);
|
42
|
-
|
41
|
+
Cmat *N = cmat_new(dct->rows, dct->cols);
|
43
42
|
int i;
|
44
43
|
for (i=0;i<dct->rows;++i) {
|
45
44
|
memcpy(N->data[i],dct->melcos[i], dct->cols * sizeof(double));
|
46
45
|
}
|
47
|
-
VALUE result =
|
48
|
-
|
46
|
+
VALUE result = cmat2r(N);
|
47
|
+
cmat_free(N);
|
49
48
|
return result;
|
50
49
|
}
|
51
50
|
|
52
51
|
static VALUE t_dft(VALUE classmod, VALUE data, VALUE size) {
|
53
|
-
|
54
|
-
|
52
|
+
Carr *M = r2carr(data);
|
53
|
+
Cmat *R = dft(M->data, M->rows, FIX2INT(size));
|
55
54
|
VALUE result = rb_ary_new2(R->cols);
|
56
55
|
int i;
|
57
56
|
for (i=0;i<R->cols;++i) {
|
@@ -59,8 +58,8 @@ static VALUE t_dft(VALUE classmod, VALUE data, VALUE size) {
|
|
59
58
|
VALUE imag = rb_float_new(R->data[1][i]);
|
60
59
|
rb_ary_store(result, i, rb_complex_new(real, imag));
|
61
60
|
}
|
62
|
-
|
63
|
-
|
61
|
+
carr_free(M);
|
62
|
+
cmat_free(R);
|
64
63
|
return result;
|
65
64
|
}
|
66
65
|
|
@@ -72,5 +71,4 @@ void Init_dct() {
|
|
72
71
|
rb_define_method(cDiscreteCosineTransform, "<<", t_left_shift, 1);
|
73
72
|
rb_define_method(cDiscreteCosineTransform, "melcos", t_melcos, 0);
|
74
73
|
rb_define_module_function(m_noyes_c, "dft", t_dft, 2);
|
75
|
-
id_push = rb_intern("push");
|
76
74
|
}
|
@@ -1,13 +1,11 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
#include "
|
3
|
-
#include "
|
4
|
-
|
5
|
-
static int id_push;
|
2
|
+
#include "c_noyes.h"
|
3
|
+
#include "r_noyes.h"
|
6
4
|
|
7
5
|
VALUE cHammingWindow;
|
8
6
|
|
9
|
-
static void
|
10
|
-
|
7
|
+
static void _hamming_window_free(void *p) {
|
8
|
+
hamming_window_free(p);
|
11
9
|
}
|
12
10
|
static VALUE t_init(VALUE self, VALUE args) {
|
13
11
|
int len = RARRAY_LEN(args);
|
@@ -15,20 +13,21 @@ static VALUE t_init(VALUE self, VALUE args) {
|
|
15
13
|
if (len > 0) {
|
16
14
|
winsz = NUM2INT(rb_ary_entry(args, 0));
|
17
15
|
}
|
18
|
-
HammingWindow *hw =
|
19
|
-
VALUE hwv = Data_Wrap_Struct(cHammingWindow, 0,
|
16
|
+
HammingWindow *hw = hamming_window_new(winsz);
|
17
|
+
VALUE hwv = Data_Wrap_Struct(cHammingWindow, 0, _hamming_window_free, hw);
|
20
18
|
rb_iv_set(self, "@hw", hwv);
|
21
19
|
return self;
|
22
20
|
}
|
23
21
|
|
24
22
|
static VALUE t_left_shift(VALUE self, VALUE obj) {
|
25
|
-
|
23
|
+
Cmat *M = r2cmat(obj);
|
26
24
|
HammingWindow *hw;
|
27
25
|
VALUE hwv = rb_iv_get(self, "@hw");
|
28
26
|
Data_Get_Struct(hwv, HammingWindow, hw);
|
29
|
-
|
30
|
-
VALUE result =
|
31
|
-
|
27
|
+
Cmat *N = hamming_window_apply(hw, M);
|
28
|
+
VALUE result = cmat2r(N);
|
29
|
+
cmat_free(N);
|
30
|
+
cmat_free(M);
|
32
31
|
return result;
|
33
32
|
}
|
34
33
|
|
@@ -37,5 +36,4 @@ void Init_hamming_window() {
|
|
37
36
|
cHammingWindow = rb_define_class_under(m_noyes_c, "HammingWindow", rb_cObject);
|
38
37
|
rb_define_method(cHammingWindow, "initialize", t_init, -2);
|
39
38
|
rb_define_method(cHammingWindow, "<<", t_left_shift, 1);
|
40
|
-
id_push = rb_intern("push");
|
41
39
|
}
|
@@ -1,13 +1,11 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
#include "
|
3
|
-
#include "
|
4
|
-
|
5
|
-
static int id_push;
|
2
|
+
#include "c_noyes.h"
|
3
|
+
#include "r_noyes.h"
|
6
4
|
|
7
5
|
VALUE cLiveCMN;
|
8
6
|
|
9
|
-
static void
|
10
|
-
|
7
|
+
static void _live_cmn_free(void *p) {
|
8
|
+
live_cmn_free(p);
|
11
9
|
}
|
12
10
|
|
13
11
|
static VALUE t_init(VALUE self, VALUE args) {
|
@@ -22,20 +20,21 @@ static VALUE t_init(VALUE self, VALUE args) {
|
|
22
20
|
if (len > 3)
|
23
21
|
shift = NUM2INT(rb_ary_entry(args, 3));
|
24
22
|
|
25
|
-
LiveCMN *cmn =
|
26
|
-
VALUE cmnv = Data_Wrap_Struct(cLiveCMN, 0,
|
23
|
+
LiveCMN *cmn = live_cmn_new(dimensions, init_mean, window_size, shift);
|
24
|
+
VALUE cmnv = Data_Wrap_Struct(cLiveCMN, 0, _live_cmn_free, cmn);
|
27
25
|
rb_iv_set(self, "@cmn", cmnv);
|
28
26
|
return self;
|
29
27
|
}
|
30
28
|
|
31
29
|
static VALUE t_left_shift(VALUE self, VALUE obj) {
|
32
|
-
|
30
|
+
Cmat *M = r2cmat(obj);
|
33
31
|
LiveCMN *cmn;
|
34
32
|
VALUE cmnv = rb_iv_get(self, "@cmn");
|
35
33
|
Data_Get_Struct(cmnv, LiveCMN, cmn);
|
36
|
-
|
37
|
-
VALUE result =
|
38
|
-
|
34
|
+
Cmat *N = live_cmn_apply(cmn, M);
|
35
|
+
VALUE result = cmat2r(N);
|
36
|
+
cmat_free(N);
|
37
|
+
cmat_free(M);
|
39
38
|
return result;
|
40
39
|
}
|
41
40
|
|
@@ -44,6 +43,4 @@ void Init_live_cmn() {
|
|
44
43
|
cLiveCMN = rb_define_class_under(m_noyes_c, "LiveCMN", rb_cObject);
|
45
44
|
rb_define_method(cLiveCMN, "initialize", t_init, -2);
|
46
45
|
rb_define_method(cLiveCMN, "<<", t_left_shift, 1);
|
47
|
-
id_push = rb_intern("push");
|
48
46
|
}
|
49
|
-
|
@@ -1,13 +1,11 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
#include "
|
3
|
-
#include "
|
4
|
-
|
5
|
-
static int id_push;
|
2
|
+
#include "c_noyes.h"
|
3
|
+
#include "r_noyes.h"
|
6
4
|
|
7
5
|
VALUE cLogCompressor;
|
8
6
|
|
9
|
-
static void
|
10
|
-
|
7
|
+
static void _log_compressor_free(void *p) {
|
8
|
+
log_compressor_free(p);
|
11
9
|
}
|
12
10
|
|
13
11
|
static VALUE t_init(VALUE self, VALUE args) {
|
@@ -16,21 +14,21 @@ static VALUE t_init(VALUE self, VALUE args) {
|
|
16
14
|
if (len > 0) {
|
17
15
|
log_zero = NUM2DBL(rb_ary_entry(args, 0));
|
18
16
|
}
|
19
|
-
LogCompressor *lc =
|
20
|
-
VALUE lcv = Data_Wrap_Struct(cLogCompressor, 0,
|
17
|
+
LogCompressor *lc = log_compressor_new(log_zero);
|
18
|
+
VALUE lcv = Data_Wrap_Struct(cLogCompressor, 0, _log_compressor_free, lc);
|
21
19
|
rb_iv_set(self, "@log_compressor", lcv);
|
22
20
|
return self;
|
23
21
|
}
|
24
22
|
|
25
23
|
static VALUE t_left_shift(VALUE self, VALUE obj) {
|
26
|
-
|
24
|
+
Cmat *M = r2cmat(obj);
|
27
25
|
LogCompressor *lc;
|
28
26
|
VALUE lcv = rb_iv_get(self, "@log_compressor");
|
29
27
|
Data_Get_Struct(lcv, LogCompressor, lc);
|
30
|
-
|
31
|
-
VALUE result =
|
32
|
-
|
33
|
-
|
28
|
+
Cmat *N = log_compressor_apply(lc, M);
|
29
|
+
VALUE result = cmat2r(N);
|
30
|
+
cmat_free(N);
|
31
|
+
cmat_free(M);
|
34
32
|
return result;
|
35
33
|
}
|
36
34
|
|
@@ -39,5 +37,4 @@ void Init_log_compressor() {
|
|
39
37
|
cLogCompressor = rb_define_class_under(m_noyes_c, "LogCompressor", rb_cObject);
|
40
38
|
rb_define_method(cLogCompressor, "initialize", t_init, -2);
|
41
39
|
rb_define_method(cLogCompressor, "<<", t_left_shift, 1);
|
42
|
-
id_push = rb_intern("push");
|
43
40
|
}
|