| 1 |
/*************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* Language Technologies Institute */ |
| 4 |
/* Carnegie Mellon University */ |
| 5 |
/* Copyright (c) 1999 */ |
| 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 |
/* Tracks (cepstrum, ffts, F0 etc) */ |
| 38 |
/* */ |
| 39 |
/*************************************************************************/ |
| 40 |
#include "cst_string.h" |
| 41 |
#include "cst_val.h" |
| 42 |
#include "cst_track.h" |
| 43 |
|
| 44 |
CST_VAL_REGISTER_TYPE(track,cst_track) |
| 45 |
|
| 46 |
cst_track *new_track() |
| 47 |
{ |
| 48 |
cst_track *w = cst_alloc(struct cst_track_struct,1); |
| 49 |
return w; |
| 50 |
} |
| 51 |
|
| 52 |
void delete_track(cst_track *w) |
| 53 |
{ |
| 54 |
int i; |
| 55 |
|
| 56 |
if (w) |
| 57 |
{ |
| 58 |
cst_free(w->times); |
| 59 |
for (i=0; i < w->num_frames; i++) |
| 60 |
cst_free(w->frames[i]); |
| 61 |
cst_free(w->frames); |
| 62 |
cst_free(w); |
| 63 |
} |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
float track_frame_shift(cst_track *t, int frame) |
| 68 |
{ |
| 69 |
if (frame == 0) |
| 70 |
return t->times[frame]; |
| 71 |
else |
| 72 |
return t->times[frame]-t->times[frame-1]; |
| 73 |
} |
| 74 |
|
| 75 |
void cst_track_resize(cst_track *t,int num_frames, int num_channels) |
| 76 |
{ |
| 77 |
float *n_times; |
| 78 |
float **n_frames; |
| 79 |
int i; |
| 80 |
|
| 81 |
n_times = cst_alloc(float,num_frames); |
| 82 |
memmove(n_times,t->times, |
| 83 |
(sizeof(float)*((num_frames < t->num_frames) ? |
| 84 |
num_frames : t->num_frames))); |
| 85 |
n_frames = cst_alloc(float*,num_frames); |
| 86 |
for (i=0; i<num_frames; i++) |
| 87 |
{ |
| 88 |
n_frames[i] = cst_alloc(float,num_channels); |
| 89 |
if (i<t->num_frames) |
| 90 |
{ |
| 91 |
memmove(n_frames[i], |
| 92 |
t->frames[i], |
| 93 |
sizeof(float)*((num_channels < t->num_channels) ? |
| 94 |
num_channels : t->num_channels)); |
| 95 |
cst_free(t->frames[i]); |
| 96 |
} |
| 97 |
} |
| 98 |
for ( ; i<t->num_frames; i++) |
| 99 |
cst_free(t->frames[i]); |
| 100 |
cst_free(t->frames); |
| 101 |
t->frames = n_frames; |
| 102 |
cst_free(t->times); |
| 103 |
t->times = n_times; |
| 104 |
t->num_frames = num_frames; |
| 105 |
t->num_channels = num_channels; |
| 106 |
} |
| 107 |
|
| 108 |
cst_track *cst_track_copy(const cst_track *t) |
| 109 |
{ |
| 110 |
cst_track *t2; |
| 111 |
int i; |
| 112 |
|
| 113 |
t2 = new_track(); |
| 114 |
t2->times = cst_alloc(float,t->num_frames); |
| 115 |
memmove(t2->times,t->times, (sizeof(float)*t->num_frames)); |
| 116 |
t2->num_frames = t->num_frames; |
| 117 |
t2->num_channels = t->num_channels; |
| 118 |
t2->frames = cst_alloc(float *,t->num_frames); |
| 119 |
for (i=0; i<t2->num_frames; i++) |
| 120 |
{ |
| 121 |
t2->frames[i] = cst_alloc(float,t2->num_channels); |
| 122 |
memmove(t2->frames[i],t->frames[i], sizeof(float)*t2->num_channels); |
| 123 |
} |
| 124 |
|
| 125 |
return t2; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|