Skip to content

Commit

Permalink
Add newHW macros
Browse files Browse the repository at this point in the history
  • Loading branch information
rsp4jack committed Nov 3, 2024
1 parent 9ac9e1c commit 65f5eb8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ option(BUILD_SONIVOX_SHARED "Build the shared library" TRUE)
option(BUILD_EXAMPLE "Build and install the example program" TRUE)
option(BUILD_TESTING "Build the unit tests" TRUE)
option(CMAKE_POSITION_INDEPENDENT_CODE "Whether to create position-independent targets" TRUE)
option(USE_NEW_HOST_WRAPPER "Use the new host wrapper" TRUE)
option(NEW_HOST_WRAPPER "Use the new host wrapper" TRUE)
set(MAX_VOICES 64 CACHE STRING "Maximum number of voices")

include(CMakeDependentOption)
Expand Down Expand Up @@ -112,7 +112,7 @@ list(APPEND SOURCES
arm-wt-22k/lib_src/wt_200k_G.c
)

if (USE_NEW_HOST_WRAPPER)
if (NEW_HOST_WRAPPER)
list(APPEND SOURCES arm-wt-22k/src/hostmm_ng.c)
else()
list(APPEND SOURCES arm-wt-22k/host_src/eas_hostmm.c)
Expand Down Expand Up @@ -146,6 +146,13 @@ target_compile_definitions( sonivox-objects PRIVATE
#JET_INTERFACE
)

include(TestBigEndian)
test_big_endian(BIG_ENDIAN)

if (BIG_ENDIAN)
target_compile_definitions( sonivox-objects PRIVATE EAS_BIG_ENDIAN )
endif()

if (USE_16BITS_SAMPLES)
target_compile_definitions( sonivox-objects PRIVATE
_16_BIT_SAMPLES
Expand Down
2 changes: 2 additions & 0 deletions arm-wt-22k/host_src/eas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extern "C" {
#define MAKE_LIB_VERSION(a,b,c,d) (((((((EAS_U32) a <<8) | (EAS_U32) b) << 8) | (EAS_U32) c) << 8) | (EAS_U32) d)
#define LIB_VERSION MAKE_LIB_VERSION(@PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,@PROJECT_VERSION_TWEAK@)

#cmakedefine NEW_HOST_WRAPPER

typedef struct
{
EAS_U32 libVersion;
Expand Down
26 changes: 8 additions & 18 deletions arm-wt-22k/src/hostmm_ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,12 @@
#define bswap32 __builtin_bswap32
#endif

// https://stackoverflow.com/a/2103095
// CC BY-SA 3.0
enum {
O32_LITTLE_ENDIAN = 0x03020100ul,
O32_BIG_ENDIAN = 0x00010203ul,
O32_PDP_ENDIAN = 0x01000302ul, /* DEC PDP-11 (aka ENDIAN_LITTLE_WORD) */
O32_HONEYWELL_ENDIAN = 0x02030001ul /* Honeywell 316 (aka ENDIAN_BIG_WORD) */
};

static const union {
uint8_t bytes[4];
uint32_t value;
} o32_host_order = { { 0, 1, 2, 3 } };

#define O32_HOST_ORDER (o32_host_order.value)
// --- end
const EAS_BOOL O32_BIG_ENDIAN =
#ifdef EAS_BIG_ENDIAN
EAS_TRUE;
#else
EAS_FALSE;
#endif

typedef struct eas_hw_file_tag {
void* handle;
Expand Down Expand Up @@ -157,7 +147,7 @@ EAS_RESULT EAS_HWGetWord(EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, vo
return result;
}

if (msbFirst ^ (O32_HOST_ORDER == O32_BIG_ENDIAN)) {
if (msbFirst ^ O32_BIG_ENDIAN) {
*((EAS_U16*)p) = bswap16(word);
} else {
*((EAS_U16*)p) = word;
Expand All @@ -175,7 +165,7 @@ EAS_RESULT EAS_HWGetDWord(EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, v
return result;
}

if (msbFirst ^ (O32_HOST_ORDER == O32_BIG_ENDIAN)) {
if (msbFirst ^ O32_BIG_ENDIAN) {
*((EAS_U32*)p) = bswap32(dword);
} else {
*((EAS_U32*)p) = dword;
Expand Down
12 changes: 8 additions & 4 deletions example/sonivoxrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ int initializeLibrary(void)
goto cleanup;
}

// mDLSFile.readAt = Read;
// mDLSFile.size = Size;
#ifndef NEW_HOST_WRAPPER
mDLSFile.readAt = Read;
mDLSFile.size = Size;
#endif

result = EAS_LoadDLSCollection(mEASDataHandle, NULL, &mDLSFile);
fclose(mDLSFile.handle);
Expand Down Expand Up @@ -220,8 +222,10 @@ int renderFile(const char *fileName)
return ok;
}

// mEasFile.readAt = Read;
// mEasFile.size = Size;
#ifndef NEW_HOST_WRAPPER
mEasFile.readAt = Read;
mEasFile.size = Size;
#endif

EAS_RESULT result = EAS_OpenFile(mEASDataHandle, &mEasFile, &mEASStreamHandle);
if (result != EAS_SUCCESS) {
Expand Down

0 comments on commit 65f5eb8

Please sign in to comment.