Пример #1
0
S_API void SUtteranceSetFeature(SUtterance *self, const char *name,
								const SObject *object, s_erc *error)
{
	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SUtteranceSetFeature",
				  "Argument \"self\" is NULL");
		return;
	}

	if (name == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SUtteranceSetFeature",
				  "Argument \"name\" is NULL");
		return;
	}

	if (object == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SUtteranceSetFeature",
				  "Argument \"object\" is NULL");
		return;
	}

	SMapSetObject(self->features, name, object, error);
	S_CHK_ERR(error, S_CONTERR,
			  "SUtteranceSetFeature",
			  "Call to \"SMapSetObject\" failed");
}
Пример #2
0
S_LOCAL void _SVoiceSetFeature_no_lock(SVoice *self, const char *key,
									   SObject *object,  s_erc *error)
{
	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "_SVoiceSetFeature_no_lock",
				  "Argument \"self\" is NULL");
		return;
	}

	if (key == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "_SVoiceSetFeature_no_lock",
				  "Argument \"key\" is NULL");
		return;
	}

	if (object == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "_SVoiceSetFeature_no_lock",
				  "Argument \"object\" is NULL");
		return;
	}

	SMapSetObject(self->features, key, object, error);
	S_CHK_ERR(error, S_CONTERR,
			  "_SVoiceSetFeature_no_lock",
			  "Call to \"SMapSetObject\" failed");
}
Пример #3
0
static void Add(SItmContent *self, const char *relation,
				const SItem *item, s_erc *error)
{
	S_CLR_ERR(error);
	SMapSetObject(self->relations, relation, S_OBJECT(item), error);
	S_CHK_ERR(error, S_CONTERR,
			  "Add",
			  "Failed to add item from relation \"%s\" to relations map", relation);
}
Пример #4
0
static void UttSetRelation(SUtterance *self, SRelation *rel, s_erc *error)
{
	S_CLR_ERR(error);

	rel->utterance = self;

	SMapSetObject(self->relations, rel->name, S_OBJECT(rel), error);
	S_CHK_ERR(error, S_CONTERR,
			  "UttSetRelation",
			  "Call to \"SMapSetObject\" failed");
}
Пример #5
0
S_API void SVoiceSetFeatProc(SVoice *self, const char *key,
							 SFeatProcessor *featProc,  s_erc *error)
{
	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetFeatProc",
				  "Argument \"self\" is NULL");
		return;
	}

	if (key == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetFeatProc",
				  "Argument \"key\" is NULL");
		return;
	}

	if (featProc == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetFeatProc",
				  "Argument \"featProc\" is NULL");
		return;
	}

	s_mutex_lock(&self->voice_mutex);
	SMapSetObject(self->featProcessors, key, S_OBJECT(featProc), error);
	s_mutex_unlock(&self->voice_mutex);

	S_CHK_ERR(error, S_CONTERR,
			  "SVoiceSetFeatProc",
			  "Call to \"SMapSetObject\" failed");
}
Пример #6
0
S_API void SVoiceSetFeature(SVoice *self, const char *key,
							SObject *object,  s_erc *error)
{
	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetFeature",
				  "Argument \"self\" is NULL");
		return;
	}

	if (key == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetFeature",
				  "Argument \"key\" is NULL");
		return;
	}

	if (object == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetFeature",
				  "Argument \"object\" is NULL");
		return;
	}

	s_mutex_lock((s_mutex*)&(self->voice_mutex));
	SMapSetObject(self->features, key, object, error);
	s_mutex_unlock((s_mutex*)&(self->voice_mutex));

	S_CHK_ERR(error, S_CONTERR,
			  "SVoiceSetFeature",
			  "Call to \"SMapSetObject\" failed");
}
Пример #7
0
S_API void SVoiceSetUttType(SVoice *self, const char *key,
							SList *uttType,  s_erc *error)
{
	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetUttType",
				  "Argument \"self\" is NULL");
		return;
	}

	if (key == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetUttType",
				  "Argument \"key\" is NULL");
		return;
	}

	if (uttType == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetUttType",
				  "Argument \"uttType\" is NULL");
		return;
	}

	s_mutex_lock(&self->voice_mutex);
	SMapSetObject(self->uttTypes, key, S_OBJECT(uttType), error);
	s_mutex_unlock(&self->voice_mutex);

	S_CHK_ERR(error, S_CONTERR,
			  "SVoiceSetUttType",
			  "Call to \"SMapSetObject\" failed");
}
Пример #8
0
static void create_new_entry(SAddendum *addendum, s_erc *error)
{
	SMap *features = NULL;
	SList *phones = NULL;
	int i;
	SObject *stringObject = NULL;


	S_CLR_ERR(error);

	/* create a word features map */
	features = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_new_entry",
				  "Failed to create new 'SMapList' object"))
		goto quit_error;

	/* now create a phones list */
	phones = S_LIST(S_NEW(SListList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_new_entry",
				  "Failed to create new 'SListList' object"))
		goto quit_error;

	SMapSetObject(features, "phones", S_OBJECT(phones), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_new_entry",
				  "Failed to initialize new 'SListList' object"))
	{
		S_DELETE(phones, "create_new_entry", error);
		goto quit_error;
	}

	/* add the phones to list */
	for (i = 0; test_word_phones[i] != NULL; i++)
	{
		/* create a string object */
		stringObject = SObjectSetString(test_word_phones[i], error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_new_entry",
					  "Call to \"SObjectSetString\" failed"))
			goto quit_error;

		/* add string object to list */
		SListAppend(phones, stringObject, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_new_entry",
					  "Call to \"SListAppend\" failed"))
		{
			S_DELETE(stringObject, "create_new_entry", error);
			goto quit_error;
		}
	}

	/* add entry to addendum */
	S_ADDENDUM_CALL(addendum, add_word)(addendum, test_word, features, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_new_entry",
				  "Call to method \"add_word\" failed"))
		goto quit_error;

	return;

