Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows build #251

Merged
merged 5 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ else()
endif()

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if(BUILD_SHARED_LIBS)
add_definitions(-DSPHINX_DLL)
endif()
option(FIXED_POINT "Build using fixed-point math" OFF)
if(NOT DEFAULT_RADIX)
set(DEFAULT_RADIX 12)
endif()
cmake_print_variables(FIXED_POINT DEFAULT_RADIX)

# Maybe not a great idea, but it does work on both Windows and Linux
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

configure_file(config.h.in config.h)
configure_file(sphinx_config.h.in include/sphinxbase/sphinx_config.h)
add_definitions(-DHAVE_CONFIG_H)
Expand Down
1 change: 1 addition & 0 deletions include/sphinxbase/ckd_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ extern "C" {
* allocation fails rather than exiting or calling longjmp().
* @return Pointer to a previously set <code>jmp_buf</code>, if any.
*/
SPHINXBASE_EXPORT
jmp_buf *ckd_set_jump(jmp_buf *env, int abort);

/**
Expand Down
6 changes: 6 additions & 0 deletions include/sphinxbase/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,39 @@ typedef struct bit_encode_s bit_encode_t;
/**
* Attach bitstream encoder to a file.
*/
SPHINXBASE_EXPORT
bit_encode_t *bit_encode_attach(FILE *outfh);

/**
* Retain pointer to a bit encoder.
*/
SPHINXBASE_EXPORT
bit_encode_t *bit_encode_retain(bit_encode_t *be);

/**
* Release pointer to a bit encoder.
*
* Note that this does NOT flush any leftover bits.
*/
SPHINXBASE_EXPORT
int bit_encode_free(bit_encode_t *be);

/**
* Write bits to encoder.
*/
SPHINXBASE_EXPORT
int bit_encode_write(bit_encode_t *be, unsigned char const *bits, int nbits);

/**
* Write lowest-order bits of codeword to encoder.
*/
SPHINXBASE_EXPORT
int bit_encode_write_cw(bit_encode_t *be, uint32 codeword, int nbits);

/**
* Flush any unwritten bits, zero-padding if necessary.
*/
SPHINXBASE_EXPORT
int bit_encode_flush(bit_encode_t *be);

/**
Expand Down
7 changes: 6 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ target_link_libraries(pocketsphinx PUBLIC Threads::Threads)
# Shared library version != package version, unfortunately
set_target_properties(pocketsphinx PROPERTIES
VERSION 4.0.0
SOVERSION 4)
SOVERSION 4
)
# No idea why this can't just go in the above list but oh well
set_property(TARGET pocketsphinx PROPERTY
COMPILE_DEFINITIONS POCKETSPHINX_EXPORTS;SPHINXBASE_EXPORTS
)

install(TARGETS pocketsphinx LIBRARY)
29 changes: 29 additions & 0 deletions src/acmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

/* Local headers. */
#include <pocketsphinx/ps_mllr.h>
#include <pocketsphinx/export.h>
#include "bin_mdef.h"
#include "tmat.h"
#include "hmm.h"
Expand Down Expand Up @@ -225,6 +226,7 @@ typedef struct acmod_s acmod_t;
* model, this function will fail. This pointer is retained.
* @return a newly initialized acmod_t, or NULL on failure.
*/
POCKETSPHINX_EXPORT
acmod_t *acmod_init(cmd_ln_t *config, logmath_t *lmath, fe_t *fe, feat_t *fcb);

/**
Expand All @@ -234,6 +236,7 @@ acmod_t *acmod_init(cmd_ln_t *config, logmath_t *lmath, fe_t *fe, feat_t *fcb);
* @param fe acoustic feature extraction module to verify.
* @return TRUE if compatible, FALSE otherwise
*/
POCKETSPHINX_EXPORT
int acmod_fe_mismatch(acmod_t *acmod, fe_t *fe);

/**
Expand All @@ -243,6 +246,7 @@ int acmod_fe_mismatch(acmod_t *acmod, fe_t *fe);
* @param fcb dynamic feature computation module to verify.
* @return TRUE if compatible, FALSE otherwise
*/
POCKETSPHINX_EXPORT
int acmod_feat_mismatch(acmod_t *acmod, feat_t *fcb);

/**
Expand All @@ -255,6 +259,7 @@ int acmod_feat_mismatch(acmod_t *acmod, feat_t *fcb);
* @return The updated transform object for this decoder, or
* NULL on failure.
*/
POCKETSPHINX_EXPORT
ps_mllr_t *acmod_update_mllr(acmod_t *acmod, ps_mllr_t *mllr);

/**
Expand All @@ -264,6 +269,7 @@ ps_mllr_t *acmod_update_mllr(acmod_t *acmod, ps_mllr_t *mllr);
* @param logfh Filehandle to log to.
* @return 0 for success, <0 on error.
*/
POCKETSPHINX_EXPORT
int acmod_set_senfh(acmod_t *acmod, FILE *senfh);

/**
Expand All @@ -273,6 +279,7 @@ int acmod_set_senfh(acmod_t *acmod, FILE *senfh);
* @param logfh Filehandle to log to.
* @return 0 for success, <0 on error.
*/
POCKETSPHINX_EXPORT
int acmod_set_mfcfh(acmod_t *acmod, FILE *logfh);

/**
Expand All @@ -282,21 +289,25 @@ int acmod_set_mfcfh(acmod_t *acmod, FILE *logfh);
* @param logfh Filehandle to log to.
* @return 0 for success, <0 on error.
*/
POCKETSPHINX_EXPORT
int acmod_set_rawfh(acmod_t *acmod, FILE *logfh);

/**
* Finalize an acoustic model.
*/
POCKETSPHINX_EXPORT
void acmod_free(acmod_t *acmod);

/**
* Mark the start of an utterance.
*/
POCKETSPHINX_EXPORT
int acmod_start_utt(acmod_t *acmod);

/**
* Mark the end of an utterance.
*/
POCKETSPHINX_EXPORT
int acmod_end_utt(acmod_t *acmod);

/**
Expand All @@ -311,6 +322,7 @@ int acmod_end_utt(acmod_t *acmod);
* @return 0 for success, <0 for failure (if the utterance can't be
* rewound due to no feature or score data available)
*/
POCKETSPHINX_EXPORT
int acmod_rewind(acmod_t *acmod);

/**
Expand All @@ -322,6 +334,7 @@ int acmod_rewind(acmod_t *acmod);
*
* @return New frame index.
*/
POCKETSPHINX_EXPORT
int acmod_advance(acmod_t *acmod);

/**
Expand All @@ -332,6 +345,7 @@ int acmod_advance(acmod_t *acmod);
* model.
* @return previous allocation policy.
*/
POCKETSPHINX_EXPORT
int acmod_set_grow(acmod_t *acmod, int grow_feat);

/**
Expand All @@ -352,6 +366,7 @@ int acmod_set_grow(acmod_t *acmod, int grow_feat);
* utterance and should be processed as such.
* @return Number of frames of data processed.
*/
POCKETSPHINX_EXPORT
int acmod_process_raw(acmod_t *acmod,
int16 const **inout_raw,
size_t *inout_n_samps,
Expand All @@ -368,6 +383,7 @@ int acmod_process_raw(acmod_t *acmod,
* utterance and should be processed as such.
* @return Number of frames of data processed.
*/
POCKETSPHINX_EXPORT
int acmod_process_cep(acmod_t *acmod,
mfcc_t ***inout_cep,
int *inout_n_frames,
Expand All @@ -386,6 +402,7 @@ int acmod_process_cep(acmod_t *acmod,
* @param feat Pointer to one frame of dynamic features.
* @return Number of frames processed (either 0 or 1).
*/
POCKETSPHINX_EXPORT
int acmod_process_feat(acmod_t *acmod,
mfcc_t **feat);

Expand All @@ -395,13 +412,15 @@ int acmod_process_feat(acmod_t *acmod,
* @param insenfh File handle of dump file
* @return 0 for success, <0 for failure
*/
POCKETSPHINX_EXPORT
int acmod_set_insenfh(acmod_t *acmod, FILE *insenfh);

/**
* Read one frame of scores from senone score dump file.
*
* @return Number of frames read or <0 on error.
*/
POCKETSPHINX_EXPORT
int acmod_read_scores(acmod_t *acmod);

/**
Expand All @@ -413,6 +432,7 @@ int acmod_read_scores(acmod_t *acmod);
* set of features.
* @return Feature array, or NULL if requested frame is not available.
*/
POCKETSPHINX_EXPORT
mfcc_t **acmod_get_frame(acmod_t *acmod, int *inout_frame_idx);

/**
Expand All @@ -428,24 +448,28 @@ mfcc_t **acmod_get_frame(acmod_t *acmod, int *inout_frame_idx);
* data pointed to persists only until the next call to
* acmod_score() or acmod_advance().
*/
POCKETSPHINX_EXPORT
int16 const *acmod_score(acmod_t *acmod,
int *inout_frame_idx);

/**
* Write senone dump file header.
*/
POCKETSPHINX_EXPORT
int acmod_write_senfh_header(acmod_t *acmod, FILE *logfh);

/**
* Write a frame of senone scores to a dump file.
*/
POCKETSPHINX_EXPORT
int acmod_write_scores(acmod_t *acmod, int n_active, uint8 const *active,
int16 const *senscr, FILE *senfh);


/**
* Get best score and senone index for current frame.
*/
POCKETSPHINX_EXPORT
int acmod_best_score(acmod_t *acmod, int *out_best_senid);

/**
Expand All @@ -466,26 +490,31 @@ void acmod_activate_hmm(acmod_t *acmod, hmm_t *hmm);
/**
* Build active list.
*/
POCKETSPHINX_EXPORT
int32 acmod_flags2list(acmod_t *acmod);

/**
* Get the offset of the utterance start of the current stream, helpful for stream-wide timing.
*/
POCKETSPHINX_EXPORT
int32 acmod_stream_offset(acmod_t *acmod);

/**
* Reset the current stream
*/
POCKETSPHINX_EXPORT
void acmod_start_stream(acmod_t *acmod);

/**
* Sets the limit of the raw audio data to store
*/
POCKETSPHINX_EXPORT
void acmod_set_rawdata_size(acmod_t *acmod, int32 size);

/**
* Retrieves the raw data collected during utterance decoding
*/
POCKETSPHINX_EXPORT
void acmod_get_rawdata(acmod_t *acmod, int16 **buffer, int32 *size);

#ifdef __cplusplus
Expand Down
8 changes: 8 additions & 0 deletions src/bin_mdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,38 +188,45 @@ int bin_mdef_write_text(bin_mdef_t *m, const char *filename);
/**
* Retain a pointer to a bin_mdef_t.
*/
POCKETSPHINX_EXPORT
bin_mdef_t *bin_mdef_retain(bin_mdef_t *m);
/**
* Release a pointer to a binary mdef.
*/
POCKETSPHINX_EXPORT
int bin_mdef_free(bin_mdef_t *m);

/**
* Context-independent phone lookup.
* @return phone id for ciphone.
*/
POCKETSPHINX_EXPORT
int bin_mdef_ciphone_id(bin_mdef_t *m, /**< In: Model structure being queried */
const char *ciphone); /**< In: ciphone for which id wanted */

/**
* Case-insensitive context-independent phone lookup.
* @return phone id for ciphone.
*/
POCKETSPHINX_EXPORT
int bin_mdef_ciphone_id_nocase(bin_mdef_t *m, /**< In: Model structure being queried */
const char *ciphone); /**< In: ciphone for which id wanted */

/* Return value: READ-ONLY ciphone string name for the given ciphone id */
POCKETSPHINX_EXPORT
const char *bin_mdef_ciphone_str(bin_mdef_t *m, /**< In: Model structure being queried */
int32 ci); /**< In: ciphone id for which name wanted */

/* Return value: phone id for the given constituents if found, else -1 */
POCKETSPHINX_EXPORT
int bin_mdef_phone_id(bin_mdef_t *m, /**< In: Model structure being queried */
int32 b, /**< In: base ciphone id */
int32 l, /**< In: left context ciphone id */
int32 r, /**< In: right context ciphone id */
int32 pos); /**< In: Word position */

/* Look up a phone id, backing off to other word positions. */
POCKETSPHINX_EXPORT
int bin_mdef_phone_id_nearest(bin_mdef_t * m, int32 b,
int32 l, int32 r, int32 pos);

Expand All @@ -228,6 +235,7 @@ int bin_mdef_phone_id_nearest(bin_mdef_t * m, int32 b,
*
* @return 0 if successful, -1 if error.
*/
POCKETSPHINX_EXPORT
int bin_mdef_phone_str(bin_mdef_t *m, /**< In: Model structure being queried */
int pid, /**< In: phone id being queried */
char *buf); /**< Out: On return, buf has the string */
Expand Down
Loading