153a5a1b3Sopenharmony_ci/* Copyright (C) 2007 Hong Zhiqian */
253a5a1b3Sopenharmony_ci/**
353a5a1b3Sopenharmony_ci   @file misc_tm.h
453a5a1b3Sopenharmony_ci   @author Hong Zhiqian
553a5a1b3Sopenharmony_ci   @brief Various compatibility routines for Speex (TriMedia version)
653a5a1b3Sopenharmony_ci*/
753a5a1b3Sopenharmony_ci/*
853a5a1b3Sopenharmony_ci   Redistribution and use in source and binary forms, with or without
953a5a1b3Sopenharmony_ci   modification, are permitted provided that the following conditions
1053a5a1b3Sopenharmony_ci   are met:
1153a5a1b3Sopenharmony_ci
1253a5a1b3Sopenharmony_ci   - Redistributions of source code must retain the above copyright
1353a5a1b3Sopenharmony_ci   notice, this list of conditions and the following disclaimer.
1453a5a1b3Sopenharmony_ci
1553a5a1b3Sopenharmony_ci   - Redistributions in binary form must reproduce the above copyright
1653a5a1b3Sopenharmony_ci   notice, this list of conditions and the following disclaimer in the
1753a5a1b3Sopenharmony_ci   documentation and/or other materials provided with the distribution.
1853a5a1b3Sopenharmony_ci
1953a5a1b3Sopenharmony_ci   - Neither the name of the Xiph.org Foundation nor the names of its
2053a5a1b3Sopenharmony_ci   contributors may be used to endorse or promote products derived from
2153a5a1b3Sopenharmony_ci   this software without specific prior written permission.
2253a5a1b3Sopenharmony_ci
2353a5a1b3Sopenharmony_ci   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2453a5a1b3Sopenharmony_ci   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2553a5a1b3Sopenharmony_ci   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2653a5a1b3Sopenharmony_ci   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
2753a5a1b3Sopenharmony_ci   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2853a5a1b3Sopenharmony_ci   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2953a5a1b3Sopenharmony_ci   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3053a5a1b3Sopenharmony_ci   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3153a5a1b3Sopenharmony_ci   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3253a5a1b3Sopenharmony_ci   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3353a5a1b3Sopenharmony_ci   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3453a5a1b3Sopenharmony_ci*/
3553a5a1b3Sopenharmony_ci#include <tmml.h>
3653a5a1b3Sopenharmony_ci
3753a5a1b3Sopenharmony_ci
3853a5a1b3Sopenharmony_ci#if TM_PROFILE
3953a5a1b3Sopenharmony_ciint __profile_begin;
4053a5a1b3Sopenharmony_ciint __profile_end;
4153a5a1b3Sopenharmony_ci#endif
4253a5a1b3Sopenharmony_ci
4353a5a1b3Sopenharmony_ci#define OVERRIDE_SPEEX_ALLOC
4453a5a1b3Sopenharmony_civoid *speex_alloc (int size)
4553a5a1b3Sopenharmony_ci{
4653a5a1b3Sopenharmony_ci	void *ptr;
4753a5a1b3Sopenharmony_ci
4853a5a1b3Sopenharmony_ci	if ( tmmlMalloc(0, size, (pVoid*)&ptr, tmmlMallocCacheAligned | tmmlMallocCleared) != TM_OK )
4953a5a1b3Sopenharmony_ci	{	return NULL;
5053a5a1b3Sopenharmony_ci	}
5153a5a1b3Sopenharmony_ci
5253a5a1b3Sopenharmony_ci	return ptr;
5353a5a1b3Sopenharmony_ci}
5453a5a1b3Sopenharmony_ci
5553a5a1b3Sopenharmony_ci
5653a5a1b3Sopenharmony_ci#define OVERRIDE_SPEEX_ALLOC_SCRATCH
5753a5a1b3Sopenharmony_civoid *speex_alloc_scratch (int size)
5853a5a1b3Sopenharmony_ci{
5953a5a1b3Sopenharmony_ci	void *ptr;
6053a5a1b3Sopenharmony_ci
6153a5a1b3Sopenharmony_ci	if ( tmmlMalloc(0, size, (pVoid*)&ptr, tmmlMallocCacheAligned | tmmlMallocCleared) != TM_OK )
6253a5a1b3Sopenharmony_ci	{	return NULL;
6353a5a1b3Sopenharmony_ci	}
6453a5a1b3Sopenharmony_ci
6553a5a1b3Sopenharmony_ci	return ptr;
6653a5a1b3Sopenharmony_ci}
6753a5a1b3Sopenharmony_ci
6853a5a1b3Sopenharmony_ci
6953a5a1b3Sopenharmony_ci#define OVERRIDE_SPEEX_REALLOC
7053a5a1b3Sopenharmony_civoid *speex_realloc (void *ptr, int size)
7153a5a1b3Sopenharmony_ci{
7253a5a1b3Sopenharmony_ci	if ( tmmlRealloc(0, size, (pVoid)ptr, (pVoid*)&ptr, tmmlMallocCacheAligned | tmmlMallocCleared) != TM_OK )
7353a5a1b3Sopenharmony_ci	{	return NULL;
7453a5a1b3Sopenharmony_ci	}
7553a5a1b3Sopenharmony_ci
7653a5a1b3Sopenharmony_ci	return ptr;
7753a5a1b3Sopenharmony_ci}
7853a5a1b3Sopenharmony_ci
7953a5a1b3Sopenharmony_ci
8053a5a1b3Sopenharmony_ci#define OVERRIDE_SPEEX_FREE
8153a5a1b3Sopenharmony_civoid speex_free (void *ptr)
8253a5a1b3Sopenharmony_ci{
8353a5a1b3Sopenharmony_ci	tmmlFree(ptr);
8453a5a1b3Sopenharmony_ci}
8553a5a1b3Sopenharmony_ci
8653a5a1b3Sopenharmony_ci
8753a5a1b3Sopenharmony_ci#define OVERRIDE_SPEEX_FREE_SCRATCH
8853a5a1b3Sopenharmony_civoid speex_free_scratch (void *ptr)
8953a5a1b3Sopenharmony_ci{
9053a5a1b3Sopenharmony_ci	tmmlFree(ptr);
9153a5a1b3Sopenharmony_ci}
9253a5a1b3Sopenharmony_ci
93