Lines Matching refs:swimodel
2 * swimodel.c *
33 #include "swimodel.h"
330 const SWIModel* load_swimodel(const char *filename)
333 SWIModel *swimodel = NULL;
339 swimodel = (SWIModel*) CALLOC(1, sizeof(SWIModel), "clib.models.base");
341 if (mmap_zip(filename, &swimodel->mmap_zip_data, &swimodel->mmap_zip_size)) {
345 file = swimodel->mmap_zip_data;
347 swimodel->num_hmmstates = *(const short*)file;
349 swimodel->num_dims = *(const short*)file;
351 swimodel->num_pdfs = *(const short*)file;
354 SWIhmmState* hmmstates = (SWIhmmState*) CALLOC(swimodel->num_hmmstates, sizeof(SWIhmmState), "clib.models.states");
355 swimodel->hmmstates = hmmstates;
358 file += sizeof(short) * swimodel->num_hmmstates;
360 swimodel->allmeans = (const featdata*)file;
361 file += sizeof(featdata) * swimodel->num_pdfs * swimodel->num_dims;
363 swimodel->allweights = (const wtdata*)file;
364 file += sizeof(wtdata) * swimodel->num_pdfs;
366 swimodel->avg_state_durations = (const featdata*)file;
367 file += sizeof(featdata) * swimodel->num_hmmstates;
369 if (file > swimodel->mmap_zip_data + swimodel->mmap_zip_size) {
376 filename, swimodel->num_hmmstates, swimodel->num_dims, swimodel->num_pdfs,
377 *swimodel->allweights);
380 const featdata* mean_ptr = swimodel->allmeans;
381 const wtdata* weight_ptr = swimodel->allweights;
383 for (i = 0;i < swimodel->num_hmmstates;i++)
388 mean_ptr += swimodel->num_dims * num_pdfs_in_model[i];
392 return swimodel;
395 free_swimodel(swimodel);
399 void free_swimodel(const SWIModel* swimodel)
401 if (!swimodel) return;
402 if (swimodel->mmap_zip_data) munmap_zip(swimodel->mmap_zip_data, swimodel->mmap_zip_size);
403 FREE((void*)swimodel->hmmstates);
404 FREE((void*)swimodel);