Edinburgh Speech Tools  2.1-release
misc.cc
Go to the documentation of this file.
1  /************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1996,1997 */
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  /* THE UNIVERSITY OF EDINBURGH 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 THE UNIVERSITY OF EDINBURGH 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  /* */
34  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
35  /* -------------------------------------------------------------------- */
36  /* Some generally useful signal processing things. */
37  /* */
38  /*************************************************************************/
39 
40 #include "EST_Wave.h"
41 #include "EST_TBuffer.h"
42 #include "sigpr/EST_misc_sigpr.h"
43 
44 #include "EST_inline_utils.h"
45 
46 static void short_set(EST_Wave &to, int ch,
47  const EST_TBuffer<double> &from,
48  double maxval)
49 {
50  for(int i=0; i<to.num_samples(); i++)
51  to.a_no_check(i,ch) = irint(from(i)/maxval*10000);
52 }
53 
54 /* redundant - see new version in filter */
55 void EST_pre_emphasis(EST_Wave &signal, EST_Wave &psignal, float a)
56 {
57  int num_samples = signal.num_samples();
58  short last=0;
59  double maxval=0;
60  EST_TBuffer<double> fpdata(num_samples);
61 
62  for(int i=0; i<num_samples; i++)
63  {
64  fpdata[i] = signal.a(i) - a*last;
65  last = signal.a(i);
66  if (absval(fpdata[i]) > maxval)
67  maxval = absval(fpdata[i]);
68  }
69 
70  psignal.resize(num_samples,1,FALSE);
71  psignal.set_sample_rate(signal.sample_rate());
72  short_set(psignal, 0, fpdata, maxval);
73 }
74 
75 /* redundant - see new version in filter */
76 void EST_post_deemphasis(EST_Wave &signal, EST_Wave &dsignal, float a)
77 {
78  int num_samples = signal.num_samples();
79  double last=0;
80  double maxval=0;
81  EST_TBuffer<double> fddata(num_samples);
82 
83  for(int i=0; i<num_samples; i++)
84  {
85  fddata[i] = signal.a(i) + a*last;
86  last = fddata[i];
87  if (absval(fddata[i]) > maxval)
88  maxval = absval(fddata[i]);
89  }
90 
91  dsignal.resize(num_samples,1,FALSE);
92  dsignal.set_sample_rate(signal.sample_rate());
93  short_set(dsignal, 0, fddata, maxval);
94 }
95 
96 
97 
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
Definition: EST_Wave.h:64
void set_sample_rate(const int n)
Set sampling rate to n
Definition: EST_Wave.h:149
void EST_pre_emphasis(EST_Wave &signal, EST_Wave &psignal, float a)
Pre process to emphasise higher frequencies.
Definition: misc.cc:55
ssize_t num_samples() const
return the number of samples in the waveform
Definition: EST_Wave.h:143
short & a(ssize_t i, ssize_t channel=0)
Definition: EST_Wave.cc:128
INLINE short & a_no_check(ssize_t i, ssize_t channel=0)
Definition: EST_Wave.h:105
#define FALSE
Definition: EST_bool.h:119
void resize(int num_samples, int num_channels=EST_ALL, int set=1)
resize the waveform
Definition: EST_Wave.h:184
int sample_rate() const
return the sampling rate (frequency)
Definition: EST_Wave.h:147
void EST_post_deemphasis(EST_Wave &signal, EST_Wave &dsignal, float a)
Post process to get the original back (eg after resynthesis).
Definition: misc.cc:76
Extending buffer class.
Definition: EST_TBuffer.h:86