char phaseexp_arg[MAX_STR];
char out_file[MAX_STR];
FILE *fout = NULL; /* output speech file */
+ int mel_resampling = 0;
+ int K = 20;
char* opt_string = "ho:";
struct option long_options[] = {
{ "Fs", required_argument, &set_fs, 1 },
+ { "mel", required_argument, &mel_resampling, 1 },
{ "lpc", required_argument, &lpc_model, 1 },
{ "lspjnd", no_argument, &lspjnd, 1 },
{ "lspmel", no_argument, &lspmel, 1 },
\*----------------------------------------------------------------*/
+ if (argc < 2) {
+ print_help(long_options, num_opts, argv);
+ }
+
while(1) {
int option_index = 0;
int opt = getopt_long(argc, argv, opt_string,
fprintf(stderr, "Error Fs must be 8000 or 16000\n");
exit(1);
}
+ } else if(strcmp(long_options[option_index].name, "mel") == 0) {
+ K = atoi(optarg);
} else if(strcmp(long_options[option_index].name, "lpc") == 0) {
orderi = atoi(optarg);
if((orderi < 4) || (orderi > order)) {
nlp_states = nlp_create(&c2const);
- if (argc < 2) {
- print_help(long_options, num_opts, argv);
- }
-
-
ex_phase[0] = 0;
Woe_[0] = Woe_[1] = 1.0;
prev_model_dec.L = PI/prev_model_dec.Wo;
prev_model_dec.voiced = 0;
+ /* mel resampling experiments */
+
+ float rate_K_sample_freqs_kHz[K];
+ if (mel_resampling) {
+ float mel_start = ftomel(100);
+ float mel_end = ftomel(0.95*Fs/2);
+ mel_sample_freqs_kHz(rate_K_sample_freqs_kHz, K, mel_start, mel_end);
+ //for(i=0; i<K; i++)
+ // fprintf(stderr, "%d %f\n", i, rate_K_sample_freqs_kHz[i]);
+ }
+
/*----------------------------------------------------------------* \
Main Loop
model.A[m] = 0.0;
}
+ /*------------------------------------------------------------*\
+
+ Mel scale resampling
+
+ \*------------------------------------------------------------*/
+
+ if (mel_resampling) {
+ float rate_K_vec[K];
+ resample_const_rate_f(&c2const, &model, rate_K_vec, rate_K_sample_freqs_kHz, K);
+ resample_rate_L(&c2const, &model, rate_K_vec, rate_K_sample_freqs_kHz, K);
+ }
+
/*------------------------------------------------------------*\
Zero-phase modelling
\*------------------------------------------------------------*/
if (phase0) {
- float Wn[m_pitch]; /* windowed speech samples */
- float Rk[order+1]; /* autocorrelation coeffs */
- COMP a[FFT_ENC];
-
#ifdef DUMP
dump_phase(&model.phi[0], model.L);
#endif
- /* find aks here, these are overwritten if LPC modelling is enabled */
-
- for(i=0; i<m_pitch; i++)
- Wn[i] = Sn[i]*w[i];
- autocorrelate(Wn,Rk,m_pitch,order);
- levinson_durbin(Rk,ak,order);
-
/* determine voicing */
#if 0
for(i=0; i<=MAX_AMP; i++)
model.phi[i] = 0;
- /* Determine DFT of A(exp(jw)), which is needed for phase0 model when
- LPC is not used, e.g. indecimate=1 (10ms) frames with no LPC */
-
- for(i=0; i<FFT_ENC; i++) {
- a[i].real = 0.0;
- a[i].imag = 0.0;
- }
-
- for(i=0; i<=order; i++)
- a[i].real = ak[i];
- codec2_fft(fft_fwd_cfg, a, Aw);
-
if (hand_voicing) {
int ret = fscanf(fvoicing,"%d\n",&model.voiced);
assert(ret == 1);
/* newamp1 initialisation */
if (c2->mode == CODEC2_MODE_700C) {
- mel_sample_freqs_kHz(c2->rate_K_sample_freqs_kHz, NEWAMP1_K);
+ mel_sample_freqs_kHz(c2->rate_K_sample_freqs_kHz, NEWAMP1_K, ftomel(200.0), ftomel(3700.0) );
int k;
for(k=0; k<NEWAMP1_K; k++) {
c2->prev_rate_K_vec_[k] = 0.0;
return mel;
}
-void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K)
+void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K, float mel_start, float mel_end)
{
- float mel_start = ftomel(200.0); float mel_end = ftomel(3700.0);
float step = (mel_end-mel_start)/(K-1);
float mel;
int k;
\*---------------------------------------------------------------------------*/
-void resample_const_rate_f(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K)
+void resample_const_rate_f(C2CONST *c2const, MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K)
{
int m;
float AmdB[MAX_AMP+1], rate_L_sample_freqs_kHz[MAX_AMP+1], AmdB_peak;
if (AmdB[m] > AmdB_peak) {
AmdB_peak = AmdB[m];
}
- rate_L_sample_freqs_kHz[m] = m*model->Wo*4.0/M_PI;
+ rate_L_sample_freqs_kHz[m] = m*model->Wo*(c2const->Fs/2000.0)/M_PI;
//printf("m: %d AmdB: %f AmdB_peak: %f sf: %f\n", m, AmdB[m], AmdB_peak, rate_L_sample_freqs_kHz[m]);
}
\*---------------------------------------------------------------------------*/
-void resample_rate_L(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K)
+void resample_rate_L(C2CONST *c2const, MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K)
{
float rate_K_vec_term[K+2], rate_K_sample_freqs_kHz_term[K+2];
float AmdB[MAX_AMP+1], rate_L_sample_freqs_kHz[MAX_AMP+1];
}
for(m=1; m<=model->L; m++) {
- rate_L_sample_freqs_kHz[m] = m*model->Wo*4.0/M_PI;
+ rate_L_sample_freqs_kHz[m] = m*model->Wo*(c2const->Fs/2000.0)/M_PI;
}
interp_para(&AmdB[1], rate_K_sample_freqs_kHz_term, rate_K_vec_term, K+2, &rate_L_sample_freqs_kHz[1], model->L);
/* convert variable rate L to fixed rate K */
- resample_const_rate_f(model, rate_K_vec, rate_K_sample_freqs_kHz, K);
+ resample_const_rate_f(c2const, model, rate_K_vec, rate_K_sample_freqs_kHz, K);
/* remove mean and two stage VQ */
model_[i].L = aL_[i];
model_[i].voiced = avoicing_[i];
- resample_rate_L(&model_[i], &interpolated_surface_[K*i], rate_K_sample_freqs_kHz, K);
+ resample_rate_L(c2const, &model_[i], &interpolated_surface_[K*i], rate_K_sample_freqs_kHz, K);
determine_phase(c2const, &H[(MAX_AMP+1)*i], &model_[i], NEWAMP1_PHASE_NFFT, fwd_cfg, inv_cfg);
}
void interp_para(float y[], float xp[], float yp[], int np, float x[], int n);
float ftomel(float fHz);
-void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K);
-void resample_const_rate_f(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K);
+void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K, float mel_start, float mel_end);
+void resample_const_rate_f(C2CONST *c2const, MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K);
float rate_K_mbest_encode(int *indexes, float *x, float *xq, int ndim, int mbest_entries);
void post_filter_newamp1(float vec[], float sample_freq_kHz[], int K, float pf_gain);
void interp_Wo_v(float Wo_[], int L_[], int voicing_[], float Wo1, float Wo2, int voicing1, int voicing2);
-void resample_rate_L(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K);
+void resample_rate_L(C2CONST *c2const, MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K);
void determine_phase(C2CONST *c2const, COMP H[], MODEL *model, int Nfft, codec2_fft_cfg fwd_cfg, codec2_fft_cfg inv_cfg);
void newamp1_model_to_indexes(C2CONST *c2const,
int indexes[],