Fix build error

PiperOrigin-RevId: 225097826
This commit is contained in:
Jian Li 2018-12-11 17:03:32 -08:00 committed by TensorFlower Gardener
parent db340f9efc
commit 5fecd1ead7
15 changed files with 68 additions and 36 deletions

View File

@ -142,7 +142,8 @@ void GenerateFeatures(TfLiteAudioMicrofrontendParams* data,
if (output.values != nullptr) {
frame_buffer[frame_index].reserve(output.size);
for (int i = 0; i < output.size; ++i) {
int i;
for (i = 0; i < output.size; ++i) {
frame_buffer[frame_index].push_back(static_cast<T>(output.values[i]) /
data->out_scale);
}
@ -152,9 +153,10 @@ void GenerateFeatures(TfLiteAudioMicrofrontendParams* data,
int index = 0;
std::vector<T> pad(data->state->filterbank.num_channels, 0);
for (int anchor = 0; anchor < frame_buffer.size();
anchor += data->frame_stride) {
for (int frame = anchor - data->left_context;
int anchor;
for (anchor = 0; anchor < frame_buffer.size(); anchor += data->frame_stride) {
int frame;
for (frame = anchor - data->left_context;
frame <= anchor + data->right_context; ++frame) {
std::vector<T>* feature;
if (data->zero_padding && (frame < 0 || frame >= frame_buffer.size())) {

View File

@ -140,13 +140,16 @@ class BaseMicroFrontendTest : public ::testing::Test {
// Mimic padding behaviour with zero_padding = true.
std::vector<int> output_flattened;
for (int anchor = 0; anchor < output.size();
int anchor;
for (anchor = 0; anchor < output.size();
anchor += micro_frontend->num_frame_stride()) {
for (int frame = anchor - micro_frontend->num_left_context();
int frame;
for (frame = anchor - micro_frontend->num_left_context();
frame <= anchor + micro_frontend->num_right_context(); ++frame) {
if (frame < 0 || frame >= output.size()) {
// Padding with zeros.
for (int j = 0; j < num_frequency_per_frame; ++j) {
int j;
for (j = 0; j < num_frequency_per_frame; ++j) {
output_flattened.push_back(0.0);
}
} else {

View File

@ -38,7 +38,8 @@ TEST(FftTest, CheckOutputValues) {
{-887, 0}, {3000, 3000}, {0, -6401}, {-3000, 3000}, {886, 0}, {118, 119},
{0, 25}, {9, -10}, {19, 0}, {9, 9}, {0, 0}};
ASSERT_EQ(state.fft_size / 2 + 1, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i <= state.fft_size / 2; ++i) {
int i;
for (i = 0; i <= state.fft_size / 2; ++i) {
EXPECT_EQ(state.output[i].real, expected[i].real);
EXPECT_EQ(state.output[i].imag, expected[i].imag);
}

View File

@ -17,7 +17,8 @@ limitations under the License.
static void PrintArray(FILE* fp, const char* name, const int16_t* values,
size_t size) {
fprintf(fp, "static int16_t filterbank_%s[] = {", name);
for (int i = 0; i < size; ++i) {
int i;
for (i = 0; i < size; ++i) {
fprintf(fp, "%d", values[i]);
if (i < size - 1) {
fprintf(fp, ", ");

View File

@ -71,7 +71,8 @@ TEST_F(FilterbankTest, CheckChannelFrequencyStarts) {
const int16_t expected[] = {0, 4, 8};
ASSERT_EQ(state.num_channels + 1, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i <= state.num_channels; ++i) {
int i;
for (i = 0; i <= state.num_channels; ++i) {
EXPECT_EQ(state.channel_frequency_starts[i], expected[i]);
}
@ -85,7 +86,8 @@ TEST_F(FilterbankTest, CheckChannelWeightStarts) {
const int16_t expected[] = {0, 8, 16};
ASSERT_EQ(state.num_channels + 1, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i <= state.num_channels; ++i) {
int i;
for (i = 0; i <= state.num_channels; ++i) {
EXPECT_EQ(state.channel_weight_starts[i], expected[i]);
}
@ -99,7 +101,8 @@ TEST_F(FilterbankTest, CheckChannelWidths) {
const int16_t expected[] = {8, 8, 8};
ASSERT_EQ(state.num_channels + 1, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i <= state.num_channels; ++i) {
int i;
for (i = 0; i <= state.num_channels; ++i) {
EXPECT_EQ(state.channel_widths[i], expected[i]);
}
@ -117,7 +120,8 @@ TEST_F(FilterbankTest, CheckWeights) {
ASSERT_EQ(state.channel_weight_starts[state.num_channels] +
state.channel_widths[state.num_channels],
sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
int i;
for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
EXPECT_EQ(state.weights[i], expected[i]);
}
@ -135,7 +139,8 @@ TEST_F(FilterbankTest, CheckUnweights) {
ASSERT_EQ(state.channel_weight_starts[state.num_channels] +
state.channel_widths[state.num_channels],
sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
int i;
for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
EXPECT_EQ(state.unweights[i], expected[i]);
}
@ -154,7 +159,8 @@ TEST_F(FilterbankTest, CheckConvertFftComplexToEnergy) {
int32_t* energy = reinterpret_cast<int32_t*>(fake_fft);
FilterbankConvertFftComplexToEnergy(&state, fake_fft, energy);
for (int i = state.start_index; i < state.end_index; ++i) {
int i;
for (i = state.start_index; i < state.end_index; ++i) {
EXPECT_EQ(energy[i], kEnergy[i]);
}
}
@ -167,7 +173,8 @@ TEST_F(FilterbankTest, CheckAccumulateChannels) {
FilterbankAccumulateChannels(&state, kEnergy);
ASSERT_EQ(state.num_channels + 1, sizeof(kWork) / sizeof(kWork[0]));
for (int i = 0; i <= state.num_channels; ++i) {
int i;
for (i = 0; i <= state.num_channels; ++i) {
EXPECT_EQ(state.work[i], kWork[i]);
}
@ -184,7 +191,8 @@ TEST_F(FilterbankTest, CheckSqrt) {
const uint32_t expected[] = {247311, 508620};
ASSERT_EQ(state.num_channels, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < state.num_channels; ++i) {
int i;
for (i = 0; i < state.num_channels; ++i) {
EXPECT_EQ(scaled_filterbank[i], expected[i]);
}

View File

@ -64,7 +64,8 @@ TEST_F(FrontendTest, CheckOutputValues) {
const uint16_t expected[] = {479, 425};
ASSERT_EQ(output.size, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < output.size; ++i) {
int i;
for (i = 0; i < output.size; ++i) {
EXPECT_EQ(output.values[i], expected[i]);
}
@ -86,7 +87,8 @@ TEST_F(FrontendTest, CheckConsecutiveWindow) {
const int16_t expected[] = {436, 378};
ASSERT_EQ(output.size, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < output.size; ++i) {
int i;
for (i = 0; i < output.size; ++i) {
EXPECT_EQ(output.values[i], expected[i]);
}

View File

@ -63,7 +63,8 @@ uint16_t* LogScaleApply(struct LogScaleState* state, uint32_t* signal,
const int scale_shift = state->scale_shift;
uint16_t* output = (uint16_t*) signal;
uint16_t* ret = output;
for (int i = 0; i < signal_size; ++i) {
int i;
for (i = 0; i < signal_size; ++i) {
uint32_t value = *signal++;
if (state->enable_log) {
if (correction_bits < 0) {

View File

@ -34,7 +34,8 @@ TEST(LogScaleTest, CheckOutputValues) {
kCorrectionBits);
const uint16_t expected[] = {479, 425};
for (int i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
int i;
for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
EXPECT_EQ(output[i], expected[i]);
}
}
@ -50,7 +51,8 @@ TEST(LogScaleTest, CheckOutputValuesNoLog) {
kCorrectionBits);
const uint16_t expected[] = {65535, 45998};
for (int i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
int i;
for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
EXPECT_EQ(output[i], expected[i]);
}
}

View File

@ -44,7 +44,8 @@ TEST_F(NoiseReductionTest, TestNoiseReductionEstimate) {
const uint32_t expected[] = {6321887, 31248341};
ASSERT_EQ(state.num_channels, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < state.num_channels; ++i) {
int i;
for (i = 0; i < state.num_channels; ++i) {
EXPECT_EQ(state.estimate[i], expected[i]);
}
@ -60,7 +61,8 @@ TEST_F(NoiseReductionTest, TestNoiseReduction) {
const uint32_t expected[] = {241137, 478104};
ASSERT_EQ(state.num_channels, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < state.num_channels; ++i) {
int i;
for (i = 0; i < state.num_channels; ++i) {
EXPECT_EQ(signal[i], expected[i]);
}

View File

@ -47,7 +47,8 @@ uint32_t PcanShrink(const uint32_t x) {
void PcanGainControlApply(struct PcanGainControlState* state,
uint32_t* signal) {
for (int i = 0; i < state->num_channels; ++i) {
int i;
for (i = 0; i < state->num_channels; ++i) {
const uint32_t gain = WideDynamicFunction(state->noise_estimate[i],
state->gain_lut);
const uint32_t snr = ((uint64_t) signal[i] * gain) >> state->snr_shift;

View File

@ -49,7 +49,8 @@ TEST_F(PcanGainControlTest, TestPcanGainControl) {
const uint32_t expected[] = {3578, 1533};
ASSERT_EQ(state.num_channels, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < state.num_channels; ++i) {
int i;
for (i = 0; i < state.num_channels; ++i) {
EXPECT_EQ(signal[i], expected[i]);
}

View File

@ -62,7 +62,8 @@ int PcanGainControlPopulateState(const struct PcanGainControlConfig* config,
state->gain_lut[0] = PcanGainLookupFunction(config, input_bits, 0);
state->gain_lut[1] = PcanGainLookupFunction(config, input_bits, 1);
state->gain_lut -= 6;
for (int interval = 2; interval <= kWideDynamicFunctionBits; ++interval) {
int interval;
for (interval = 2; interval <= kWideDynamicFunctionBits; ++interval) {
const uint32_t x0 = (uint32_t) 1 << (interval - 1);
const uint32_t x1 = x0 + (x0 >> 1);
const uint32_t x2 = (interval == kWideDynamicFunctionBits)

View File

@ -16,7 +16,8 @@ limitations under the License.
void WindowWriteMemmapPreamble(FILE* fp, const struct WindowState* state) {
fprintf(fp, "static int16_t window_coefficients[] = {\n");
for (int i = 0; i < state->size; ++i) {
int i;
for (i = 0; i < state->size; ++i) {
fprintf(fp, "%d", state->coefficients[i]);
if (i < state->size - 1) {
fprintf(fp, ", ");

View File

@ -48,7 +48,8 @@ TEST_F(WindowTest, CheckCoefficients) {
3843, 3541, 3145, 2681, 2177, 1664, 1176,
743, 391, 144, 16};
ASSERT_EQ(state.size, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < state.size; ++i) {
int i;
for (i = 0; i < state.size; ++i) {
EXPECT_EQ(state.coefficients[i], expected[i]);
}
@ -64,7 +65,8 @@ TEST_F(WindowTest, CheckResidualInput) {
&state, kFakeAudioData,
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read));
for (int i = kStepSamples; i < kWindowSamples; ++i) {
int i;
for (i = kStepSamples; i < kWindowSamples; ++i) {
EXPECT_EQ(state.input[i - kStepSamples], kFakeAudioData[i]);
}
@ -84,7 +86,8 @@ TEST_F(WindowTest, CheckOutputValues) {
0, 1151, 0, -5944, 0, 13311, 0, -21448, 0, 28327, 0, -32256, 0, 32255,
0, -28328, 0, 21447, 0, -13312, 0, 5943, 0, -1152, 0};
ASSERT_EQ(state.size, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < state.size; ++i) {
int i;
for (i = 0; i < state.size; ++i) {
EXPECT_EQ(state.output[i], expected[i]);
}
@ -122,7 +125,8 @@ TEST_F(WindowTest, CheckConsecutiveWindow) {
0, -1152, 0, 5943, 0, -13312, 0, 21447, 0, -28328, 0, 32255, 0, -32256,
0, 28327, 0, -21448, 0, 13311, 0, -5944, 0, 1151, 0};
ASSERT_EQ(state.size, sizeof(expected) / sizeof(expected[0]));
for (int i = 0; i < state.size; ++i) {
int i;
for (i = 0; i < state.size; ++i) {
EXPECT_EQ(state.output[i], expected[i]);
}

View File

@ -250,7 +250,8 @@ class AudioMicrofrontendOp : public OpKernel {
if (output.values != nullptr) {
frame_buffer[frame_index].reserve(output.size);
for (int i = 0; i < output.size; ++i) {
int i;
for (i = 0; i < output.size; ++i) {
frame_buffer[frame_index].push_back(static_cast<T>(output.values[i]) /
out_scale_);
}
@ -261,9 +262,10 @@ class AudioMicrofrontendOp : public OpKernel {
int index = 0;
std::vector<T> pad(config_.filterbank.num_channels, 0);
for (int anchor = 0; anchor < frame_buffer.size();
anchor += frame_stride_) {
for (int frame = anchor - left_context_; frame <= anchor + right_context_;
int anchor;
for (anchor = 0; anchor < frame_buffer.size(); anchor += frame_stride_) {
int frame;
for (frame = anchor - left_context_; frame <= anchor + right_context_;
++frame) {
std::vector<T>* feature;
if (zero_padding_ && (frame < 0 || frame >= frame_buffer.size())) {