diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..0899f0ed --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,49 @@ +# +# Initial CMake and project setup +# + +CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) +SET(PROJECT_NAME sphinxbase) +PROJECT(${PROJECT_NAME}) + +SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/build-data) +set(CMAKE_MACOSX_RPATH FALSE) + +# +# Setup compiler flags +# + +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE CACHE Release FORCE) +endif() + +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=gnu11 -O0 -fprofile-arcs -ftest-coverage") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=gnu11 -O3") + +# +# Final project settings +# +configure_file("${CMAKE_SOURCE_DIR}/include/sphinx_config.h.in" "${CMAKE_SOURCE_DIR}/include/sphinx_config.h") +INCLUDE_DIRECTORIES(include) +ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(test EXCLUDE_FROM_ALL) + +ADD_LIBRARY(${PROJECT_NAME}_static STATIC + $ + $ + $ + $ + $ + ) + +ADD_LIBRARY(${PROJECT_NAME} SHARED + $ + $ + $ + $ + $ +) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBS}) diff --git a/cmake/FindOSS.cmake b/cmake/FindOSS.cmake new file mode 100644 index 00000000..7470e7d6 --- /dev/null +++ b/cmake/FindOSS.cmake @@ -0,0 +1,51 @@ +# - Find Oss +# Find Oss headers and libraries. +# +# OSS_INCLUDE_DIR - where to find soundcard.h, etc. +# OSS_FOUND - True if Oss found. + +# OSS is not for APPLE or WINDOWS + +IF(APPLE OR WIN32) + RETURN() +ENDIF() + +FIND_PATH(LINUX_OSS_INCLUDE_DIR "linux/soundcard.h" + "/usr/include" "/usr/local/include" +) + +FIND_PATH(SYS_OSS_INCLUDE_DIR "sys/soundcard.h" + "/usr/include" "/usr/local/include" +) + +FIND_PATH(MACHINE_OSS_INCLUDE_DIR "machine/soundcard.h" + "/usr/include" "/usr/local/include" +) + +SET(OSS_FOUND FALSE) + +IF(LINUX_OSS_INCLUDE_DIR) + SET(OSS_FOUND TRUE) + SET(OSS_INCLUDE_DIR ${LINUX_OSS_INCLUDE_DIR}) + SET(HAVE_LINUX_SOUNDCARD_H 1) +ENDIF() + +IF(SYS_OSS_INCLUDE_DIR) + SET(OSS_FOUND TRUE) + SET(OSS_INCLUDE_DIR ${SYS_OSS_INCLUDE_DIR}) + SET(HAVE_SYS_SOUNDCARD_H 1) +ENDIF() + +IF(MACHINE_OSS_INCLUDE_DIR) + SET(OSS_FOUND TRUE) + SET(OSS_INCLUDE_DIR ${MACHINE_OSS_INCLUDE_DIR}) + SET(HAVE_MACHINE_SOUNDCARD_H 1) +ENDIF() + +MARK_AS_ADVANCED ( + OSS_FOUND + OSS_INCLUDE_DIR + LINUX_OSS_INCLUDE_DIR + SYS_OSS_INCLUDE_DIR + MACHINE_OSS_INCLUDE_DIR +) diff --git a/cmake/FindPulseAudio.cmake b/cmake/FindPulseAudio.cmake new file mode 100644 index 00000000..ff9c22e7 --- /dev/null +++ b/cmake/FindPulseAudio.cmake @@ -0,0 +1,43 @@ +# - Find PulseAudio includes and libraries +# +# PULSEAUDIO_FOUND - True if PULSEAUDIO_INCLUDE_DIR & +# PULSEAUDIO_LIBRARY are found +# PULSEAUDIO_LIBRARIES - Set when PULSEAUDIO_LIBRARY is found +# PULSEAUDIO_INCLUDE_DIRS - Set when PULSEAUDIO_INCLUDE_DIR is found +# +# PULSEAUDIO_INCLUDE_DIR - where to find pulse/pulseaudio.h, etc. +# PULSEAUDIO_LIBRARY - the pulse library +# PULSEAUDIO_VERSION_STRING - the version of PulseAudio found +# + +find_path(PULSEAUDIO_INCLUDE_DIR + NAMES pulse/pulseaudio.h + DOC "The PulseAudio include directory" +) + +find_library(PULSEAUDIO_LIBRARY + NAMES pulse + DOC "The PulseAudio library" +) + +if(PULSEAUDIO_INCLUDE_DIR AND EXISTS "${PULSEAUDIO_INCLUDE_DIR}/pulse/version.h") + file(STRINGS "${PULSEAUDIO_INCLUDE_DIR}/pulse/version.h" pulse_version_str + REGEX "^#define[\t ]+pa_get_headers_version\\(\\)[\t ]+\\(\".*\"\\)") + + string(REGEX REPLACE "^.*pa_get_headers_version\\(\\)[\t ]+\\(\"([^\"]*)\"\\).*$" "\\1" + PULSEAUDIO_VERSION_STRING "${pulse_version_str}") + unset(pulse_version_str) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PulseAudio + REQUIRED_VARS PULSEAUDIO_LIBRARY PULSEAUDIO_INCLUDE_DIR + VERSION_VAR PULSEAUDIO_VERSION_STRING +) + +if(PULSEAUDIO_FOUND) + set(PULSEAUDIO_LIBRARIES ${PULSEAUDIO_LIBRARY}) + set(PULSEAUDIO_INCLUDE_DIRS ${PULSEAUDIO_INCLUDE_DIR}) +endif() + +mark_as_advanced(PULSEAUDIO_INCLUDE_DIR PULSEAUDIO_LIBRARY) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..05f43485 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(libsphinxad) +add_subdirectory(libsphinxbase) +#add_subdirectory(sphinx_adtools) +#add_subdirectory(sphinx_cepview) +#add_subdirectory(sphinx_fe) +#add_subdirectory(sphinx_jsgf2fsg) +#add_subdirectory(sphinx_lmtools) \ No newline at end of file diff --git a/src/libsphinxad/CMakeLists.txt b/src/libsphinxad/CMakeLists.txt new file mode 100644 index 00000000..1d898445 --- /dev/null +++ b/src/libsphinxad/CMakeLists.txt @@ -0,0 +1,33 @@ +include_directories(${CMAKE_SOURCE_DIR}/include/sphinxbase) + +if (WIN32) + set(SOURCES ${SOURCES} ad_win32.c) + set(LIBS winmm CACHE INTERNAL "libs") +endif () + +find_package(PulseAudio) +if (PULSEAUDIO_FOUND) + set(SOURCES ${SOURCES} ad_pulse.c) + set(LIBS ${PULSEAUDIO_LIBRARIES} CACHE INTERNAL "libs") +endif() + +find_package(OSS) +if (OSS_FOUND) + set(SOURCES ${SOURCES} ad_oss.c ) +endif() + +find_package(OpenAL) +if (OPENAL_FOUND) + set(SOURCES ${SOURCES} ad_openal.c) + set(LIBS ${OPENAL_LIBRARY} CACHE INTERNAL "libs") + include_directories(${OPENAL_INCLUDE_DIR}) +endif() + +find_package(ALSA) +if (ALSA_FOUND) + set(SOURCES ${SOURCES} ad_alsa.c) + set(LIBS ${ALSA_LIBRARIES} CACHE INTERNAL "libs") +endif() + +add_library(libsphinxad OBJECT ${SOURCES}) +set_property(TARGET libsphinxad PROPERTY POSITION_INDEPENDENT_CODE TRUE) diff --git a/src/libsphinxad/ad_alsa.c b/src/libsphinxad/ad_alsa.c index 6521cb19..8020a2f3 100644 --- a/src/libsphinxad/ad_alsa.c +++ b/src/libsphinxad/ad_alsa.c @@ -75,7 +75,6 @@ #include #include #include -#include #include #include "prim_type.h" diff --git a/src/libsphinxad/ad_base.c b/src/libsphinxad/ad_base.c index d248ccdb..8d81075e 100644 --- a/src/libsphinxad/ad_base.c +++ b/src/libsphinxad/ad_base.c @@ -50,7 +50,6 @@ #include #include -#include #include "prim_type.h" #include "ad.h" diff --git a/src/libsphinxad/ad_openal.c b/src/libsphinxad/ad_openal.c index 82e63008..8ac469c9 100644 --- a/src/libsphinxad/ad_openal.c +++ b/src/libsphinxad/ad_openal.c @@ -34,7 +34,6 @@ * ==================================================================== * */ -#include #include #include @@ -113,16 +112,9 @@ ad_read(ad_rec_t * r, int16 * buf, int32 max) } -int32 -ad_close(ad_rec_t * r) +int32 ad_close(ad_rec_t *r) { - ALCboolean isClosed; - - isClosed = alcCaptureCloseDevice(r -> device); + ALCboolean isClosed = alcCaptureCloseDevice(r -> device); - if (isClosed) { - return 0; - } else { - return -1; - } + return isClosed ? 0 : -1; } diff --git a/src/libsphinxad/ad_oss.c b/src/libsphinxad/ad_oss.c index d3a936d9..c75d3c63 100644 --- a/src/libsphinxad/ad_oss.c +++ b/src/libsphinxad/ad_oss.c @@ -64,7 +64,6 @@ #include #include #include -#include #include "prim_type.h" #include "ad.h" diff --git a/src/libsphinxad/ad_pulse.c b/src/libsphinxad/ad_pulse.c index 9df3ea73..7883f484 100644 --- a/src/libsphinxad/ad_pulse.c +++ b/src/libsphinxad/ad_pulse.c @@ -39,7 +39,6 @@ #include #include -#include #include #include diff --git a/src/libsphinxbase/CMakeLists.txt b/src/libsphinxbase/CMakeLists.txt new file mode 100644 index 00000000..91d7de87 --- /dev/null +++ b/src/libsphinxbase/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(fe) +add_subdirectory(feat) +add_subdirectory(lm) +add_subdirectory(util) \ No newline at end of file diff --git a/src/libsphinxbase/fe/CMakeLists.txt b/src/libsphinxbase/fe/CMakeLists.txt new file mode 100644 index 00000000..6b331353 --- /dev/null +++ b/src/libsphinxbase/fe/CMakeLists.txt @@ -0,0 +1,23 @@ +SET(SOURCES fe_interface.c + fe_internal.h + fe_noise.c + fe_noise.h + fe_prespch_buf.c + fe_prespch_buf.h + fe_sigproc.c + fe_type.h + fe_warp.c + fe_warp.h + fe_warp_affine.c + fe_warp_affine.h + fe_warp_inverse_linear.c + fe_warp_inverse_linear.h + fe_warp_piecewise_linear.c + fe_warp_piecewise_linear.h + fixlog.c + yin.c + ) + +add_library(fe OBJECT ${SOURCES}) + +set_property(TARGET fe PROPERTY POSITION_INDEPENDENT_CODE TRUE) \ No newline at end of file diff --git a/src/libsphinxbase/feat/CMakeLists.txt b/src/libsphinxbase/feat/CMakeLists.txt new file mode 100644 index 00000000..d5dd2392 --- /dev/null +++ b/src/libsphinxbase/feat/CMakeLists.txt @@ -0,0 +1,9 @@ +SET(SOURCES agc.c + cmn.c + cmn_live.c + feat.c + lda.c + ) + +add_library(feat OBJECT ${SOURCES}) +set_property(TARGET feat PROPERTY POSITION_INDEPENDENT_CODE TRUE) \ No newline at end of file diff --git a/src/libsphinxbase/lm/CMakeLists.txt b/src/libsphinxbase/lm/CMakeLists.txt new file mode 100644 index 00000000..eb51651b --- /dev/null +++ b/src/libsphinxbase/lm/CMakeLists.txt @@ -0,0 +1,14 @@ +SET(SOURCES fsg_model.c + jsgf.c + jsgf_parser.c + jsgf_scanner.c + lm_trie.c + lm_trie_quant.c + ngram_model.c + ngram_model_set.c + ngram_model_trie.c + ngrams_raw.c + ) + +add_library(lm OBJECT ${SOURCES}) +set_property(TARGET lm PROPERTY POSITION_INDEPENDENT_CODE TRUE) \ No newline at end of file diff --git a/src/libsphinxbase/lm/lm_trie_quant.c b/src/libsphinxbase/lm/lm_trie_quant.c index 525e69da..32cd4de6 100644 --- a/src/libsphinxbase/lm/lm_trie_quant.c +++ b/src/libsphinxbase/lm/lm_trie_quant.c @@ -275,14 +275,8 @@ lm_trie_quant_mwrite(lm_trie_quant_t * quant, bitarr_address_t address, int order_minus_2, float prob, float backoff) { bitarr_write_int57(address, quant->prob_bits + quant->bo_bits, - (uint64) ((bins_encode - (&quant->tables[order_minus_2][0], - prob) << quant-> - bo_bits) | bins_encode(&quant-> - tables - [order_minus_2] - [1], - backoff))); + (((int)bins_encode(&quant->tables[order_minus_2][0],prob) << quant->bo_bits) + | (int)bins_encode(&quant-> tables[order_minus_2][1], backoff))); } void diff --git a/src/libsphinxbase/util/CMakeLists.txt b/src/libsphinxbase/util/CMakeLists.txt new file mode 100644 index 00000000..1bb2b0e3 --- /dev/null +++ b/src/libsphinxbase/util/CMakeLists.txt @@ -0,0 +1,34 @@ +SET(SOURCES bio.c + bitarr.c + bitvec.c + blas_lite.c + case.c + ckd_alloc.c + cmd_ln.c + dtoa.c + err.c + f2c_lite.c + filename.c + genrand.c + glist.c + hash_table.c + heap.c + listelem_alloc.c + logmath.c + matrix.c + mmio.c + pio.c + priority_queue.c + profile.c + sbthread.c + slamch.c + slapack_lite.c + strfuncs.c + ) + +if (WIN32) + set(SOURCES ${SOURCES} errno.c) +endif () + +add_library(util OBJECT ${SOURCES}) +set_property(TARGET util PROPERTY POSITION_INDEPENDENT_CODE TRUE) \ No newline at end of file diff --git a/src/libsphinxbase/util/bitarr.c b/src/libsphinxbase/util/bitarr.c index a76b0331..8d64152b 100644 --- a/src/libsphinxbase/util/bitarr.c +++ b/src/libsphinxbase/util/bitarr.c @@ -81,7 +81,7 @@ static uint64 read_off(bitarr_address_t address) uint64 bitarr_read_int57(bitarr_address_t address, uint8 length, uint64 mask) { - return (read_off(address) >> get_shift(address.offset & 7, length)) & mask; + return ((int)read_off(address) >> get_shift(address.offset & 7, length)) & (int)mask; } void bitarr_write_int57(bitarr_address_t address, uint8 length, uint64 value) @@ -93,7 +93,7 @@ void bitarr_write_int57(bitarr_address_t address, uint8 length, uint64 value) value64 |= (value << get_shift(address.offset & 7, length)); memcpy(base_off, &value64, sizeof(value64)); #else - *(uint64 *)((uint8 *)(address.base) + (address.offset >> 3)) |= (value << get_shift(address.offset & 7, length)); + *(int *)((uint8 *)(address.base) + (address.offset >> 3)) |= ((int)value << get_shift(address.offset & 7, length)); #endif } diff --git a/src/libsphinxbase/util/profile.c b/src/libsphinxbase/util/profile.c index c8d84ca9..e2b506a0 100644 --- a/src/libsphinxbase/util/profile.c +++ b/src/libsphinxbase/util/profile.c @@ -73,7 +73,7 @@ # ifndef _WIN32_WCE # include # endif -#elif defined(HAVE_UNISTD_H) /* I know this, this is Unix... */ +#else # include # include # include diff --git a/src/sphinx_adtools/CMakeLists.txt b/src/sphinx_adtools/CMakeLists.txt new file mode 100644 index 00000000..45737846 --- /dev/null +++ b/src/sphinx_adtools/CMakeLists.txt @@ -0,0 +1,12 @@ +set(PROGRAMS cont_seg + sphinx_pitch + ) + +foreach (program ${PROGRAMS}) + add_executable(${program} ${program}) + target_link_libraries(${program} ${PROJECT_NAME}) + set_target_properties (${program} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endforeach () \ No newline at end of file diff --git a/src/sphinx_cepview/CMakeLists.txt b/src/sphinx_cepview/CMakeLists.txt new file mode 100644 index 00000000..211aa86b --- /dev/null +++ b/src/sphinx_cepview/CMakeLists.txt @@ -0,0 +1,10 @@ +set(PROGRAM sphinx_cepview) + +SET(SOURCES main_cepview.c) + +add_executable(${PROGRAM} ${SOURCES}) +target_link_libraries(${PROGRAM} ${PROJECT_NAME}) +set_target_properties (${PROGRAM} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) \ No newline at end of file diff --git a/src/sphinx_fe/CMakeLists.txt b/src/sphinx_fe/CMakeLists.txt new file mode 100644 index 00000000..0e57d7f5 --- /dev/null +++ b/src/sphinx_fe/CMakeLists.txt @@ -0,0 +1,9 @@ +set(PROGRAM sphinx_fe) +set(SOURCES sphinx_fe.c) + +add_executable(${PROGRAM} ${SOURCES}) +target_link_libraries(${PROGRAM} ${PROJECT_NAME}) +set_target_properties (${PROGRAM} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) \ No newline at end of file diff --git a/src/sphinx_jsgf2fsg/CMakeLists.txt b/src/sphinx_jsgf2fsg/CMakeLists.txt new file mode 100644 index 00000000..07af436c --- /dev/null +++ b/src/sphinx_jsgf2fsg/CMakeLists.txt @@ -0,0 +1,9 @@ +set(PROGRAM sphinx_jsgf2fsg) +set(SOURCES main.c) + +add_executable(${PROGRAM} ${SOURCES}) +target_link_libraries(${PROGRAM} ${PROJECT_NAME}) +set_target_properties (${PROGRAM} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) \ No newline at end of file diff --git a/src/sphinx_lmtools/CMakeLists.txt b/src/sphinx_lmtools/CMakeLists.txt new file mode 100644 index 00000000..23e12dcb --- /dev/null +++ b/src/sphinx_lmtools/CMakeLists.txt @@ -0,0 +1,12 @@ +set(PROGRAMS sphinx_lm_convert.c + sphinx_lm_eval.c + ) + +foreach (program ${PROGRAMS}) + add_executable(${program} ${program}) + target_link_libraries(${program} ${PROJECT_NAME}) + set_target_properties (${program} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endforeach () \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..059f2a25 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(unit) \ No newline at end of file diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt new file mode 100644 index 00000000..71bd9ed4 --- /dev/null +++ b/test/unit/CMakeLists.txt @@ -0,0 +1,15 @@ +add_subdirectory(test_alloc) +#add_subdirectory(test_bitvec) +#add_subdirectory(test_case) +#add_subdirectory(test_cmdln) +#add_subdirectory(test_fe) +#add_subdirectory(test_feat) +#add_subdirectory(test_fsg) +#add_subdirectory(test_hash) +#add_subdirectory(test_lineiter) +#add_subdirectory(test_logmath) +#add_subdirectory(test_matrix) +#add_subdirectory(test_ngram) +#add_subdirectory(test_string) +#add_subdirectory(test_thread) +#add_subdirectory(test_util) \ No newline at end of file diff --git a/test/unit/test_alloc/CMakeLists.txt b/test/unit/test_alloc/CMakeLists.txt new file mode 100644 index 00000000..50e36d26 --- /dev/null +++ b/test/unit/test_alloc/CMakeLists.txt @@ -0,0 +1,23 @@ +include_directories(${CMAKE_SOURCE_DIR}/include/sphinxbase) + +SET(TESTS test_ckd_alloc + test_ckd_alloc_abort + test_ckd_alloc_catch + test_ckd_alloc_fail + test_listelem_alloc +) + +enable_testing() +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${TESTS}) +set(CMAKE_CTEST_COMMAND ctest -V) + +foreach (test ${TESTS}) + add_executable(${test} ${test}) + target_link_libraries(${test} ${PROJECT_NAME}) + set_target_properties(${test} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + ) + add_test(NAME ${test} COMMAND ${test} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) + add_dependencies(check ${test}) +endforeach ()