Skip to content

Commit

Permalink
Add optional debug log thing for buffer over/underruns.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Jan 11, 2025
1 parent 7f0ef83 commit 64603ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option(BUILD_EXAMPLES "Build the example applications" ON)
option(BUILD_TESTER "Build the tester application" ON)
option(BUILD_SIMD "Build with SIMD as minimum requirement" ON)
option(BUILD_DOCS "Build the doxygen documentation files" ON)
option(BUILD_DEBUG_LOG "Build with debug logging output" OFF)
set(BUILD_SIMD_VERSION "SSE" CACHE STRING "Which SIMD version to require")

## Generate version
Expand Down Expand Up @@ -150,6 +151,9 @@ target_include_directories(mixed PRIVATE "src/" "libsamplerate/" "spiralfft/")
set_property(TARGET mixed PROPERTY C_STANDARD 99)
set_property(TARGET mixed PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(mixed PRIVATE MIXED_BUILD=1 MIXED_VERSION="${MIXED_VERSION_STRING}")
if(BUILD_DEBUG_LOG)
target_compile_definitions(mixed PRIVATE MIXED_DEBUG=1)
endif()
target_compile_options(mixed PRIVATE ${COMPILATION_FLAGS} -W -Wall -Wextra -Wpedantic -Wno-ignored-attributes -Wno-enum-conversion)

find_library(DL_LIB dl)
Expand Down
4 changes: 4 additions & 0 deletions src/bip.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static inline int bip_request_write(uint32_t *off, uint32_t *size, struct bip *b
}else{ // Read has not done anything yet, no space!
*size = 0;
*off = 0;
debug_log("%p Overrun", buffer);
return 0;
}
}else if(write < read){
Expand All @@ -38,6 +39,7 @@ static inline int bip_request_write(uint32_t *off, uint32_t *size, struct bip *b
}else{
*size = 0;
*off = 0;
debug_log("%p Overrun", buffer);
return 0;
}
return 1;
Expand Down Expand Up @@ -77,6 +79,7 @@ static inline int bip_request_read(uint32_t *off, uint32_t *size, struct bip *bu
}else{ // Write has not done anything yet, no space!
*size = 0;
*off = 0;
debug_log("%p Underrun", buffer);
return 0;
}
}else if(read < write){
Expand All @@ -85,6 +88,7 @@ static inline int bip_request_read(uint32_t *off, uint32_t *size, struct bip *bu
}else{
*size = 0;
*off = 0;
debug_log("%p Underrun", buffer);
return 0;
}
return 1;
Expand Down
6 changes: 6 additions & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#define IGNORE(...) __ignore(0, __VA_ARGS__)
static inline void __ignore(char _, ...){(void)_;}

#ifdef MIXED_DEBUG
#define debug_log(...) {fprintf(stderr, "[libmixed] "); fprintf(stderr, __VA_ARGS__);}
#else
#define debug_log(...)
#endif

#if defined(__GNUC__) && !defined(__WIN32__)
#if defined(__x86_64__)
#define VECTORIZE __attribute__((target_clones("avx2","avx","sse4.1","default")))
Expand Down

0 comments on commit 64603ff

Please sign in to comment.