Skip to content

Commit

Permalink
Updates for Krusher with Jai on ARM (#336)
Browse files Browse the repository at this point in the history
* Updateds for Jai on ARM

* Apply clang-format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jatinchowdhury18 and github-actions[bot] authored Nov 17, 2023
1 parent e97727b commit bacc53a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,3 @@ target_link_libraries(BYOD PRIVATE rnn_accelerated)
if (MSVC)
target_compile_options(BYOD PRIVATE /bigobj)
endif ()

# pre-compiled header
target_precompile_headers(BYOD PRIVATE pch.h)
9 changes: 6 additions & 3 deletions src/jai/SharedJaiContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

#include <juce_core/juce_core.h>

struct jai_Context;
namespace jai
{
struct Context;
}
struct JaiContextWrapper
{
JaiContextWrapper();
~JaiContextWrapper();

operator jai_Context*() { return internal; }; // NOLINT
operator jai::Context*() { return internal; }; // NOLINT

private:
jai_Context* internal = nullptr;
jai::Context* internal = nullptr;
};

using SharedJaiContext = juce::SharedResourcePointer<JaiContextWrapper>;
46 changes: 39 additions & 7 deletions src/jai/build.jai
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#import "Basic";
#import "Compiler";
#import "generate_c_header";

#run build();
#import "generate_cpp_header";

SRC_FILES :: string.[
"krusher/lofi_downsampler.jai",
"krusher/bit_reduction.jai"
];

build :: () {
build :: (building_arm64 := false, lib_postfix := "") {
header_info : Header_Info;
header_info.jai_type_prefix = "jai_";

w := compiler_create_workspace();

target_options := get_build_options(w);
target_options.output_executable_name = "byod_jai_lib";
target_options.output_executable_name = tprint("%0%", "byod_jai_lib", lib_postfix);
target_options.output_type = .STATIC_LIBRARY; // specifies output to be a static library
target_options.backend = .LLVM;
target_options.text_output_flags = 1;
set_optimization(*target_options, .OPTIMIZED);
if building_arm64 {
target_options.cpu_target = .ARM64;
target_options.llvm_options.target_system_triple = "arm64-apple-darwin20.1.0";
}

set_build_options(target_options, w);

Expand All @@ -38,7 +39,38 @@ build :: () {
}
compiler_end_intercept(w);

generate_header(*header_info, "byod_jai_lib.h");
if ! building_arm64 {
generate_header(*header_info, "byod_jai_lib.h");
}

set_build_options_dc(.{do_output=false}); // No executable for this workspace.
}

#if OS == .MACOS {
#run {
print("Building universal binary on MacOS...\n");

arm_lib := "byod_jai_lib_arm64.a";
x64_lib := "byod_jai_lib_x64.a";

File.file_delete(arm_lib);
File.file_delete(x64_lib);

build(false, "_x64");
build(true, "_arm64");

// For some reason we need to wait a second for the ARM build to finish?
// sleep_milliseconds(500);

lipo_command := string.["lipo", "-create", "-output", "byod_jai_lib.a", x64_lib, arm_lib];
Process.run_command(..lipo_command);

lipo_check_command := string.["lipo", "-info", "byod_jai_lib.a"];
Process.run_command(..lipo_check_command);
}

Process :: #import "Process";
File :: #import "File";
} else {
#run build();
}
4 changes: 3 additions & 1 deletion src/processors/modulation/CleanDelayType.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <pch.h>

/*
This class wraps chowdsp::DelayLine so it has an equivalent
interface to chowdsp::BBBDelayWrapper
Expand All @@ -24,6 +26,6 @@ struct CleanDelayType
inline void pushSample (int channel, float sample) { delay.pushSample (channel, sample); }
inline float popSample (int channel) { return lpf.processSample (channel, delay.popSample (channel)); }

chowdsp::SVFLowpass<float> lpf;
chowdsp::SVFLowpass<float> lpf {};
chowdsp::DelayLine<float, chowdsp::DelayLineInterpolationTypes::Lagrange5th> delay { 1 << 18 };
};
6 changes: 3 additions & 3 deletions src/processors/other/krusher/Krusher.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "processors/BaseProcessor.h"

#define KRUSHER_USE_JAI_IMPL ! JUCE_ARM&& BYOD_BUILDING_JAI_MODULES
#define KRUSHER_USE_JAI_IMPL ! JUCE_IOS&& BYOD_BUILDING_JAI_MODULES

#if KRUSHER_USE_JAI_IMPL
#include "jai/byod_jai_lib.h"
Expand Down Expand Up @@ -36,8 +36,8 @@ class Krusher : public BaseProcessor

#if KRUSHER_USE_JAI_IMPL
SharedJaiContext jai_context;
jai_Krusher_Lofi_Resample_State resample_state {};
std::array<jai_Krusher_Bit_Reducer_Filter_State, 2> brFilterStates {};
jai::Krusher_Lofi_Resample_State resample_state {};
std::array<jai::Krusher_Bit_Reducer_Filter_State, 2> brFilterStates {};
#else
std::unique_ptr<chowdsp::NullType> jai_context;
Krusher_Lofi_Resample_State resample_state {};
Expand Down
1 change: 1 addition & 0 deletions src/state/presets/PresetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "PresetsServerJobPool.h"
#include "PresetsServerSyncManager.h"
#include "PresetsServerUserManager.h"
#include <pch.h>

namespace PresetConstants
{
Expand Down

0 comments on commit bacc53a

Please sign in to comment.