| 1 |
/*************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* Language Technologies Institute */ |
| 4 |
/* Carnegie Mellon University */ |
| 5 |
/* Copyright (c) 2010 */ |
| 6 |
/* All Rights Reserved. */ |
| 7 |
/* */ |
| 8 |
/* Permission is hereby granted, free of charge, to use and distribute */ |
| 9 |
/* this software and its documentation without restriction, including */ |
| 10 |
/* without limitation the rights to use, copy, modify, merge, publish, */ |
| 11 |
/* distribute, sublicense, and/or sell copies of this work, and to */ |
| 12 |
/* permit persons to whom this work is furnished to do so, subject to */ |
| 13 |
/* the following conditions: */ |
| 14 |
/* 1. The code must retain the above copyright notice, this list of */ |
| 15 |
/* conditions and the following disclaimer. */ |
| 16 |
/* 2. Any modifications must be clearly marked as such. */ |
| 17 |
/* 3. Original authors' names are not deleted. */ |
| 18 |
/* 4. The authors' names are not used to endorse or promote products */ |
| 19 |
/* derived from this software without specific prior written */ |
| 20 |
/* permission. */ |
| 21 |
/* */ |
| 22 |
/* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */ |
| 23 |
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ |
| 24 |
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ |
| 25 |
/* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */ |
| 26 |
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ |
| 27 |
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ |
| 28 |
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ |
| 29 |
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ |
| 30 |
/* THIS SOFTWARE. */ |
| 31 |
/* */ |
| 32 |
/*************************************************************************/ |
| 33 |
/* Author: Alan W Black ([email protected]) */ |
| 34 |
/* Date: April 2010 */ |
| 35 |
/*************************************************************************/ |
| 36 |
/* */ |
| 37 |
/* Convert between lpc and rfc */ |
| 38 |
/*************************************************************************/ |
| 39 |
#include <stdio.h> |
| 40 |
#include "cst_track.h" |
| 41 |
#include "cst_tokenstream.h" |
| 42 |
#include "cst_args.h" |
| 43 |
#include "cst_math.h" |
| 44 |
|
| 45 |
void lpc2ref(const float *lpc, float *rfc, int order); |
| 46 |
void ref2lpc(const float *rfc, float *lpc, int order); |
| 47 |
|
| 48 |
int main(int argc, char **argv) |
| 49 |
{ |
| 50 |
cst_track *t1, *t2; |
| 51 |
cst_val *files; |
| 52 |
cst_features *args; |
| 53 |
int i; |
| 54 |
int tolpc = 0; |
| 55 |
const char *f1, *f2; |
| 56 |
|
| 57 |
args = new_features(); |
| 58 |
files = |
| 59 |
cst_args(argv,argc, |
| 60 |
"usage: rfc OPTIONS INTRACK1 OUTTRACK2\n" |
| 61 |
"Convert between LPC and RFC\n" |
| 62 |
"-tolpc from RFC to LPC\n" |
| 63 |
"-torfc from LPC to RFC\n", |
| 64 |
args); |
| 65 |
|
| 66 |
f1 = val_string(val_car(files)); |
| 67 |
f2 = val_string(val_car(val_cdr(files))); |
| 68 |
t1 = new_track(); |
| 69 |
|
| 70 |
if (cst_track_load_est(t1,f1) != CST_OK_FORMAT) |
| 71 |
{ |
| 72 |
fprintf(stderr, |
| 73 |
"rfc: can't read file or wrong format \"%s\"\n", |
| 74 |
f1); |
| 75 |
return -1; |
| 76 |
} |
| 77 |
if (feat_present(args,"-tolpc")) |
| 78 |
tolpc = 1; |
| 79 |
if (feat_present(args,"-torfc")) |
| 80 |
tolpc = 0; |
| 81 |
|
| 82 |
t2 = cst_track_copy(t1); |
| 83 |
|
| 84 |
for (i=0; i<t2->num_frames; i++) |
| 85 |
{ |
| 86 |
if (tolpc) |
| 87 |
ref2lpc(&(t1->frames[i][1]),&(t2->frames[i][1]),t2->num_channels-1); |
| 88 |
else |
| 89 |
lpc2ref(&(t1->frames[i][1]),&(t2->frames[i][1]),t2->num_channels-1); |
| 90 |
|
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
cst_track_save_est(t2,f2); |
| 95 |
|
| 96 |
return 0; |
| 97 |
} |