56 int internalRate = 11025;
57 int decimationFactor =
samplerate / internalRate;
58 if (decimationFactor < 1) decimationFactor = 1;
61 while (decimationFactor & (decimationFactor - 1)) ++decimationFactor;
67 if (decimationFactor > 1) {
88 int internalRate = 22050;
89 int decimationFactor =
samplerate / internalRate;
90 if (decimationFactor < 1) decimationFactor = 1;
93 while (decimationFactor & (decimationFactor - 1)) ++decimationFactor;
99 if (decimationFactor > 1) {
146 std::cerr <<
"ERROR: ClusterMeltSegmenter::extractFeaturesConstQ: "
147 <<
"No const-q: initialise not called?"
153 std::cerr <<
"ERROR: ClusterMeltSegmenter::extractFeatures: nsamples < windowsize (" << nsamples <<
" < " <<
getWindowsize() <<
")" << std::endl;
157 int fftsize =
constq->getfftlength();
164 vector<double> cq(
ncoeff);
166 for (
int i = 0; i <
ncoeff; ++i) cq[i] = 0.0;
168 const double *psource = samples;
169 int pcount = nsamples;
172 pcount = nsamples /
decimator->getFactor();
173 double *decout =
new double[pcount];
184 double *frame =
new double[fftsize];
185 double *real =
new double[fftsize];
186 double *imag =
new double[fftsize];
187 double *cqre =
new double[
ncoeff];
188 double *cqim =
new double[
ncoeff];
190 while (origin <= pcount) {
194 if (origin > 0 && origin + fftsize >= pcount)
break;
196 for (
int i = 0; i < fftsize; ++i) {
197 if (origin + i < pcount) {
198 frame[i] = psource[origin + i];
204 for (
int i = 0; i < fftsize/2; ++i) {
205 double value = frame[i];
206 frame[i] = frame[i + fftsize/2];
207 frame[i + fftsize/2] = value;
212 fft->forward(frame, real, imag);
214 constq->process(real, imag, cqre, cqim);
216 for (
int i = 0; i <
ncoeff; ++i) {
217 cq[i] += sqrt(cqre[i] * cqre[i] + cqim[i] * cqim[i]);
230 for (
int i = 0; i <
ncoeff; ++i) {
242 std::cerr <<
"ERROR: ClusterMeltSegmenter::extractFeaturesMFCC: "
243 <<
"No mfcc: initialise not called?"
249 std::cerr <<
"ERROR: ClusterMeltSegmenter::extractFeatures: nsamples < windowsize (" << nsamples <<
" < " <<
getWindowsize() <<
")" << std::endl;
253 int fftsize =
mfcc->getfftlength();
255 vector<double> cc(
ncoeff);
257 for (
int i = 0; i <
ncoeff; ++i) cc[i] = 0.0;
259 const double *psource = samples;
260 int pcount = nsamples;
263 pcount = nsamples /
decimator->getFactor();
264 double *decout =
new double[pcount];
272 double *frame =
new double[fftsize];
273 double *ccout =
new double[
ncoeff];
275 while (origin <= pcount) {
279 if (origin > 0 && origin + fftsize >= pcount)
break;
281 for (
int i = 0; i < fftsize; ++i) {
282 if (origin + i < pcount) {
283 frame[i] = psource[origin + i];
289 mfcc->process(frame, ccout);
291 for (
int i = 0; i <
ncoeff; ++i) {
302 for (
int i = 0; i <
ncoeff; ++i) {
338 double** arrFeatures =
new double*[
features.size()];
339 for (
int i = 0; i <
features.size(); i++)
342 arrFeatures[i] =
new double[
features[0].size()];
343 for (
int j = 0; j <
features[0].size(); j++)
346 arrFeatures[i] =
new double[
ncoeff+1];
347 for (
int j = 0; j <
ncoeff; j++)
367 for (
int i = 0; i <
features.size(); i++)
368 delete [] arrFeatures[i];
369 delete [] arrFeatures;
385 for (
int i = 1; i < len; i++)
virtual int getWindowsize()
virtual void extractFeatures(const double *samples, int nsamples)
virtual void initialise(int samplerate)
void extractFeaturesMFCC(const double *, int)
ClusterMeltSegmenter(ClusterMeltSegmenterParams params)
virtual ~ClusterMeltSegmenter()
feature_types featureType
void setFeatures(const vector< vector< double > > &f)
void extractFeaturesConstQ(const double *, int)
void makeSegmentation(int *q, int len)
Window< double > * window
Decimator carries out a fast downsample by a power-of-two factor.
static int getHighestSupportedFactor()
Segmentation segmentation
vector< vector< double > > features
Various shaped windows for sample frame conditioning, including cosine windows (Hann etc) and triangu...
void constq_segment(int *q, double **features, int frames_read, int bins, int ncoeff, int feature_type, int nHMM_states, int histogram_length, int nclusters, int neighbour_limit)
void cluster_segment(int *q, double **features, int frames_read, int feature_length, int nHMM_states, int histogram_length, int nclusters, int neighbour_limit)