xue@11: /* xue@11: Harmonic sinusoidal modelling and tools xue@11: xue@11: C++ code package for harmonic sinusoidal modelling and relevant signal processing. xue@11: Centre for Digital Music, Queen Mary, University of London. xue@11: This file copyright 2011 Wen Xue. xue@11: xue@11: This program is free software; you can redistribute it and/or xue@11: modify it under the terms of the GNU General Public License as xue@11: published by the Free Software Foundation; either version 2 of the xue@11: License, or (at your option) any later version. xue@11: */ xue@1: //--------------------------------------------------------------------------- xue@1: xue@1: xue@1: #include xue@1: #include xue@1: #include "align8.h" xue@1: xue@1: //--------------------------------------------------------------------------- xue@1: /* xue@1: function malloc8: 8-byte (64-bit) aligned memory allocation. xue@1: xue@1: Returns pointer to a memory block of $size starting at an address divisible by 8. xue@1: */ xue@1: void* malloc8(unsigned size) xue@1: { Chris@4: #if (!defined(__SIZEOF_POINTER__) || (__SIZEOF_POINTER__ == 4)) xue@1: char *buffer, *result; xue@1: buffer=(char*)malloc(size+8+sizeof(void*)); xue@1: if(!buffer) return(NULL); xue@1: char* tmp=&buffer[sizeof(void*)]; xue@1: result=&((char*)((unsigned)tmp&0xFFFFFFF8))[8]; xue@1: ((void**)result)[-1]=buffer; xue@1: return(result); Chris@4: #else Chris@4: return malloc(size); Chris@4: #endif xue@1: }//malloc8 xue@1: xue@1: /* xue@1: function free8: deallocation for malloc8() xue@1: xue@1: No return value. xue@1: */ xue@1: void free8(void* buffer8) xue@1: { Chris@4: #if (!defined(__SIZEOF_POINTER__) || (__SIZEOF_POINTER__ == 4)) Chris@4: if (buffer8) free(((void**)buffer8)[-1]); Chris@4: #else Chris@4: free(buffer8); Chris@4: #endif xue@1: }//free8 Chris@4: