Skip to content

Commit ef35a10

Browse files
authored
Merge pull request #78 from sp-nitech/pitch_mark
Update pitch_mark
2 parents ca591f7 + 8c3a81d commit ef35a10

File tree

8 files changed

+172
-45
lines changed

8 files changed

+172
-45
lines changed

include/SPTK/generation/excitation_generation.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,23 @@ namespace sptk {
3232
*/
3333
class ExcitationGeneration {
3434
public:
35+
/**
36+
* Normalization type.
37+
*/
38+
enum NormalizationType {
39+
kNone = 0,
40+
kPower,
41+
kMagnitude,
42+
kNumNormalizationTypes
43+
};
44+
3545
/**
3646
* @param[in] input_source Input source.
3747
* @param[in] random_generation Random value generator.
3848
*/
3949
ExcitationGeneration(InputSourceInterpolationWithMagicNumber* input_source,
40-
RandomGenerationInterface* random_generation);
50+
RandomGenerationInterface* random_generation,
51+
NormalizationType normalization_type = kPower);
4152

4253
virtual ~ExcitationGeneration() {
4354
}
@@ -63,6 +74,7 @@ class ExcitationGeneration {
6374
private:
6475
InputSourceInterpolationWithMagicNumber* input_source_;
6576
RandomGenerationInterface* random_generation_;
77+
const NormalizationType normalization_type_;
6678

6779
bool is_valid_;
6880

src/analysis/goertzel_analysis.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "SPTK/analysis/goertzel_analysis.h"
1818

19-
#include <cmath> // std::round
19+
#include <cmath> // std::cos, std::round, std::sin
2020
#include <cstddef> // std::size_t
2121
#include <vector> // std::vector
2222

src/generation/excitation_generation.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ namespace sptk {
2323

2424
ExcitationGeneration::ExcitationGeneration(
2525
InputSourceInterpolationWithMagicNumber* input_source,
26-
RandomGenerationInterface* random_generation)
26+
RandomGenerationInterface* random_generation,
27+
NormalizationType normalization_type)
2728
: input_source_(input_source),
2829
random_generation_(random_generation),
30+
normalization_type_(normalization_type),
2931
is_valid_(true),
3032
phase_(1.0) {
3133
if (NULL == input_source_ || !input_source_->IsValid()) {
@@ -79,7 +81,15 @@ bool ExcitationGeneration::Get(double* excitation, double* pulse, double* noise,
7981
double pulse_in_current_point;
8082
if (1.0 <= phase_) {
8183
phase_ -= 1.0;
82-
pulse_in_current_point = std::sqrt(pitch_in_current_point);
84+
if (kNone == normalization_type_) {
85+
pulse_in_current_point = 1.0;
86+
} else if (kPower == normalization_type_) {
87+
pulse_in_current_point = std::sqrt(pitch_in_current_point);
88+
} else if (kMagnitude == normalization_type_) {
89+
pulse_in_current_point = pitch_in_current_point;
90+
} else {
91+
return false;
92+
}
8393
} else {
8494
pulse_in_current_point = 0.0;
8595
}

src/main/excite.cc

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ enum NoiseType { kZero = 0, kGaussian, kMSequence, kNumNoiseTypes };
3535
const int kDefaultFramePeriod(100);
3636
const int kDefaultInterpolationPeriod(1);
3737
const NoiseType kDefaultNoiseType(NoiseType::kMSequence);
38+
const sptk::ExcitationGeneration::NormalizationType kDefaultNormalizationType(
39+
sptk::ExcitationGeneration::NormalizationType::kPower);
3840
const int kDefaultSeed(1);
3941
const 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) {
110121
int 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;

src/main/frame.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <iostream> // std::cerr, std::cin, std::cout, std::endl, etc.
2121
#include <numeric> // std::accumulate
2222
#include <sstream> // std::ostringstream
23+
#include <string> // std::char_traits
2324
#include <vector> // std::vector
2425

2526
#include "GETOPT/ya_getopt.h"
@@ -274,7 +275,7 @@ int main(int argc, char* argv[]) {
274275
// Extract the remaining frames.
275276
const int overlap(frame_length - frame_period);
276277
if (0 < overlap) {
277-
bool is_eof(input_stream.peek() == std::ios::traits_type::eof());
278+
bool is_eof(input_stream.peek() == std::char_traits<char>::eof());
278279
int last_data_position_in_frame(center + actual_read_size - 1);
279280
while (center <= last_data_position_in_frame) {
280281
if (is_eof) {
@@ -302,7 +303,7 @@ int main(int argc, char* argv[]) {
302303
return 1;
303304
}
304305

305-
if (input_stream.peek() == std::iostream::traits_type::eof()) {
306+
if (input_stream.peek() == std::char_traits<char>::eof()) {
306307
last_data_position_in_frame = overlap + actual_read_size - 1;
307308
is_eof = true;
308309
}

0 commit comments

Comments
 (0)