1#!/bin/sh
2#####################################################-*-mode:shell-script-*-
3##                                                                       ##
4##                   Carnegie Mellon University and                      ##
5##                   Alan W Black and Kevin A. Lenzo                     ##
6##                      Copyright (c) 1998-2000                          ##
7##                        All Rights Reserved.                           ##
8##                                                                       ##
9##  Permission is hereby granted, free of charge, to use and distribute  ##
10##  this software and its documentation without restriction, including   ##
11##  without limitation the rights to use, copy, modify, merge, publish,  ##
12##  distribute, sublicense, and/or sell copies of this work, and to      ##
13##  permit persons to whom this work is furnished to do so, subject to   ##
14##  the following conditions:                                            ##
15##   1. The code must retain the above copyright notice, this list of    ##
16##      conditions and the following disclaimer.                         ##
17##   2. Any modifications must be clearly marked as such.                ##
18##   3. Original authors' names are not deleted.                         ##
19##   4. The authors' names are not used to endorse or promote products   ##
20##      derived from this software without specific prior written        ##
21##      permission.                                                      ##
22##                                                                       ##
23##  CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK         ##
24##  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      ##
25##  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   ##
26##  SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE      ##
27##  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    ##
28##  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   ##
29##  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          ##
30##  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       ##
31##  THIS SOFTWARE.                                                       ##
32##                                                                       ##
33###########################################################################
34##                                                                       ##
35##  Find power normalization contour for each waveform file              ##
36##      Finds power for each labelled vowel                              ##
37##      Finds mean power for each vowel                                  ##
38##      Construct power contour interpolating between vowels to break    ##
39##        points                                                         ##
40##                                                                       ##
41##  Naively assumes that vowels in phoneset start with (upper or lower   ##
42##  letter vowels)                                                       ##
43##                                                                       ##
44##  usage:  bin/find_powercontours lab/*.lab                             ##
45##                                                                       ##
46###########################################################################
47
48if [ $# = 0 ]
49then
50   echo "Find power normalization contour for each file"
51   echo "Usage:  bin/find_powercontours lab/*.lab"
52   exit 1
53fi
54
55for i in $*
56do
57   fname=`basename $i .lab`
58   echo $fname >/dev/tty
59   cat $i | sed 's/h#/pau/' |
60   awk 'BEGIN {fname="'$fname'"; }
61        {if ((($3 ~ /^[AaEeIiOoUu].*/) ||
62	      ($3 ~ "SIL") ||
63	      ($3 ~ "pau")) &&
64             ($3 != "using"))
65         {
66	   printf("echo START %s %s %f\n",fname,$3,(ltime+$1)/2);
67           printf("ch_wave -start %f -end %f wav/%s.wav -otype raw -ostype ascii\n",ltime,$1,fname);
68         }
69         if ($3 != "DB")
70            ltime=$1}' | sh |
71         awk 'BEGIN {fname="start";}
72              {if ($1 == "START")
73              {
74                  if (fname != "start")
75		       print fname,ph,point,t,sqrt(t/l)
76                  fname = $2;
77                  ph=$3;
78                  point=$4;
79                  l=1;
80                  t=0;
81              }
82              else
83              {
84                 t += $1*$1;
85                 l++;
86              }}
87              END { # dont care about final pau
88                    # print fname,ph,point,t,sqrt(t/l)
89                  }'
90done >etc/all_vpower
91
92# Find the mean power for each vowel
93cat etc/all_vpower |
94awk '{vp[$2] += $5;
95      vn[$2] += 1;}
96     END {for (i in vp)
97            printf("vp[\"%s\"] =  %f;\n",i,vp[i]/vn[i]); }' >etc/mean_vpow
98
99if [ ! -d pow ]
100then
101   mkdir pow
102fi
103
104# find the power modficiation contour for each file
105cat etc/all_vpower |
106awk 'BEGIN {'"`cat etc/mean_vpow`"' lfile = ""; t = 0; nt = 0;
107}
108   {if ($1 != lfile)
109    {
110       if (lfile != "")
111          printf("EOF\n");
112       printf("cat >pow/%s.lab <<EOF\n",$1);
113       printf("#\n");
114   }
115    if (vp[$2] != 0)
116    {
117       if ($5 > 0)
118          printf("%f 123 %f\n",$3,vp[$2]/$5);
119    }
120    lfile = $1;
121   }
122   END {
123      printf("EOF\n");
124   }' | sh
125
126
127
128
129