-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working Jai compiler on MacOS and fallback for ARM CPUs
- Loading branch information
1 parent
f3ab856
commit 1f1cf2f
Showing
6 changed files
with
84 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
if(NOT IOS) | ||
if(WIN32) | ||
set(JAI_COMPILER_EXE "jai.exe") | ||
elseif(APPLE) | ||
set(JAI_COMPILER_EXE "jai-macos") | ||
else() | ||
set(JAI_COMPILER_EXE "jai-linux") | ||
endif() | ||
|
||
find_program(JAI_COMPILER | ||
NAMES ${JAI_COMPILER_EXE} | ||
HINTS ${CMAKE_SOURCE_DIR}/../jai/bin ${CMAKE_SOURCE_DIR}/../../Research/jai/bin | ||
) | ||
message(STATUS "Jai compiler: ${JAI_COMPILER}") | ||
else() | ||
message(STATUS "Skipping Jai checks on this platform") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
struct Krusher_Lofi_Resample_State | ||
{ | ||
double upsample_overshoot = 0.0; | ||
double downsample_overshoot = 0.0; | ||
}; | ||
|
||
inline void krusher_init_lofi_resample (Krusher_Lofi_Resample_State* state) | ||
{ | ||
state->upsample_overshoot = 0.0; | ||
state->downsample_overshoot = 0.0; | ||
} | ||
|
||
inline void krusher_process_lofi_resample (float** source_buffer, | ||
float** dest_buffer, | ||
int num_channels, | ||
int num_samples_source, | ||
int num_samples_dest, | ||
double resample_factor, | ||
double& overshoot_samples) | ||
{ | ||
// simple S&H lofi resampler | ||
for (int channel = 0; channel < num_channels; ++channel) | ||
{ | ||
const auto* source_data = source_buffer[channel]; | ||
auto* dest_data = dest_buffer[channel]; | ||
|
||
for (int i = 0; i < num_samples_dest; ++i) | ||
{ | ||
const auto grab_index = (int) ((double) i * resample_factor + overshoot_samples); | ||
dest_data[i] = source_data[std::min (grab_index, num_samples_source - 1)]; | ||
} | ||
} | ||
|
||
overshoot_samples = (double) num_samples_dest * resample_factor - std::floor ((double) num_samples_dest * resample_factor); | ||
} | ||
|
||
inline void krusher_process_lofi_downsample ([[maybe_unused]] void* ctx, | ||
Krusher_Lofi_Resample_State* state, | ||
float** buffer, | ||
int num_channels, | ||
int num_samples, | ||
double resample_factor) | ||
{ | ||
const auto ds_buffer_size = (int) std::ceil ((double) num_samples / resample_factor); | ||
|
||
auto* temp_data = (float*) alloca (2 * (size_t) ds_buffer_size * sizeof (float)); | ||
float* ds_buffer[2] = { temp_data, temp_data + ds_buffer_size }; | ||
|
||
krusher_process_lofi_resample (buffer, ds_buffer, num_channels, num_samples, ds_buffer_size, resample_factor, state->downsample_overshoot); | ||
krusher_process_lofi_resample (ds_buffer, buffer, num_channels, ds_buffer_size, num_samples, 1.0 / resample_factor, state->upsample_overshoot); | ||
} |