@@ -35,6 +35,8 @@ enum NoiseType { kZero = 0, kGaussian, kMSequence, kNumNoiseTypes };
3535const int kDefaultFramePeriod (100 );
3636const int kDefaultInterpolationPeriod (1 );
3737const NoiseType kDefaultNoiseType (NoiseType::kMSequence );
38+ const sptk::ExcitationGeneration::NormalizationType kDefaultNormalizationType (
39+ sptk::ExcitationGeneration::NormalizationType::kPower );
3840const int kDefaultSeed (1 );
3941const double kMagicNumberForUnvoicedFrame (0.0 );
4042
@@ -48,6 +50,10 @@ void PrintUsage(std::ostream* stream) {
4850 *stream << " options:" << std::endl;
4951 *stream << " -p p : frame period ( int)[" << std::setw (5 ) << std::right << kDefaultFramePeriod << " ][ 1 <= p <= ]" << std::endl; // NOLINT
5052 *stream << " -i i : interpolation period ( int)[" << std::setw (5 ) << std::right << kDefaultInterpolationPeriod << " ][ 0 <= i <= p/2 ]" << std::endl; // NOLINT
53+ *stream << " -N N : normalization type ( int)[" << std::setw (5 ) << std::right << kDefaultNormalizationType << " ][ 0 <= N <= 2 ]" << std::endl; // NOLINT
54+ *stream << " 0 (none)" << std::endl;
55+ *stream << " 1 (power)" << std::endl;
56+ *stream << " 2 (magnitude)" << std::endl;
5157 *stream << " -n n : noise type ( int)[" << std::setw (5 ) << std::right << kDefaultNoiseType << " ][ 0 <= n <= 2 ]" << std::endl; // NOLINT
5258 *stream << " 0 (none)" << std::endl;
5359 *stream << " 1 (Gaussian)" << std::endl;
@@ -60,7 +66,7 @@ void PrintUsage(std::ostream* stream) {
6066 *stream << " excitation (double)" << std::endl;
6167 *stream << " notice:" << std::endl;
6268 *stream << " if i = 0, don't interpolate pitch" << std::endl;
63- *stream << " s is valid only if n = 1" << std::endl;
69+ *stream << " -s option is valid only if n = 1" << std::endl;
6470 *stream << " magic number for unvoiced frame is " << kMagicNumberForUnvoicedFrame << std::endl; // NOLINT
6571 *stream << std::endl;
6672 *stream << " SPTK: version " << sptk::kVersion << std::endl;
@@ -77,6 +83,11 @@ void PrintUsage(std::ostream* stream) {
7783 * - frame_period @f$(1 \le P)@f$
7884 * - @b -i @e int
7985 * - interpolation period @f$(0 \le I \le P/2)@f$
86+ * - @b -N @e int
87+ * - normalization type
88+ * \arg @c 0 none
89+ * \arg @c 1 power
90+ * \arg @c 2 magnitude
8091 * - @b -n @e int
8192 * - noise type
8293 * \arg @c 0 none
@@ -110,11 +121,13 @@ void PrintUsage(std::ostream* stream) {
110121int main (int argc, char * argv[]) {
111122 int frame_period (kDefaultFramePeriod );
112123 int interpolation_period (kDefaultInterpolationPeriod );
124+ sptk::ExcitationGeneration::NormalizationType normalization_type (
125+ kDefaultNormalizationType );
113126 NoiseType noise_type (kDefaultNoiseType );
114127 int seed (kDefaultSeed );
115128
116129 for (;;) {
117- const int option_char (getopt_long (argc, argv, " p:i:n:s:h" , NULL , NULL ));
130+ const int option_char (getopt_long (argc, argv, " p:i:N: n:s:h" , NULL , NULL ));
118131 if (-1 == option_char) break ;
119132
120133 switch (option_char) {
@@ -140,6 +153,25 @@ int main(int argc, char* argv[]) {
140153 }
141154 break ;
142155 }
156+ case ' N' : {
157+ const int min (0 );
158+ const int max (
159+ static_cast <int >(sptk::ExcitationGeneration::NormalizationType::
160+ kNumNormalizationTypes ) -
161+ 1 );
162+ int tmp;
163+ if (!sptk::ConvertStringToInteger (optarg, &tmp) ||
164+ !sptk::IsInRange (tmp, min, max)) {
165+ std::ostringstream error_message;
166+ error_message << " The argument for the -N option must be an integer "
167+ << " in the range of " << min << " to " << max;
168+ sptk::PrintErrorMessage (" excite" , error_message);
169+ return 1 ;
170+ }
171+ normalization_type =
172+ static_cast <sptk::ExcitationGeneration::NormalizationType>(tmp);
173+ break ;
174+ }
143175 case ' n' : {
144176 const int min (0 );
145177 const int max (static_cast <int >(kNumNoiseTypes ) - 1 );
@@ -243,7 +275,8 @@ int main(int argc, char* argv[]) {
243275 }
244276 }
245277 sptk::ExcitationGeneration excitation_generation (
246- &input_source_interpolation_with_magic_number, random_generation);
278+ &input_source_interpolation_with_magic_number, random_generation,
279+ normalization_type);
247280
248281 if (!excitation_generation.IsValid ()) {
249282 std::ostringstream error_message;
0 commit comments