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

Switch extensions from .c to .cc and fix compile time errors #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 16 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,30 @@
"kiss_fft_int16.cc",
"fft.cc",
"fft_util.cc",
"filterbank.c",
"filterbank_util.c",
"frontend.c",
"frontend_util.c",
"log_lut.c",
"log_scale.c",
"log_scale_util.c",
"noise_reduction.c",
"noise_reduction_util.c",
"pcan_gain_control.c",
"pcan_gain_control_util.c",
"window.c",
"window_util.c",
"filterbank.cc",
"filterbank_util.cc",
"frontend.cc",
"frontend_util.cc",
"log_lut.cc",
"log_scale.cc",
"log_scale_util.cc",
"noise_reduction.cc",
"noise_reduction_util.cc",
"pcan_gain_control.cc",
"pcan_gain_control_util.cc",
"window.cc",
"window_util.cc",
]
)
sources.append(_KISSFFT_DIR / "kiss_fft.c")
sources.append(_KISSFFT_DIR / "tools" / "kiss_fftr.c")
sources.append(_KISSFFT_DIR / "kiss_fft.cc")
sources.append(_KISSFFT_DIR / "tools" / "kiss_fftr.cc")

flags = ["-DFIXED_POINT=16"]
ext_modules = [
Pybind11Extension(
name="micro_features_cpp",
language="c++",
cxx_std=17,
extra_compile_args=flags,
sources=sorted([str(p) for p in sources] + [str(_DIR / "python.cpp")]),
define_macros=[("VERSION_INFO", __version__)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ int FilterbankPopulateState(const struct FilterbankConfig* config,
: kFilterbankIndexAlignment / sizeof(int16_t));

state->channel_frequency_starts =
malloc(num_channels_plus_1 * sizeof(*state->channel_frequency_starts));
(int16_t*)malloc(num_channels_plus_1 * sizeof(*state->channel_frequency_starts));
state->channel_weight_starts =
malloc(num_channels_plus_1 * sizeof(*state->channel_weight_starts));
(int16_t*)malloc(num_channels_plus_1 * sizeof(*state->channel_weight_starts));
state->channel_widths =
malloc(num_channels_plus_1 * sizeof(*state->channel_widths));
state->work = malloc(num_channels_plus_1 * sizeof(*state->work));
(int16_t*)malloc(num_channels_plus_1 * sizeof(*state->channel_widths));
state->work = (uint64_t*)malloc(num_channels_plus_1 * sizeof(*state->work));

float* center_mel_freqs =
malloc(num_channels_plus_1 * sizeof(*center_mel_freqs));
(float*)malloc(num_channels_plus_1 * sizeof(*center_mel_freqs));
int16_t* actual_channel_starts =
malloc(num_channels_plus_1 * sizeof(*actual_channel_starts));
(int16_t*)malloc(num_channels_plus_1 * sizeof(*actual_channel_starts));
int16_t* actual_channel_widths =
malloc(num_channels_plus_1 * sizeof(*actual_channel_widths));
(int16_t*)malloc(num_channels_plus_1 * sizeof(*actual_channel_widths));

if (state->channel_frequency_starts == NULL ||
state->channel_weight_starts == NULL || state->channel_widths == NULL ||
Expand Down Expand Up @@ -160,8 +160,8 @@ int FilterbankPopulateState(const struct FilterbankConfig* config,
// Allocate the two arrays to store the weights - weight_index_start contains
// the index of what would be the next set of weights that we would need to
// add, so that's how many weights we need to allocate.
state->weights = calloc(weight_index_start, sizeof(*state->weights));
state->unweights = calloc(weight_index_start, sizeof(*state->unweights));
state->weights = (int16_t*)calloc(weight_index_start, sizeof(*state->weights));
state->unweights = (int16_t*)calloc(weight_index_start, sizeof(*state->unweights));

// If the alloc failed, we also need to nuke the arrays.
if (state->weights == NULL || state->unweights == NULL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define FIXED_POINT 16
namespace kissfft_fixed16 {
#include "kiss_fft.c"
#include "tools/kiss_fftr.c"
#include "kiss_fft.cc"
#include "tools/kiss_fftr.cc"
} // namespace kissfft_fixed16
#undef FIXED_POINT
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int NoiseReductionPopulateState(const struct NoiseReductionConfig* config,
state->min_signal_remaining =
config->min_signal_remaining * (1 << kNoiseReductionBits);
state->num_channels = num_channels;
state->estimate = calloc(state->num_channels, sizeof(*state->estimate));
state->estimate = (uint32_t*)calloc(state->num_channels, sizeof(*state->estimate));
if (state->estimate == NULL) {
fprintf(stderr, "Failed to alloc estimate buffer\n");
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int PcanGainControlPopulateState(const struct PcanGainControlConfig* config,
}
state->noise_estimate = noise_estimate;
state->num_channels = num_channels;
state->gain_lut = malloc(kWideDynamicFunctionLUTSize * sizeof(int16_t));
state->gain_lut = (int16_t*)malloc(kWideDynamicFunctionLUTSize * sizeof(int16_t));
if (state->gain_lut == NULL) {
fprintf(stderr, "Failed to allocate gain LUT\n");
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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 = (int16_t*)malloc(state->size * sizeof(*state->coefficients));
if (state->coefficients == NULL) {
fprintf(stderr, "Failed to allocate window coefficients\n");
return 0;
Expand All @@ -51,13 +51,13 @@ int WindowPopulateState(const struct WindowConfig* config,
}

state->input_used = 0;
state->input = malloc(state->size * sizeof(*state->input));
state->input = (int16_t*)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 = (int16_t*)malloc(state->size * sizeof(*state->output));
if (state->output == NULL) {
fprintf(stderr, "Failed to allocate window output\n");
return 0;
Expand Down