| 1 |
/*************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* Language Technologies Institute */ |
| 4 |
/* Carnegie Mellon University */ |
| 5 |
/* Copyright (c) 2001 */ |
| 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: August 2000 */ |
| 35 |
/*************************************************************************/ |
| 36 |
/* */ |
| 37 |
/* Resynthesize from lpc coefficients plus a residual */ |
| 38 |
/* */ |
| 39 |
/*************************************************************************/ |
| 40 |
#include <stdio.h> |
| 41 |
#include "cst_wave.h" |
| 42 |
#include "cst_track.h" |
| 43 |
#include "cst_sigpr.h" |
| 44 |
|
| 45 |
int main(int argc, char **argv) |
| 46 |
{ |
| 47 |
/* need that cool argument parser */ |
| 48 |
cst_wave *w,*res; |
| 49 |
cst_track *lpc; |
| 50 |
cst_lpcres *lpcres; |
| 51 |
int i,j; |
| 52 |
float lpcmin = -2.709040; |
| 53 |
float lpcrange = 2.328840+2.709040; |
| 54 |
unsigned short *bbb; |
| 55 |
|
| 56 |
if (argc != 4) |
| 57 |
{ |
| 58 |
fprintf(stderr,"usage: lpc_test LPC RESIDUAL WAVEFILE\n"); |
| 59 |
return 1; |
| 60 |
} |
| 61 |
|
| 62 |
lpc = new_track(); |
| 63 |
cst_track_load_est(lpc,argv[1]); |
| 64 |
res = new_wave(); |
| 65 |
cst_wave_load_riff(res,argv[2]); |
| 66 |
|
| 67 |
lpcres = new_lpcres(); |
| 68 |
lpcres_resize_frames(lpcres,lpc->num_frames); |
| 69 |
lpcres->num_channels = lpc->num_channels-1; |
| 70 |
for (i=0; i<lpc->num_frames; i++) |
| 71 |
{ |
| 72 |
bbb = cst_alloc(unsigned short,lpc->num_channels-1); |
| 73 |
for (j=1; j<lpc->num_channels; j++) |
| 74 |
bbb[j-1] = (unsigned short) |
| 75 |
(((lpc->frames[i][j]-lpcmin)/lpcrange)*65535); |
| 76 |
lpcres->frames[i] = bbb; |
| 77 |
lpcres->sizes[i] = track_frame_shift(lpc,i)*res->sample_rate; |
| 78 |
} |
| 79 |
lpcres_resize_samples(lpcres,res->num_samples); |
| 80 |
lpcres->lpc_min = lpcmin; |
| 81 |
lpcres->lpc_range = lpcrange; |
| 82 |
lpcres->sample_rate = res->sample_rate; |
| 83 |
for (i=0; i<res->num_samples; i++) |
| 84 |
lpcres->residual[i] = cst_short_to_ulaw(res->samples[i]); |
| 85 |
|
| 86 |
w = lpc_resynth(lpcres); |
| 87 |
|
| 88 |
cst_wave_save_riff(w,argv[3]); |
| 89 |
|
| 90 |
return 0; |
| 91 |
} |