end
end
- printf(" Sdb..: ");
- for i=1:5
- printf("%5.2f ", real(Sdb(i)));
- end
- printf("\n ");
- for i=1:5
- printf("%5.2f ", imag(Sdb(i)));
- end
- printf("\n");
-
c = ifft(Sdb); % compute real cepstrum from log magnitude spectrum
- printf(" c....: ");
- for i=1:5
- printf("%5.2f ", real(c(i)));
- end
- printf("\n ");
- for i=1:5
- printf("%5.2f ", imag(c(i)));
- end
- printf("\n");
-
% Check aliasing of cepstrum (in theory there is always some):
caliaserr = 100*norm(c(round(Ns*0.9:Ns*1.1)))/norm(c);
rate_L_sample_freqs_kHz = (1:L)*Wo*4/pi;
Gdbfk = interp_para(rate_L_sample_freqs_kHz, AmdB, sample_freqs_kHz);
- printf(" AmdB.: ");
- for m=1:5
- printf("%5.2f ", AmdB(m));
- end
- printf("\n");
- printf(" Gdbfk: ");
- for m=1:5
- printf("%5.2f ", Gdbfk(m));
- end
- printf("\n");
-
% Gdbfk = resample_mask(model, f, mask_sample_freqs_kHz);
% optional input of aks for testing
for k=f-M:f-1
model_(k,:) = resample_rate_L(model_(k,:), interpolated_surface_(k,:), sample_freqs_kHz);
- printf("\n");
- printf("frame: %d Wo: %4.3f L: %d\n", k, model_(k,1), model_(k,2));
phase = determine_phase(model_, k, Nfft_phase);
- printf(" phase: ");
- for i=1:5
- printf("%5.2f ", phase(i));
- end
- printf("\n");
- printf(" b....: ");
for m=1:model_(k,2)
b = round(m*model_(k,1)*Nfft_phase/(2*pi)); % map harmonic centre to DFT bin
- if m <= 5
- printf("%5d ", b);
- end
phi(m) = phase(b+1);
Hm(k,m) = exp(-j*phi(m));
end
- printf("\n");
- printf(" phi..: ");
- for m=1:5
- printf("%5.2f ", phi(m));
- end
- printf("\n");
- %if k == 2
- % xx
- %end
-
+
end
end
end
%Hm(2,:) - Hm_c(2,:)
- for f=1:frames
- s = abs(sum(Hm(f,:) - Hm_c(f,:)));
- printf("f: %d s: %f \n", f, s);
- end
figure(1);
mesh(angle(Hm));
#include "newamp1.h"
#define NEWAMP1_VQ_MBEST_DEPTH 5 /* how many candidates we keep for each stage of mbest search */
-#define NEWAMP1_VQ_STAGES 2 /* hard coded two stage VQ */
/*---------------------------------------------------------------------------*\
float Gdbfk[Ns], sample_freqs_kHz[Ns], phase[Ns];
float AmdB[MAX_AMP+1], rate_L_sample_freqs_kHz[MAX_AMP+1];
- printf(" AmdB.: ");
for(m=1; m<=model->L; m++) {
AmdB[m] = 20.0*log10(model->A[m]);
rate_L_sample_freqs_kHz[m] = (float)m*model->Wo*4.0/M_PI;
- if (m <=5) {
- printf("%5.2f ", AmdB[m]);
- }
}
- printf("\n");
for(i=0; i<Ns; i++) {
sample_freqs_kHz[i] = (FS/1000.0)*(float)i/Nfft;
interp_para(Gdbfk, &rate_L_sample_freqs_kHz[1], &AmdB[1], model->L, sample_freqs_kHz, Ns);
- printf(" Gdbfk: ");
- for(i=0; i<5; i++) {
- printf("%5.2f ", Gdbfk[i]);
- }
- printf("\n");
-
mag_to_phase(phase, Gdbfk, Nfft, fwd_cfg, inv_cfg);
- printf(" b....: ");
for(m=1; m<=model->L; m++) {
b = floorf(0.5+m*model->Wo*Nfft/(2.0*M_PI));
model->phi[m] = phase[b];
- if (m <= 5) {
- printf("%5d ", b);
- }
- }
- printf("\n");
- printf(" phi..: ");
- for(m=1; m<=5; m++) {
- printf("% 5.2f ", model->phi[m]);
}
- printf("\n");
}
float w[1] = {1.0};
float se;
- indexes[NEWAMP1_VQ_STAGES] = quantise(newamp1_energy_cb[0].cb,
- mean,
- w,
- newamp1_energy_cb[0].k,
- newamp1_energy_cb[0].m,
- &se);
+ indexes[2] = quantise(newamp1_energy_cb[0].cb,
+ mean,
+ w,
+ newamp1_energy_cb[0].k,
+ newamp1_energy_cb[0].m,
+ &se);
+
+ /* scalar quantise Wo. We steal the smallest Wo index to signal
+ an unvoiced frame */
+
+ if (model->voiced) {
+ int index = encode_log_Wo(model->Wo, 6);
+ if (index == 0) {
+ index = 1;
+ }
+ indexes[3] = index;
+ }
+ else {
+ indexes[3] = 0;
+ }
+
}
post_filter_newamp1(rate_K_vec_no_mean_, rate_K_sample_freqs_kHz, K, 1.5);
- *mean_ = newamp1_energy_cb[0].cb[indexes[NEWAMP1_VQ_STAGES]];
+ *mean_ = newamp1_energy_cb[0].cb[indexes[2]];
for(k=0; k<K; k++) {
rate_K_vec_[k] = rate_K_vec_no_mean_[k] + *mean_;
#ifndef __NEWAMP1__
#define __NEWAMP1__
+#define NEWAMP1_N_INDEXES 4 /* Number of indexes to pack: vq1, vq2, energy, Wo */
+
#include "codec2_fft.h"
#include "comp.h"
Sdb[i].imag = Sdb[Nfft-i].imag = 0.0;
}
- printf(" Sdb..: ");
- for(i=0; i<5; i++) {
- printf("%5.2f ", Sdb[i].real);
- }
- printf("\n ");
- for(i=0; i<5; i++) {
- printf("%5.2f ", Sdb[i].imag);
- }
- printf("\n");
-
/* compute real cepstrum from log magnitude spectrum */
codec2_fft(fft_inv_cfg, Sdb, c);
c[i].imag /= (float)Nfft;
}
- printf(" c....: ");
- for(i=0; i<5; i++) {
- printf("%5.2f ", c[i].real);
- }
- printf("\n ");
- for(i=0; i<5; i++) {
- printf("%5.2f ", c[i].imag);
- }
- printf("\n");
- /*
- for(i=0; i<Nfft; i++) {
- printf("i: %d c: %f %f\n", i, c[i].real, c[i].imag);
- }
- */
-
/* Fold cepstrum to reflect non-min-phase zeros inside unit circle */
cf[0] = c[0];
phase[i] = Cf[i].imag/scale;
}
- printf(" phase: ");
- for(i=0; i<5; i++) {
- printf("%5.2f ", phase[i]);
- }
- printf("\n");
}
int voicing_[FRAMES];
float model_octave_[FRAMES][MAX_AMP+2];
COMP Hm[FRAMES][MAX_AMP];
+ int indexes[FRAMES][NEWAMP1_N_INDEXES];
for(f=0; f<FRAMES; f++) {
for(m=0; m<MAX_AMP+2; m++) {
/* newamp1 processing ----------------------------------------*/
- int indexes[3];
- newamp1_model_to_indexes(indexes,
+ newamp1_model_to_indexes(&indexes[f][0],
&model,
&rate_K_surface[f][0],
rate_K_sample_freqs_kHz,
rate_K_sample_freqs_kHz,
K,
&mean_[f],
- indexes);
+ &indexes[f][0]);
/* log vectors */
for(f=0; f<FRAMES; f+=M) {
+#ifdef TMP1
/* Quantise Wo. V/UV flag is coded using a zero index for Wo,
this means we need to adjust Wo index slightly for the
lowest Wo V frames */
else {
model_octave_[f][0] = 2.0*M_PI/100.0;
}
+#endif
+ if (indexes[f][3]) {
+ model_octave_[f][0] = decode_log_Wo(indexes[f][3], 6);
+ }
+ else {
+ model_octave_[f][0] = 2.0*M_PI/100.0;
+ }
+
+ /*
+ pass in left and right rate K vectors, Wo, v
+ interpolate at rate K
+ convert to rate L
+ output 4 model parameters
+ ref indexes to 0...3
+ slowly change
+ */
float c;
if (f >= M) {
model_.Wo = model_octave_[i][0];
model_.L = model_octave_[i][1];
resample_rate_L(&model_, &interpolated_surface_[i][0], rate_K_sample_freqs_kHz, K);
- printf("\n");
- printf("frame: %d Wo: %4.3f L: %d\n", i+1, model_.Wo, model_.L);
+ //printf("\n");
+ //printf("frame: %d Wo: %4.3f L: %d\n", i+1, model_.Wo, model_.L);
determine_phase(&model_, PHASE_NFFT, phase_fft_fwd_cfg, phase_fft_inv_cfg);
//if (i == 1) {
// exit(0);