/* SpiralLoops * Copyleft (C) 2000 David Griffiths * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "Sample.h" #include Sample::Sample(int Len) : m_IsEmpty(true), m_DataGranularity(1),//512), m_Data(NULL), m_Length(0) { if (Len) { Allocate(Len); } } Sample::Sample(const Sample &rhs): m_IsEmpty(true), m_DataGranularity(512), m_Data(NULL), m_Length(0) { *this=rhs; } Sample::Sample(const float *S, int Len): m_IsEmpty(false), m_DataGranularity(512), m_Data(NULL), m_Length(0) { assert(S); Allocate(Len); memcpy(m_Data,S,GetLengthInBytes()); } Sample::~Sample() { Clear(); } bool Sample::Allocate(int Size) { Clear(); m_Data = new float[Size]; m_Length=Size; memset(m_Data,0,GetLengthInBytes()); return (m_Data); } void Sample::Clear() { m_IsEmpty=true; if (m_Data) { delete[] m_Data; m_Length=0; m_Data=NULL; } } void Sample::Zero() { m_IsEmpty=true; memset(m_Data,0,GetLengthInBytes()); } void Sample::Set(float Val) { m_IsEmpty=false; for (int n=0; nGetLength()) ToPos=0; ToPos++; } } void Sample::Remove(int Start, int End) { // do some checking assert(EndGetLength()) End=GetLength(); if (Start<0) Start=0; // calc lengths and allocate memory int CutLen = End - Start; // has to be granulated by the buffer size CutLen-=CutLen % m_DataGranularity; int NewLen = GetLength()-CutLen; float *TempBuf = new float[NewLen]; int ToPos=0; for (int FromPos=0; FromPosEnd) { TempBuf[ToPos]=m_Data[FromPos]; ToPos++; // check the position is in range of the calculated length assert(ToPos<=NewLen); } } Clear(); m_Data=TempBuf; m_Length=NewLen; } void Sample::Reverse(int Start, int End) { // do some checking assert(EndGetLength()) End=GetLength(); int NewLen = End-Start; float *TempBuf = new float[NewLen]; int ToPos=0; int FromPos=0; // get the reversed sample for (FromPos=End; FromPos>Start; FromPos--) { TempBuf[ToPos]=m_Data[FromPos]; ToPos++; assert(ToPos<=NewLen); } FromPos=0; // overwrite back into place for (ToPos=Start; ToPosLength) FromPos-=Length; // get the offset sample for (ToPos=0; ToPos=Length) FromPos=0; } Clear(); m_Data=TempBuf; m_Length=Length; } void Sample::GetRegion(Sample &S, int Start, int End) { // do some checking assert(End0 && NewLength<=GetLength()); float *temp = new float[NewLength]; for(int n=0; n