Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang format changes #26946

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tensorflow/lite/examples/minimal/minimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace tflite;
}

int main(int argc, char* argv[]) {
if(argc != 2) {
if (argc != 2) {
fprintf(stderr, "minimal <tflite model>\n");
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/experimental/micro/bluepill/debug_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ extern "C" void DebugLog(const char* s) {
"mov r1, %[str]\n"
"bkpt #0xAB\n"
:
: [ str ] "r"(s)
: [str] "r"(s)
: "r0", "r1");
}
2 changes: 1 addition & 1 deletion tensorflow/lite/experimental/microfrontend/lib/fft_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void FftWriteMemmapPreamble(FILE* fp, const struct FftState* state) {
}

void FftWriteMemmap(FILE* fp, const struct FftState* state,
const char* variable) {
const char* variable) {
fprintf(fp, "%s->input = fft_input;\n", variable);
fprintf(fp, "%s->output = fft_output;\n", variable);
fprintf(fp, "%s->fft_size = %zu;\n", variable, state->fft_size);
Expand Down
1 change: 0 additions & 1 deletion tensorflow/lite/experimental/microfrontend/lib/fft_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ void FftFreeStateContents(struct FftState* state) {
free(state->output);
free(state->scratch);
}

10 changes: 5 additions & 5 deletions tensorflow/lite/experimental/microfrontend/lib/filterbank.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void FilterbankAccumulateChannels(struct FilterbankState* state,
const int width = *channel_widths++;
int j;
for (j = 0; j < width; ++j) {
weight_accumulator += *weights++ * ((uint64_t) *magnitudes);
unweight_accumulator += *unweights++ * ((uint64_t) *magnitudes);
weight_accumulator += *weights++ * ((uint64_t)*magnitudes);
unweight_accumulator += *unweights++ * ((uint64_t)*magnitudes);
++magnitudes;
}
*work++ = weight_accumulator;
Expand Down Expand Up @@ -93,7 +93,7 @@ static uint32_t Sqrt64(uint64_t num) {
// clear. This will cause a slight off by one issue for numbers close to 2^32,
// but it probably isn't going to matter (and gives us a big performance win).
if ((num >> 32) == 0) {
return Sqrt32((uint32_t) num);
return Sqrt32((uint32_t)num);
}
uint64_t res = 0;
int max_bit_number = 64 - MostSignificantBit64(num);
Expand Down Expand Up @@ -121,12 +121,12 @@ uint32_t* FilterbankSqrt(struct FilterbankState* state, int scale_down_shift) {
const int64_t* work = state->work + 1;
// Reuse the work buffer since we're fine clobbering it at this point to hold
// the output.
uint32_t* output = (uint32_t*) state->work;
uint32_t* output = (uint32_t*)state->work;
int i;
for (i = 0; i < num_channels; ++i) {
*output++ = Sqrt64(*work++) >> scale_down_shift;
}
return (uint32_t*) state->work;
return (uint32_t*)state->work;
}

void FilterbankReset(struct FilterbankState* state) {
Expand Down
23 changes: 10 additions & 13 deletions tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ static void CalculateCenterFrequencies(const int num_channels,
const float mel_low = FreqToMel(lower_frequency_limit);
const float mel_hi = FreqToMel(upper_frequency_limit);
const float mel_span = mel_hi - mel_low;
const float mel_spacing = mel_span / ((float) num_channels);
const float mel_spacing = mel_span / ((float)num_channels);
int i;
for (i = 0; i < num_channels; ++i) {
center_frequencies[i] = mel_low + (mel_spacing * (i + 1));
}
}

static void QuantizeFilterbankWeights(const float float_weight,
int16_t* weight, int16_t* unweight) {
static void QuantizeFilterbankWeights(const float float_weight, int16_t* weight,
int16_t* unweight) {
*weight = floor(float_weight * (1 << kFilterbankBits) + 0.5);
*unweight = floor((1.0 - float_weight) * (1 << kFilterbankBits) + 0.5);
}

int FilterbankPopulateState(const struct FilterbankConfig* config,
struct FilterbankState* state,
int sample_rate, int spectrum_size) {
struct FilterbankState* state, int sample_rate,
int spectrum_size) {
state->num_channels = config->num_channels;
const int num_channels_plus_1 = config->num_channels + 1;

Expand All @@ -81,10 +81,8 @@ int FilterbankPopulateState(const struct FilterbankConfig* config,
malloc(num_channels_plus_1 * sizeof(*actual_channel_widths));

if (state->channel_frequency_starts == NULL ||
state->channel_weight_starts == NULL ||
state->channel_widths == NULL ||
center_mel_freqs == NULL ||
actual_channel_starts == NULL ||
state->channel_weight_starts == NULL || state->channel_widths == NULL ||
center_mel_freqs == NULL || actual_channel_starts == NULL ||
actual_channel_widths == NULL) {
free(center_mel_freqs);
free(actual_channel_starts);
Expand All @@ -97,7 +95,7 @@ int FilterbankPopulateState(const struct FilterbankConfig* config,
config->upper_band_limit, center_mel_freqs);

// Always exclude DC.
const float hz_per_sbin = 0.5 * sample_rate / ((float) spectrum_size - 1);
const float hz_per_sbin = 0.5 * sample_rate / ((float)spectrum_size - 1);
state->start_index = 1.5 + config->lower_band_limit / hz_per_sbin;
state->end_index = 0; // Initialized to zero here, but actually set below.

Expand All @@ -115,7 +113,7 @@ int FilterbankPopulateState(const struct FilterbankConfig* config,
for (chan = 0; chan < num_channels_plus_1; ++chan) {
// Keep jumping frequencies until we overshoot the bound on this channel.
int freq_index = chan_freq_index_start;
while (FreqToMel((freq_index) * hz_per_sbin) <= center_mel_freqs[chan]) {
while (FreqToMel((freq_index)*hz_per_sbin) <= center_mel_freqs[chan]) {
++freq_index;
}

Expand Down Expand Up @@ -146,8 +144,7 @@ int FilterbankPopulateState(const struct FilterbankConfig* config,
// alignment?
const int aligned_start =
(chan_freq_index_start / index_alignment) * index_alignment;
const int aligned_width =
(chan_freq_index_start - aligned_start + width);
const int aligned_width = (chan_freq_index_start - aligned_start + width);
const int padded_width =
(((aligned_width - 1) / kFilterbankChannelBlockSize) + 1) *
kFilterbankChannelBlockSize;
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/experimental/microfrontend/lib/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct FrontendOutput FrontendProcessSamples(struct FrontendState* state,
FftCompute(&state->fft, state->window.output, input_shift);

// We can re-ruse the fft's output buffer to hold the energy.
int32_t* energy = (int32_t*) state->fft.output;
int32_t* energy = (int32_t*)state->fft.output;

FilterbankConvertFftComplexToEnergy(&state->filterbank, state->fft.output,
energy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ int main(int argc, char** argv) {
return 1;
}


FILE* fp = fopen(filename, "r");
if (fp == NULL) {
fprintf(stderr, "Failed to open %s for read\n", filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ limitations under the License.
==============================================================================*/
#include <stdio.h>

#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h"
#include "memmap.h"
#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h"

int main(int argc, char** argv) {
struct FrontendState* frontend_state = GetFrontendStateMemmap();
Expand Down
10 changes: 4 additions & 6 deletions tensorflow/lite/experimental/microfrontend/lib/frontend_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ int FrontendPopulateState(const struct FrontendConfig* config,

int input_correction_bits =
MostSignificantBit32(state->fft.fft_size) - 1 - (kFilterbankBits / 2);
if (!PcanGainControlPopulateState(&config->pcan_gain_control,
&state->pcan_gain_control,
state->noise_reduction.estimate,
state->filterbank.num_channels,
state->noise_reduction.smoothing_bits,
input_correction_bits)) {
if (!PcanGainControlPopulateState(
&config->pcan_gain_control, &state->pcan_gain_control,
state->noise_reduction.estimate, state->filterbank.num_channels,
state->noise_reduction.smoothing_bits, input_correction_bits)) {
fprintf(stderr, "Failed to populate pcan gain control state\n");
return 0;
}
Expand Down
7 changes: 3 additions & 4 deletions tensorflow/lite/experimental/microfrontend/lib/log_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static uint32_t Log2FractionPart(const uint32_t x, const uint32_t log2x) {
// Part 2
const uint32_t base_seg = frac >> (kLogScaleLog2 - kLogSegmentsLog2);
const uint32_t seg_unit =
(((uint32_t) 1) << kLogScaleLog2) >> kLogSegmentsLog2;
(((uint32_t)1) << kLogScaleLog2) >> kLogSegmentsLog2;

const int32_t c0 = kLogLut[base_seg];
const int32_t c1 = kLogLut[base_seg + 1];
Expand All @@ -51,8 +51,7 @@ static uint32_t Log(const uint32_t x, const uint32_t scale_shift) {
const uint32_t fraction = Log2FractionPart(x, integer);
const uint32_t log2 = (integer << kLogScaleLog2) + fraction;
const uint32_t round = kLogScale / 2;
const uint32_t loge =
(((uint64_t) kLogCoeff) * log2 + round) >> kLogScaleLog2;
const uint32_t loge = (((uint64_t)kLogCoeff) * log2 + round) >> kLogScaleLog2;
// Finally scale to our output scale
const uint32_t loge_scaled = ((loge << scale_shift) + round) >> kLogScaleLog2;
return loge_scaled;
Expand All @@ -61,7 +60,7 @@ static uint32_t Log(const uint32_t x, const uint32_t scale_shift) {
uint16_t* LogScaleApply(struct LogScaleState* state, uint32_t* signal,
int signal_size, int correction_bits) {
const int scale_shift = state->scale_shift;
uint16_t* output = (uint16_t*) signal;
uint16_t* output = (uint16_t*)signal;
uint16_t* ret = output;
int i;
for (i = 0; i < signal_size; ++i) {
Expand Down
10 changes: 5 additions & 5 deletions tensorflow/lite/experimental/microfrontend/lib/noise_reduction.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void NoiseReductionApply(struct NoiseReductionState* state, uint32_t* signal) {
// Update the estimate of the noise.
const uint32_t signal_scaled_up = signal[i] << state->smoothing_bits;
uint32_t estimate =
(((uint64_t) signal_scaled_up * smoothing) +
((uint64_t) state->estimate[i] * one_minus_smoothing)) >>
(((uint64_t)signal_scaled_up * smoothing) +
((uint64_t)state->estimate[i] * one_minus_smoothing)) >>
kNoiseReductionBits;
state->estimate[i] = estimate;

Expand All @@ -37,10 +37,10 @@ void NoiseReductionApply(struct NoiseReductionState* state, uint32_t* signal) {
}

const uint32_t floor =
((uint64_t) signal[i] * state->min_signal_remaining) >>
((uint64_t)signal[i] * state->min_signal_remaining) >>
kNoiseReductionBits;
const uint32_t subtracted = (signal_scaled_up - estimate) >>
state->smoothing_bits;
const uint32_t subtracted =
(signal_scaled_up - estimate) >> state->smoothing_bits;
const uint32_t output = subtracted > floor ? subtracted : floor;
signal[i] = output;
}
Expand Down
19 changes: 9 additions & 10 deletions tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ int16_t WideDynamicFunction(const uint32_t x, const int16_t* lut) {
const int16_t interval = MostSignificantBit32(x);
lut += 4 * interval - 6;

const int16_t frac = ((interval < 11)
? (x << (11 - interval))
: (x >> (interval - 11))
) & 0x3FF;
const int16_t frac =
((interval < 11) ? (x << (11 - interval)) : (x >> (interval - 11))) &
0x3FF;

int32_t result = ((int32_t) lut[2] * frac) >> 5;
result += ((int32_t) lut[1]) << 5;
int32_t result = ((int32_t)lut[2] * frac) >> 5;
result += ((int32_t)lut[1]) << 5;
result *= frac;
result = (result + (1 << 14)) >> 15;
result += lut[0];
return (int16_t) result;
return (int16_t)result;
}

uint32_t PcanShrink(const uint32_t x) {
Expand All @@ -49,9 +48,9 @@ void PcanGainControlApply(struct PcanGainControlState* state,
uint32_t* signal) {
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;
const uint32_t gain =
WideDynamicFunction(state->noise_estimate[i], state->gain_lut);
const uint32_t snr = ((uint64_t)signal[i] * gain) >> state->snr_shift;
signal[i] = PcanShrink(snr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ void PcanGainControlFillConfigWithDefaults(

int16_t PcanGainLookupFunction(const struct PcanGainControlConfig* config,
int32_t input_bits, uint32_t x) {
const float x_as_float = ((float) x) / ((uint32_t) 1 << input_bits);
const float gain_as_float = ((uint32_t) 1 << config->gain_bits) *
const float x_as_float = ((float)x) / ((uint32_t)1 << input_bits);
const float gain_as_float =
((uint32_t)1 << config->gain_bits) *
powf(x_as_float + config->offset, -config->strength);

if (gain_as_float > kint16max) {
return kint16max;
}
return (int16_t) (gain_as_float + 0.5f);
return (int16_t)(gain_as_float + 0.5f);
}

int PcanGainControlPopulateState(const struct PcanGainControlConfig* config,
Expand Down Expand Up @@ -64,23 +65,23 @@ int PcanGainControlPopulateState(const struct PcanGainControlConfig* config,
state->gain_lut -= 6;
int interval;
for (interval = 2; interval <= kWideDynamicFunctionBits; ++interval) {
const uint32_t x0 = (uint32_t) 1 << (interval - 1);
const uint32_t x0 = (uint32_t)1 << (interval - 1);
const uint32_t x1 = x0 + (x0 >> 1);
const uint32_t x2 = (interval == kWideDynamicFunctionBits)
? x0 + (x0 - 1) : 2 * x0;
const uint32_t x2 =
(interval == kWideDynamicFunctionBits) ? x0 + (x0 - 1) : 2 * x0;

const int16_t y0 = PcanGainLookupFunction(config, input_bits, x0);
const int16_t y1 = PcanGainLookupFunction(config, input_bits, x1);
const int16_t y2 = PcanGainLookupFunction(config, input_bits, x2);

const int32_t diff1 = (int32_t) y1 - y0;
const int32_t diff2 = (int32_t) y2 - y0;
const int32_t diff1 = (int32_t)y1 - y0;
const int32_t diff2 = (int32_t)y2 - y0;
const int32_t a1 = 4 * diff1 - diff2;
const int32_t a2 = diff2 - a1;

state->gain_lut[4 * interval] = y0;
state->gain_lut[4 * interval + 1] = (int16_t) a1;
state->gain_lut[4 * interval + 2] = (int16_t) a2;
state->gain_lut[4 * interval + 1] = (int16_t)a1;
state->gain_lut[4 * interval + 2] = (int16_t)a2;
}
state->gain_lut += 6;
return 1;
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/experimental/microfrontend/lib/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int WindowProcessSamples(struct WindowState* state, const int16_t* samples,
int16_t max_abs_output_value = 0;
for (i = 0; i < size; ++i) {
int16_t new_value =
(((int32_t) *input++) * *coefficients++) >> kFrontendWindowBits;
(((int32_t)*input++) * *coefficients++) >> kFrontendWindowBits;
*output++ = new_value;
if (new_value < 0) {
new_value = -new_value;
Expand Down
11 changes: 4 additions & 7 deletions tensorflow/lite/experimental/microfrontend/lib/window_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ int WindowPopulateState(const struct WindowConfig* config,
state->size = config->size_ms * sample_rate / 1000;
state->step = config->step_size_ms * sample_rate / 1000;

state->coefficients = malloc(
state->size * sizeof(*state->coefficients));
state->coefficients = malloc(state->size * sizeof(*state->coefficients));
if (state->coefficients == NULL) {
fprintf(stderr, "Failed to allocate window coefficients\n");
return 0;
}

// Populate the window values.
const float arg = M_PI * 2.0 / ((float) state->size);
const float arg = M_PI * 2.0 / ((float)state->size);
int i;
for (i = 0; i < state->size; ++i) {
float float_value = 0.5 - (0.5 * cos(arg * (i + 0.5)));
Expand All @@ -47,15 +46,13 @@ int WindowPopulateState(const struct WindowConfig* config,
}

state->input_used = 0;
state->input = malloc(
state->size * sizeof(*state->input));
state->input = malloc(state->size * sizeof(*state->input));
if (state->input == NULL) {
fprintf(stderr, "Failed to allocate window input\n");
return 0;
}

state->output = malloc(
state->size * sizeof(*state->output));
state->output = malloc(state->size * sizeof(*state->output));
if (state->output == NULL) {
fprintf(stderr, "Failed to allocate window output\n");
return 0;
Expand Down