quit_error:
	if (features != NULL)
		S_DELETE(features, "create_new_entry", error);
}
Пример #9
0
static s_hash_table *read_item_contents(SEbmlRead *ebmlReader, s_erc *error)
{
	s_hash_table *items_content_table = NULL;
	s_items_content_container *ic = NULL;
	uint32 *item_content_id = NULL;
	uint32 id;
	s_bool container_exhausted;


	S_CLR_ERR(error);

	/* read S_UTT_EBML_ITEMS_CONTENTS container */
	id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_item_contents",
				  "ebmlRead method \"container\" failed"))
		goto quit_error;

	/* 2^9 = 512 item contents for a start */
	items_content_table = s_hash_table_new(&items_content_table_free_fp, 9, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_item_contents",
				  "Call to \"s_hash_table_new\" failed"))
		goto quit_error;

	while (1)
	{
		container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_item_contents",
					  "ebmlRead method \"container_at_end\" failed"))
			goto quit_error;

		if (container_exhausted)
			break;

		/* peek id  */
		id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_item_contents",
					  "ebmlRead method \"peek_id\" failed"))
			goto quit_error;

		switch(id)
		{
		case S_UTT_EBML_ITEMS_CONTENT_ID:
		{
			item_content_id = S_MALLOC(uint32, 1);
			if (item_content_id == NULL)
			{
				S_FTL_ERR(error, S_MEMERROR,
						  "read_item_contents",
						  "Failed to allocate memory for 'uint32' object");
				goto quit_error;
			}

			*item_content_id = S_EBMLREAD_CALL(ebmlReader, read_uint)(ebmlReader, &id, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_item_contents",
						  "ebmlRead method \"read_uint\" failed"))
				goto quit_error;

			/* make new item contents container */
			ic = S_CALLOC(s_items_content_container, 1);
			if (ic == NULL)
			{
				S_FTL_ERR(error, S_MEMERROR,
						  "read_item_contents",
						  "Failed to allocate memory for 's_items_content_container' object");
				goto quit_error;
			}

			/* create a new item contents */
			ic->content =  S_NEW(SItmContent, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_item_contents",
						  "Failed to create new item content"))
				goto quit_error;

			break;
		}
		case S_UTT_EBML_ITEMS_CONTENT_FEATURES:
		{
			/* read S_UTT_EBML_ITEMS_CONTENT_FEATURES container */
			id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_item_contents",
						  "ebmlRead method \"container\" failed"))
				goto quit_error;

			while (1)
			{
				container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "read_item_contents",
							  "ebmlRead method \"container_at_end\" failed"))
					goto quit_error;

				if (container_exhausted)
				{
					/* add item contents container to hash table */
					s_hash_table_add(items_content_table, (void*)item_content_id,
									 sizeof(uint32), ic, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_item_contents",
								  "Call to \"s_hash_table_add\" failed"))
						goto quit_error;

					item_content_id = NULL;
					ic = NULL;
					break; /* we are finished reading the item content
							* features */
				}

				/* peek id for item content feature elements */
				id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "read_item_contents",
							  "ebmlRead method \"peek_id\" failed"))
					goto quit_error;

				switch(id)
				{
				case S_UTT_EBML_ITEMS_CONTENT_FEAT_NAME:
				{
					char *feat_name;
					SObject *featObject;


					/* feature elements are ordered (feat name, feat object),
					 * so we do it in one go
					 */
					read_feature(ebmlReader,
								 &feat_name, S_UTT_EBML_ITEMS_CONTENT_FEAT_NAME,
								 &featObject, S_UTT_EBML_ITEMS_CONTENT_FEAT_OBJECT,
								 error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_item_contents",
								  "Call to \"read_feature\" failed"))
						goto quit_error;

					/* set item content feature */
					SMapSetObject(ic->content->features, feat_name, featObject, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_item_contents",
								  "Call to \"SMapSetObject\" failed"))
						goto quit_error;

					/* feat name is copied */
					S_FREE(feat_name); /* sets to NULL */
					featObject = NULL;
					break;
				}
				default:
					/* unknown elements, skip */
					S_WARNING(S_FAILURE,
							  "read_item_contents",
							  "Skipping element with unknown id '0x%x'",
							  id);

					S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_item_contents",
								  "ebmlRead method \"element_skip\" failed"))
						goto quit_error;
				}
			}
			break;
		}
		default:
			/* unknown elements, skip */
			S_WARNING(S_FAILURE,
					  "read_item_contents",
					  "Skipping element with unknown id '0x%x'",
					  id);

			S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_item_contents",
						  "ebmlRead method \"element_skip\" failed"))
				goto quit_error;
		}
	}

	/* here everything went OK */
	return items_content_table;

	/* errors here, clean up code */
