1/*---------------------------------------------------------------------------* 2 * chelfep.c * 3 * * 4 * Copyright 2007, 2008 Nuance Communciations, Inc. * 5 * * 6 * Licensed under the Apache License, Version 2.0 (the 'License'); * 7 * you may not use this file except in compliance with the License. * 8 * * 9 * You may obtain a copy of the License at * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, software * 13 * distributed under the License is distributed on an 'AS IS' BASIS, * 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 15 * See the License for the specific language governing permissions and * 16 * limitations under the License. * 17 * * 18 *---------------------------------------------------------------------------*/ 19 20 21#ifndef _RTT 22#include <stdio.h> 23#endif 24#include <stdlib.h> 25#include <string.h> 26 27 28#ifdef unix 29#include <unistd.h> 30#endif 31#include <assert.h> 32 33#ifndef _RTT 34#include "duk_io.h" 35#endif 36#include "voicing.h" 37#include "front.h" 38#include "portable.h" 39 40 41#include "../clib/memmove.h" 42#include "sh_down.h" 43 44#define SMOOTH_C0_FOR_VOICING 1 45 46#if SMOOTH_C0_FOR_VOICING 47static featdata smoothed_c0(front_cep *cepobj, front_channel *channel); 48#endif 49 50int make_frame(front_channel *channel, front_wave *waveobj, 51 front_freq *freqobj, front_cep *cepobj, 52 voicing_info *voice, 53 samdata *inFramesWorth, samdata *refFramesWorth, 54 int num_samples, 55 featdata *framdata, featdata *voicedata) 56{ 57#if SMOOTH_C0_FOR_VOICING 58 featdata smooth_c0; 59#endif 60 if (freqobj->do_filterbank_input) 61 /* This memmove is in filterbank_emulation */ 62 MEMMOVE(channel->cep + (channel->mel_dim + 1), channel->cep, 63 (Q2 - 1) *(channel->mel_dim + 1), sizeof(float)); 64 else 65 { 66 /* not fb input */ 67 68 /* JFR data processing is no longer supported. BP 21-Jul98. */ 69 70 /* 2. CEP data processing */ 71 filterbank_emulation(channel, waveobj, freqobj, cepobj, 72 inFramesWorth, refFramesWorth, num_samples); 73 /* if doing fb dump then skip frame making. A top level will 74 read channel->fbo and dump it. */ 75 if (freqobj->do_filterbank_dump) 76 return True; 77 } 78 cepstrum_params(channel, waveobj, freqobj, cepobj); 79 80 /* 4. Delta CEP data processing */ 81 (void) make_std_frame(channel, cepobj, framdata); 82 if (!channel->frame_valid) 83 return (channel->frame_valid); 84 85 86 /* 5. Voicing analysis */ 87 if (channel->frame_valid) 88 { 89 if (voice != NULL) 90 { 91#if SMOOTH_C0_FOR_VOICING 92 if (cepobj->do_smooth_c0) 93 { 94 smooth_c0 = smoothed_c0(cepobj, channel); 95 *voicedata = (featdata) voicing_analysis(voice, smooth_c0, NULL); 96 } 97 else 98 *voicedata = (featdata) voicing_analysis(voice, framdata[0], NULL); 99 100#else 101 *voicedata = (featdata) voicing_analysis(voice, framdata[0], NULL); 102#endif 103 } 104 if (cepobj->do_skip_even_frames) 105 channel->frame_valid = (channel->frame_count) % 2; 106 } 107 return (channel->frame_valid); 108} 109 110static featdata smoothed_c0(front_cep *cepobj, front_channel *channel) 111{ 112 cepdata val; 113 featdata fval; 114 bigdata scval; 115 116 if (channel->frame_count <= 1) 117 val = channel->cep[DELTA * (channel->mel_dim+1)]; 118 else 119 { 120 val = (channel->cep[(DELTA-1) * (channel->mel_dim+1)] >> 2) 121 + (channel->cep[DELTA * (channel->mel_dim+1)] >> 1) 122 + (channel->cep[(DELTA+1) * (channel->mel_dim+1)] >> 2); 123 } 124 125 /* Now scaling and byteranging 126 */ 127 /* Now take the costable scaling off the ceps. */ 128 ASSERT((cepobj->melA_scale[0] *(float)SHIFT_DOWN(val, COSINE_TABLE_SHIFT)) 129 < LONG_MAX); 130 ASSERT((cepobj->melA_scale[0] *(float)SHIFT_DOWN(val, COSINE_TABLE_SHIFT)) 131 > -LONG_MAX); 132 133 scval = (bigdata)(SHIFT_DOWN((bigdata)cepobj->melA_scale[0] 134 * (bigdata) SHIFT_DOWN(val, COSINE_TABLE_SHIFT) 135 + (bigdata)cepobj->melB_scale[0], BYTERANGE_SHIFT + LOG_SCALE_SHIFT)); 136 fval = (featdata) MAKEBYTE(scval); 137 return (fval); 138} 139 140