OGG Link, Signed 16-bit

- Added linking to OGG library in CMakeLists
- Added Signed 16-bit output for files ending in ".s16"
- Changed 2047 to 2048 in flac conversions
This commit is contained in:
montoyatim01 2025-04-28 20:13:50 -07:00
parent 6fe8f43f8d
commit 80a352ac24
4 changed files with 56 additions and 13 deletions

View file

@ -97,6 +97,15 @@ else()
set(LIBFLAC_LIBRARIES "" CACHE STRING "manual FLAC path")
set(LIBFLAC_INCLUDE_DIRS "" CACHE STRING "manual FLAC includepath")
endif()
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBOGG ogg IMPORTED_TARGET)
if(LIBOGG_LINK_LIBRARIES)
set(LIBOGG_LIBRARIES "${LIBOGG_LINK_LIBRARIES}")
endif()
else()
set(LIBOGG_LIBRARIES "" CACHE STRING "manual libogg path")
set(LIBOGG_INCLUDE_DIRS "" CACHE STRING "manual libogg includepath")
endif()
if(MSVC)
set(THREADS_PTHREADS_LIBRARY "" CACHE STRING "manual pthread-win32 path")
@ -115,6 +124,9 @@ endif()
if(PKG_CONFIG_FOUND AND NOT LIBFLAC_FOUND)
message(FATAL_ERROR "LibFLAC required to compile hsdaoh")
endif()
if(PKG_CONFIG_FOUND AND NOT LIBOGG_FOUND)
message(FATAL_ERROR "LibOgg required to compile hsdaoh")
endif()
if(NOT THREADS_FOUND)
message(FATAL_ERROR "pthreads(-win32) required to compile hsdaoh")
endif()
@ -186,6 +198,14 @@ FOREACH(lib ${LIBFLAC_LIBRARY_DIRS})
LIST(APPEND hsdaoh_PC_LIBS "-L${lib}")
ENDFOREACH(lib)
FOREACH(inc ${LIBOGG_INCLUDEDIR})
LIST(APPEND hsdaoh_PC_CFLAGS "-I${inc}")
ENDFOREACH(inc)
FOREACH(lib ${LIBOGG_LIBRARY_DIRS})
LIST(APPEND hsdaoh_PC_LIBS "-L${lib}")
ENDFOREACH(lib)
# use space-separation format for the pc file
STRING(REPLACE ";" " " hsdaoh_PC_CFLAGS "${hsdaoh_PC_CFLAGS}")
STRING(REPLACE ";" " " hsdaoh_PC_LIBS "${hsdaoh_PC_LIBS}")

View file

