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: #ifndef ARRAYALLOC xue@1: #define ARRAYALLOC xue@1: Chris@5: /** Chris@5: \file arrayalloc.h - 2D, 3D and 4D array memory allocation routines. xue@1: xue@1: An x-dimensional array (x=2, 3, 4, ...) is managed as a single memory block hosting all records, plus xue@1: an index block which is a (x-1)D array itself. Therefore a 2D array is allocated as two 1D arrays, a xue@1: 3D array is allocated as three 1D arrays, etc. xue@1: xue@1: Examples: xue@1: Alloc2(4, N, x) declares an array x[4][N] of double-precision floating points. xue@1: Allocate3(int, K, L, M, x) allocates an array x[K][L][M] of integers and returns x as int***. xue@1: xue@1: This file also includes a garbage collector class MList that works with arrays allcoated in this way. xue@1: */ xue@1: xue@1: xue@1: #include xue@1: xue@1: //2D array allocation macros for declaring an array of double xue@1: #define Alloc2(M, N, x) \ xue@1: double **x=new double*[M]; x[0]=new double[(M)*(N)]; for (int _z=1; _zAdd(x, 2); xue@1: //2D array allocation macros for all data types xue@1: #define Allocate2(INT, M, N, x) \ xue@1: x=new INT*[M]; x[0]=new INT[(M)*(N)]; for (int _z=1; _zAdd(x, 2); xue@1: //2D array deallocation macro xue@1: #define DeAlloc2(x) {if (x) {delete[] (char*)(x[0]); delete[] x; x=0;}} xue@1: xue@1: //3D array allocation macro for declaring an array of double xue@1: #define Alloc3(L, M, N, x) \ xue@1: double*** x=new double**[L]; x[0]=new double*[(L)*(M)]; x[0][0]=new double[(L)*(M)*(N)]; \ xue@1: for (int _z=0; _zAdd(x, 3); xue@1: //3D array deallocation macro xue@1: #define DeAlloc3(x) {if (x) {delete[] (char*)(x[0][0]); delete[] x[0]; delete[] x; x=0;}} xue@1: xue@1: //4D array allocation macro for declaring an array of double xue@1: #define Alloc4(L, M, N, O, x) \ xue@1: double**** x=new double***[L]; x[0]=new double**[(L)*(M)]; \ xue@1: x[0][0]=new double*[(L)*(M)*(N)]; x[0][0][0]=new double[(L)*(M)*(N)*(O)]; \ xue@1: for (int _z=0; _z