Clang format changes

This commit is contained in:
Siju Samuel 2019-03-20 21:06:15 +05:30
parent 203c4f750e
commit 96c8ad77f2
20 changed files with 75 additions and 86 deletions

View File

@ -68,4 +68,3 @@ void FftFreeStateContents(struct FftState* state) {
free(state->output);
free(state->scratch);
}

View File

@ -47,15 +47,15 @@ static void CalculateCenterFrequencies(const int num_channels,
}
}
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;
@ -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);
@ -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;

View File

@ -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);

View File

@ -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();

View File

@ -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;
}

View File

@ -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;

View File

@ -39,8 +39,8 @@ void NoiseReductionApply(struct NoiseReductionState* state, uint32_t* signal) {
const uint32_t floor =
((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;
}

View File

@ -24,10 +24,9 @@ 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;
@ -49,8 +48,8 @@ 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 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);
}

View File

@ -30,7 +30,8 @@ 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 gain_as_float =
((uint32_t)1 << config->gain_bits) *
powf(x_as_float + config->offset, -config->strength);
if (gain_as_float > kint16max) {
@ -66,8 +67,8 @@ int PcanGainControlPopulateState(const struct PcanGainControlConfig* config,
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)
? 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);

View File

@ -29,8 +29,7 @@ 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;
@ -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;

View File

@ -59,11 +59,11 @@ limitations under the License.
#include <limits>
#include <memory>
#include <farmhash.h>
#include "tensorflow/lite/c/builtin_op_data.h"
#include "tensorflow/lite/c/c_api_internal.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tensorflow/lite/kernels/op_macros.h"
#include <farmhash.h>
namespace tflite {
namespace ops {