@ -89,6 +89,7 @@ set(INSTALL_TARGETS hsdaoh hsdaoh_static hsdaoh_file hsdaoh_tcp hsdaoh_test)
target_link_libraries(hsdaoh_file hsdaoh
${LIBFLAC_LIBRARIES}
${LIBOGG_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(hsdaoh_tcp hsdaoh

View file

@ -69,10 +69,15 @@ void hsdaoh_unpack_pio_12bit(hsdaoh_dev_t *dev, hsdaoh_data_info_t *data_info)
unsigned int j = 0;
for (unsigned int i = 0; i < inlen; i += 3) {
out[j++] = (in[i+2] & 0xf000) >> 4 | (in[i+1] & 0xf000) >> 8 | (in[i] >> 12);
out[j++] = in[i ] & 0x0fff;
out[j++] = in[i+1] & 0x0fff;
out[j++] = in[i+2] & 0x0fff;
uint16_t sample1 = (in[i+2] & 0xf000) >> 4 | (in[i+1] & 0xf000) >> 8 | (in[i] >> 12);
uint16_t sample2 = in[i ] & 0x0fff;
uint16_t sample3 = in[i+1] & 0x0fff;
uint16_t sample4 = in[i+2] & 0x0fff;
out[j++] = ((bool *)(data_info->ctx))[0] ? (int16_t)((sample1 - 2048) << 4) : sample1;
out[j++] = ((bool *)(data_info->ctx))[0] ? (int16_t)((sample2 - 2048) << 4) : sample2;
out[j++] = ((bool *)(data_info->ctx))[0] ? (int16_t)((sample3 - 2048) << 4) : sample3;
out[j++] = ((bool *)(data_info->ctx))[0] ? (int16_t)((sample4 - 2048) << 4) : sample4;
}
if (dev->output_float) {
@ -107,8 +112,11 @@ void hsdaoh_unpack_pio_12bit_dual(hsdaoh_dev_t *dev, hsdaoh_data_info_t *data_in
}
for (i = 0; i < j; i++) {
out16_1[i] = (out[i] >> 12) & 0x0fff;
out16_2[i] = out[i] & 0x0fff;
uint16_t sample1 = (out[i] >> 12) & 0x0fff;
uint16_t sample2 = out[i] & 0x0fff;
out16_1[i] = ((bool *)(data_info->ctx))[0] ? (int16_t)((sample1 - 2048) << 4) : sample1;
out16_2[i] = ((bool *)(data_info->ctx))[1] ? (int16_t)((sample2 - 2048) << 4) : sample2;
}
data_info->bits_per_samp = 12;
@ -243,10 +251,15 @@ void hsdaoh_unpack_fpga_12bit_dual(hsdaoh_dev_t *dev, hsdaoh_data_info_t *data_i
/* extract packed 2x12 bit samples */
for (int i = 0; i < inlen; i += 3) {
uint16_t lsbs = in[i+2];
out16_1[j] = ((in[i+0] & 0xff00) >> 4) | ((lsbs >> 0) & 0xf);
out16_2[j++] = ((in[i+0] & 0x00ff) << 4) | ((lsbs >> 4) & 0xf);
out16_1[j] = ((in[i+1] & 0xff00) >> 4) | ((lsbs >> 8) & 0xf);
out16_2[j++] = ((in[i+1] & 0x00ff) << 4) | ((lsbs >> 12) & 0xf);
uint16_t sample1 = ((in[i+0] & 0xff00) >> 4) | ((lsbs >> 0) & 0xf);
uint16_t sample2 = ((in[i+0] & 0x00ff) << 4) | ((lsbs >> 4) & 0xf);
uint16_t sample3 = ((in[i+1] & 0xff00) >> 4) | ((lsbs >> 8) & 0xf);
uint16_t sample4 = ((in[i+1] & 0x00ff) << 4) | ((lsbs >> 12) & 0xf);
out16_1[j] = ((bool *)(data_info->ctx))[0] ? (int16_t)((sample1 - 2048) << 4) : sample1;
out16_2[j++] = ((bool *)(data_info->ctx))[1] ? (int16_t)((sample2 - 2048) << 4) : sample2;
out16_1[j] = ((bool *)(data_info->ctx))[0] ? (int16_t)((sample3 - 2048) << 4) : sample3;
out16_2[j++] = ((bool *)(data_info->ctx))[1] ? (int16_t)((sample4 - 2048) << 4) : sample4;
}
if (dev->output_float) {

View file

@ -48,6 +48,7 @@ static uint32_t flac_level = 5;
static uint32_t flac_nthreads = 4;
typedef struct file_ctx {
bool use_signed[FD_NUMS];
FILE *files[FD_NUMS];
bool use_flac[FD_NUMS];
FLAC__StreamEncoder *encoder[FD_NUMS];
@ -168,7 +169,7 @@ static void hsdaoh_callback(hsdaoh_data_info_t *data_info)
FLAC__int32 test[len/sizeof(uint16_t)];
uint16_t *dat = (uint16_t *)data_info->buf;
for (int i = 0; i < len/sizeof(uint16_t); i++) {
test[i] = dat[i] - 2047;
test[i] = dat[i] - 2048;
}
ok = FLAC__stream_encoder_process_interleaved(f->encoder[data_info->stream_id], test, len/sizeof(uint16_t));
@ -300,13 +301,21 @@ int main(int argc, char **argv)
}
char *dot = strrchr(filenames[i], '.');
if (dot && !strcmp(dot, ".flac"))
if (dot && !strcmp(dot, ".flac")) {
f.use_flac[i] = true;
else
f.use_signed[i] = false;
} else if (dot && !strcmp(dot, ".s16") && i < 2) {
f.use_flac[i] = false;
f.use_signed[i] = true;
} else {
f.use_flac[i] = false;
f.use_signed[i] = false;
}
if (f.use_flac[i])
printf("File %d is flac!\n", i);
if (f.use_signed[i])
printf("File %d is signed!\n", i);
}
}