Skip to content

Commit

Permalink
Use float/fixed based on the platform used.
Browse files Browse the repository at this point in the history
  • Loading branch information
DatanoiseTV committed Aug 19, 2024
1 parent 4bb4dd3 commit 61d8c43
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
48 changes: 30 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,35 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_D
add_subdirectory(lib/audio)
add_subdirectory(lib/oled)

message("CMAKE_HOST_SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
# Set the real flag based on the PICO_PLATFORM variable
if (DEFINED PICO_PLATFORM AND PICO_PLATFORM STREQUAL "rp2350-arm-s")
set(REAL_TYPE_FLAG "float")
message("Using float for real type")
else()
set(REAL_TYPE_FLAG "fixed")
message("Using fixed for real type")
endif()

set(VULT_EXAMPLE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/vult/examples")

# Generate Vult C++ code from Vult Code every time
set(VULT_EXAMPLE_PATH "${CMAKE_CURRENT_LIST_DIR}/lib/vult/examples")
add_custom_command(
OUTPUT ALL ${CMAKE_CURRENT_BINARY_DIR}/vult.cpp
COMMAND vultc ${CMAKE_CURRENT_LIST_DIR}/vultsrc/dsp.vult
-i ${VULT_EXAMPLE_PATH}/osc
-i ${VULT_EXAMPLE_PATH}/util
-i ${VULT_EXAMPLE_PATH}/filters
-i ${VULT_EXAMPLE_PATH}/env
-i ${VULT_EXAMPLE_PATH}/midi
-i ${VULT_EXAMPLE_PATH}/effects
-i ${VULT_EXAMPLE_PATH}/units
-ccode
-real float
-samplerate 44140
-o vult
COMMENT "Transcompiling Vult DSP Code to C++."
OUTPUT ALL ${CMAKE_CURRENT_BINARY_DIR}/vult.cpp
COMMAND vultc ${CMAKE_CURRENT_LIST_DIR}/vultsrc/dsp.vult
-i ${VULT_EXAMPLE_PATH}/osc
-i ${VULT_EXAMPLE_PATH}/util
-i ${VULT_EXAMPLE_PATH}/filters
-i ${VULT_EXAMPLE_PATH}/env
-i ${VULT_EXAMPLE_PATH}/midi
-i ${VULT_EXAMPLE_PATH}/effects
-i ${VULT_EXAMPLE_PATH}/units
-ccode
-real ${REAL_TYPE_FLAG}
-samplerate 44100
-o vult
COMMENT "Transcompiling Vult DSP Code to C++."
)


if (NOT FREERTOS_KERNEL_PATH AND NOT DEFINED ENV{FREERTOS_KERNEL_PATH})
message("Skipping FreeRTOS examples as FREERTOS_KERNEL_PATH not defined")
return()
Expand Down Expand Up @@ -115,9 +122,14 @@ endforeach()

add_compile_options("-Wall" "-Wredundant-decls")

# compile the following thins only if rp2040 is used
if (PICO_PLATFORM STREQUAL "rp2040")
pico_define_boot_stage2(slower_boot2 ${PICO_DEFAULT_BOOT_STAGE2_FILE})
target_compile_definitions(slower_boot2 PRIVATE PICO_FLASH_SPI_CLKDIV=4)

pico_set_boot_stage2(main slower_boot2)
else()
message("Skipping slower_boot2 as PICO_PLATFORM is not rp2040")
endif()

pico_add_extra_outputs(main)
9 changes: 9 additions & 0 deletions include/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

#include "vultin.h"

#if PICO_RP2350
#define VULT_DATA_TYPE float
#define VULT_DATA_CONVERT(x) float_to_int32(x)
#else
#define VULT_DATA_TYPE fix16_t
#define VULT_DATA_CONVERT(x) fix16_to_int32(x)
#endif


static inline int32_t fix16_to_int32(fix16_t x)
{
fix16_t out;
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,18 @@ extern "C"
// smp should be the output of your processing code.
// In case of the Vult Example, this is Dsp_process(ctx);
Dsp_process(ctx, cv0, cv1, cv2, cv3);
VULT_DATA_TYPE left_out = Dsp_process_ret_0(ctx);
VULT_DATA_TYPE right_out = Dsp_process_ret_1(ctx);
samples[i * 2 + 0] = VULT_DATA_CONVERT(left_out); // LEFT
samples[i * 2 + 1] = VULT_DATA_CONVERT(right_out); // RIGHT

/*
Dsp_process(ctx, cv0, cv1, cv2, cv3);
float left_out = Dsp_process_ret_0(ctx);
float right_out = Dsp_process_ret_1(ctx);
samples[i * 2 + 0] = float_to_int32(left_out); // LEFT
samples[i * 2 + 1] = float_to_int32(right_out); // RIGHT
*/
}

dsp_end = to_us_since_boot(get_absolute_time());
Expand Down
4 changes: 4 additions & 0 deletions src/picoadk_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ void picoadk_init()
{
// Overclock the CPU to 402 MHz.

#if PICO_RP2040
vreg_set_voltage(VREG_VOLTAGE_1_30);
sleep_ms(1);
set_sys_clock_khz(402000, true);
#else
#warning "No overclocking will performed, as this is untested on plaftorms other than the RP2040."
#endif

// Initialize TinyUSB
board_init();
Expand Down

0 comments on commit 61d8c43

Please sign in to comment.