quit_error:
	if (ic != NULL)
	{
		if (ic->content != NULL)
			S_FORCE_DELETE(ic->content, "read_item_contents", error);
		S_FREE(ic);
	}

	if (items_content_table != NULL)
	{
		s_erc local_err = S_SUCCESS;

		s_hash_table_delete(items_content_table, &local_err);
		S_CHK_ERR(&local_err, S_CONTERR,
				  "read_item_contents",
				  "Call to \"s_hash_table_delete\" failed");
	}

	if (item_content_id != NULL)
		S_FREE(item_content_id);

	return NULL;
}
Пример #10
0
static void Initialize(SFeatProcessor *self, const SMap* features, s_erc *error)
{
	S_CLR_ERR(error);

	SPhraseTypeFeatProc *castSelf = S_CAST(self, SPhraseTypeFeatProc, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to S_CAST failed"))
		goto quit_error;

	castSelf->symbols =  S_CAST( SMapGetObject(features , "list definitions", error),
								SMap, error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "Initialize",
			  "Call to \"SMapGetObject\" failed"))
		goto quit_error;

	castSelf->symbols = SMapCopy ( NULL , castSelf->symbols , error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "Initialize",
			  "Call to \"SMapCopy\" failed"))
		goto quit_error;

	/* Get the iterator for the SMap */
	SIterator *itrList = S_ITERATOR_GET(castSelf->symbols, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to \"S_ITERATOR_GET\" failed"))
		goto quit_error;

	while( itrList != NULL ) {

		const char *curStr = SIteratorKey(itrList, error);
		if (S_CHK_ERR(error, S_CONTERR,
			      "Initialize",
			      "Call to \"SIteratorKey\" failed"))
			goto quit_error;

		SList *valueList;
		valueList = S_CAST(SMapGetObject(castSelf->symbols, curStr, error), SList, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetObject\" failed"))
			goto quit_error;

		/* Initializing a new SMap */
		SMap *newCastMap= S_MAP(S_NEW(SMapHashTable, error));

		SIterator *itrValueList = S_ITERATOR_GET(valueList, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"S_ITERATOR_GET\" failed"))
			goto quit_error;

		while(itrValueList != NULL) {
			const SObject *curValueObj = SIteratorObject(itrValueList, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SIteratorObject\" failed"))
				goto quit_error;

			const char *curValueStr = SObjectGetString(curValueObj, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SObjectGetString\" failed"))
				goto quit_error;

			/* Insert the string inside the map */
			SMapSetString(newCastMap, curValueStr, curValueStr, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SMapSetObject\" failed"))
				goto quit_error;

			itrValueList = SIteratorNext(itrValueList);
		}

		/* Insertion of the SMap inside the SMap */
		SMapSetObject(castSelf->symbols, curStr, (SObject *) newCastMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SMapSetObject\" failed"))
				goto quit_error;
		itrList = SIteratorNext(itrList);
	}

	/* error cleanup */
	quit_error:
		return;
}
Пример #11
0
static void Initialize(SUttProcessor *self, const SVoice *voice, s_erc *error)
{
	const SObject *tmp;
	const SMap *syllInfo;
	const char *plugin_name;
	const char *class_name;
	SPlugin *sylPlugin;
	SSyllabification *syllab;


	S_CLR_ERR(error);

	/* check if a syllabification function is defined as a feature,
	 * and if so, create the syllabification object */
	tmp = SMapGetObjectDef(self->features, "syllabification function", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	/* nothing, return */
	if (tmp == NULL)
		return;

	syllInfo = S_CAST(tmp, SMap, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"S_CAST (SMap)\" failed"))
		return;

	plugin_name = SMapGetString(syllInfo, "plug-in", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetString\" failed"))
		return;

	if (plugin_name == NULL)
		return;

	class_name = SMapGetString(syllInfo, "class", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetString\" failed"))
		return;

	if (class_name == NULL)
		return;

	/* load the plug-in */
	sylPlugin = s_pm_load_plugin(plugin_name, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"s_pm_load_plugin\" failed"))
		return;

	/* create a syllabification object */
	syllab = (SSyllabification*)S_NEW_FROM_NAME(class_name, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Failed to create new '%s' object", class_name))
	{
		S_DELETE(sylPlugin, "Initialize", error);
		return;
	}

	/* add them to the features */
	SMapSetObject(self->features, "_syll_func_plugin", S_OBJECT(sylPlugin), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapSetObject\" failed"))
	{
		S_DELETE(syllab, "Initialize", error);
		S_DELETE(sylPlugin, "Initialize", error);
		return;
	}

	SMapSetObject(self->features, "_syll_func", S_OBJECT(syllab), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapSetObject\" failed"))
	{
		/* plugin will be deleted when utt processor is deleted */
		S_DELETE(syllab, "Initialize", error);
		return;
	}

	S_UNUSED(voice);
}
Пример #12
0
S_LOCAL void _s_load_voice_utterance_processors(const SMap *voiceConfig, SVoice *voice, s_erc *error)
{
	SMap *uttProcessors;
	const SObject *tmp;
	const SMap *voiceConfigUttProcessors;
	s_bool key_present;
	SIterator *itr;
	const char *uttproc_name;
	const char *uttproc_class;
	const char *uttproc_plugin;
	const SMap *uttProcInfo;
	const SMap *uttProcFeats;
	SUttProcessor *uProcessor;
	SPlugin *plugin;
	SList *uttProcPlugins;


	S_CLR_ERR(error);

	/* create a map container for utterance-processors */
	uttProcessors = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Failed to create new map for voice utterance-processors"))
		return;

	/* look for "utterance-processors" key in voiceConfig map */
	key_present = SMapObjectPresent(voiceConfig, "utterance-processors", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"SMapObjectPresent\" failed for \'utterance-processors\' key"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	if (!key_present)
	{
		/* no defined utterance-processors  */
		voice->uttProcessors = uttProcessors;
		return;
	}

	/* get utterance-processors from voiceConfig */
	tmp = SMapGetObject(voiceConfig, "utterance-processors", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"SMapGetObject\" failed"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	voiceConfigUttProcessors = S_CAST(tmp, SMap, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"S_CAST (SMap)\" failed for \'utterance-processors\' object"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	/*
	 * iterate through the voiceConfigUttProcessors, create the
	 * utterance-processors and add their features (if any), and add
	 * them to the uttProcessors map
	 */
	itr = S_ITERATOR_GET(voiceConfigUttProcessors, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	if (itr)
	{
		/* create a plug-in list */
		uttProcPlugins = S_LIST(S_NEW(SListList, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Failed to create new list for voice utterance-processor plug-ins"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			return;
		}
	}
	else
		uttProcPlugins = NULL;

	while (itr)
	{
		/* the utterance-processor name */
		uttproc_name = SIteratorKey(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SIteratorKey\" failed"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* the utterance-processor info (SMap) */
		tmp = SIteratorObject(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SIteratorObject\" failed"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uttProcInfo = S_CAST(tmp, SMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"S_CAST (SMap)\" failed for utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/*
		 * uttProcInfo must have "class" and "plug-in" and
		 * optionally "features"
		 */
		uttproc_class = SMapGetString(uttProcInfo, "class", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapGetString\" failed for \'class\' name of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uttproc_plugin = SMapGetString(uttProcInfo, "plug-in", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapGetString\" failed for \'plug-in\' name of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/*
		 * load the plug-in, add it to the list of utterance-processor plug-ins and create
		 * the utterance-processor object
		 */
		plugin = s_pm_load_plugin(uttproc_plugin, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"s_pm_load_plugin\" failed for utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		SListPush(uttProcPlugins, S_OBJECT(plugin), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SListPush\" failed for utterance-processor plug-ins"))
		{
			S_DELETE(plugin, "_s_load_voice_utterance_processors", error);
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uProcessor = S_UTTPROCESSOR(S_NEW_FROM_NAME(uttproc_class, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Failed to create new utterance-processor of class \'%s\'",
					  uttproc_class))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* add the utterance-processor to the map of utterance-processors */
		SMapSetObject(uttProcessors, uttproc_name, S_OBJECT(uProcessor), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapSetObject\" failed"))
		{
			S_DELETE(uProcessor, "_s_load_voice_utterance_processors", error);
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* Check if this utterance-processor has any defined features */
		key_present = SMapObjectPresent(uttProcInfo, "features", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapObjectPresent\" failed for \'features\' key of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		if (key_present)
		{
			/* get utterance-processors "features" */
			tmp = SMapGetObject(uttProcInfo, "features", error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"SMapGetObject\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}

			uttProcFeats = S_CAST(tmp, SMap, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"S_CAST (SMap)\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}

			/* copy them to the utterance-processor */
			SMapCopy(uProcessor->features, uttProcFeats, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"SMapCopy\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}
		}

		/* initialize the utterance processor */
		SUttProcessorInit(&uProcessor, voice, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SUttProcessorInit\" failed for utterance-processor of class \'%s\'",
					  uttproc_class))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		itr = SIteratorNext(itr);
	}

	if (uttProcPlugins != NULL)
	{
		SListMerge(voice->plugins, uttProcPlugins, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SListMerge\" failed"))
		{
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
	}

	voice->uttProcessors = uttProcessors;
}
Пример #13
0
static void read_g2p_rewrites_rules(SG2PRewrites *g2p, SEbmlRead *ebmlReader, s_erc *error)
{
	uint32 id;
	s_bool container_exhausted;
	SList *graphemeRuleList = NULL;
	SG2PRewritesRule *rule = NULL;


	S_CLR_ERR(error);

	/* read S_G2PREWRITES_EBML_RULES_CONTAINER container */
	id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_rules",
				  "ebmlRead method \"container\" failed"))
		return;

	/* create rules SMap */
	g2p->rules = S_MAP(S_NEW(SMapHashTable, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_rules",
				  "Failed to create new 'SMap' object"))
		return;

	/* 64 should be enough for graphemes */
	SMapHashTableResize(S_MAPHASHTABLE(g2p->rules), 64, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_rules",
				  "Call to \"SMapHashTableResize\" failed"))
	{
		S_DELETE(g2p->rules, "read_g2p_rewrites_rules", error);
		return;
	}

	while (1)
	{
		container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_rules",
					  "ebmlRead method \"container_at_end\" failed"))
			return;

		if (container_exhausted)
			break;

		/* peek id  */
		id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_rules",
					  "ebmlRead method \"peek_id\" failed"))
			return;

		switch(id)
		{
		case S_G2PREWRITES_EBML_RULES_GRAPHEME:
		{
			char *grapheme;


			grapheme = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "ebmlRead method \"read_utf8\" failed"))
				return;

			/* create rule list for this grapheme */
			graphemeRuleList = S_LIST(S_NEW(SListList, error));
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "Failed to create new 'SList' object"))
				return;

			/* add it to the rules SMap */
			SMapSetObject(g2p->rules, grapheme, S_OBJECT(graphemeRuleList), error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "Call to \"SMapSetObject\" failed"))
			{
				S_DELETE(graphemeRuleList, "read_g2p_rewrites_rules", error);
				S_FREE(grapheme);
				return;
			}

			S_FREE(grapheme);
			break;
		}
		case S_G2PREWRITES_EBML_SINGLE_RULE_CONTAINER:
		{
			/* read S_G2PREWRITES_EBML_SINGLE_RULE_CONTAINER container */
			id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "ebmlRead method \"container\" failed"))
				return;

			while (1)
			{
				container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "read_g2p_rewrites_rules",
							  "ebmlRead method \"container_at_end\" failed"))
					return;

				if (container_exhausted)
					break;

				/* peek id  */
				id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "read_g2p_rewrites_rules",
							  "ebmlRead method \"peek_id\" failed"))
					return;

				switch(id)
				{
				case S_G2PREWRITES_EBML_SINGLE_RULE_LEFT_CONTEXT:
				{
					/* elements are ordered so we create a rule here */
					rule = S_NEW(SG2PRewritesRule, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "Failed to create new 'SG2PRewritesRule' object"))
						return;

					/* add it to the list */
					SListAppend(graphemeRuleList, S_OBJECT(rule), error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "Call to \"SListAppend\" failed"))
					{
						S_DELETE(rule, "read_g2p_rewrites_rules", error);
						return;
					}

					rule->left_context = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id,
																				error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "ebmlRead method \"read_utf8\" failed"))
						return;



					break;
				}
				case S_G2PREWRITES_EBML_SINGLE_RULE_RIGHT_CONTEXT:
				{
					rule->right_context = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id,
																				 error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "ebmlRead method \"read_utf8\" failed"))
						return;

					break;
				}
				case S_G2PREWRITES_EBML_SINGLE_RULE_PHONEME:
				{
					rule->phone = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id,
																		 error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "ebmlRead method \"read_utf8\" failed"))
						return;

					break;
				}
				default:
					/* unknown elements, skip */
					S_WARNING(S_FAILURE,
							  "read_g2p_rewrites_rules",
							  "Skipping element with unknown id '0x%x'",
							  id);

					S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "ebmlRead method \"element_skip\" failed"))
						return;
				}
			}
			break;
		}
		default:
			/* unknown elements, skip */
			S_WARNING(S_FAILURE,
					  "read_g2p_rewrites_rules",
					  "Skipping element with unknown id '0x%x'",
					  id);

			S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "ebmlRead method \"element_skip\" failed"))
				return;
		}
	}

	return;
}
Пример #14
0
S_API void SVoiceSetData(SVoice *self, const char *key,
						 SObject *object,  s_erc *error)
{
	s_bool key_present;
	s_bool vm_loaded_data;



	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetData",
				  "Argument \"self\" is NULL");
		return;
	}

	if (key == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetData",
				  "Argument \"key\" is NULL");
		return;
	}

	if (object == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "SVoiceSetData",
				  "Argument \"object\" is NULL");
		return;
	}

	s_mutex_lock(&self->voice_mutex);

	/* check if the data is in the data objects map */
	key_present = SMapObjectPresent(self->data->dataObjects, key, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "SVoiceSetData",
				  "Call to \"SMapObjectPresent\" failed"))
	{
		s_mutex_unlock(&self->voice_mutex);
		return;
	}

	if (key_present)
	{
		/* delete the data and config key */
		unload_data_entry(self, key, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "SVoiceSetData",
					  "Call to \"unload_data_entry\" failed"))
		{
			s_mutex_unlock(&self->voice_mutex);
			return;
		}
	}

	vm_loaded_data = _s_vm_data_loaded_inc_ref(object, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "SVoiceSetData",
				  "Call to \"_s_vm_data_loaded_inc_ref\" failed"))
	{
		s_mutex_unlock(&self->voice_mutex);
		return;
	}

	if (vm_loaded_data)
	{
		/* it was loaded previously by vm, just incremented reference
		 * in _s_vm_data_loaded_inc_ref. Set it in data objects and
		 * return.
		 */
		SMapSetObject(self->data->dataObjects, key, object, error);
		S_CHK_ERR(error, S_CONTERR,
				  "SVoiceSetData",
				  "Call to \"SMapSetObject\" for data '%s' in data config failed",
				  key); /* data is probably corrupted */
		s_mutex_unlock(&self->voice_mutex);
		return;
	}

	/* not previously loaded in voice manager */
	SMapSetObject(self->data->dataObjects, key, object, error);
	S_CHK_ERR(error, S_CONTERR,
			  "SVoiceSetData",
			  "Call to \"SMapSetObject\" failed");

	s_mutex_unlock(&self->voice_mutex);
}
Пример #15
0
S_LOCAL void _s_voice_load_data(SVoice *self, const SMap *dataConfig, s_erc *error)
{
	SIterator *itr;
	const char *data_name;
	const SObject *loaded;
	const SMap *dataObjectMap;
	s_data_info *data_info;
	const SObject *vcfgObject;
	char *voice_base_path;


	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "_s_voice_load_data",
				  "Argument \"self\" is NULL");
		return;
	}

	/* get voice base path */
	vcfgObject = SVoiceGetFeature(self, "config_file", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_voice_load_data",
				  "Call to \"SVoiceGetFeature\" failed, failed to get voice config file"))
		return;

	voice_base_path = s_get_base_path(SObjectGetString(vcfgObject, error), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_voice_load_data",
				  "Call to \"s_get_base_path/SObjectGetString\" failed"))
		return;

	/*
	 * now iterate through data config and load everything
	 */
	itr = S_ITERATOR_GET(dataConfig, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_voice_load_data",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_DELETE(itr, "_s_voice_load_data", error);
		S_FREE(voice_base_path);
		return;
	}

	while (itr)
	{
		char *combined_path;


		data_name = SIteratorKey(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SIteratorKey\" failed"))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		/*
		 * We have already checked this cast in
		 * _s_voice_load_dataConfig (_s_load_voice_data_config)
		 */
		dataObjectMap = (const SMap*)SMapGetObjectDef(dataConfig, data_name, NULL, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SMapGetObjectDef\" for data '%s' failed",
					  data_name))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		if (dataObjectMap == NULL)
		{
			S_CTX_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Data object map for data '%s' in data config in NULL",
					  data_name);
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		data_info = get_data_info(dataObjectMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"get_data_info\" for data '%s' in data config failed",
					  data_name))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		/* get data path, the one in the config file may be relative
		 * to the voice base path
		 */
		combined_path = s_path_combine(voice_base_path, data_info->path,
									   error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"s_path_combine\" failed"))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		loaded = _s_vm_load_data(data_info->plugin, combined_path,
								 data_info->format, error);
		S_FREE(combined_path);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"_s_vm_load_data\" for data '%s' in data config failed",
					  data_name))
		{
			S_FREE(data_info);
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		S_FREE(data_info);

		SMapSetObject(self->data->dataObjects, data_name, loaded, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SMapSetObject\" for data '%s' in data config failed",
					  data_name))
		{
			s_erc local_err = S_SUCCESS;


			S_FREE(voice_base_path);
			S_DELETE(itr, "_s_voice_load_data", error);
			_s_vm_unload_data((SObject*)loaded, &local_err); /* error is already set */
			return;
		}

		itr = SIteratorNext(itr);
	}

	S_FREE(voice_base_path);
}