/* * $Id$ * * ***** BEGIN LGPL LICENSE BLOCK ***** * * Copyright 2009 Jörg Hermann Müller * * This file is part of SoundSpace. * * SoundSpace is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SoundSpace 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with SoundSpace. If not, see . * * ***** END LGPL LICENSE BLOCK ***** */ #include "SND_Buffer.h" #include "SND_Space.h" #include #include #define SND_ALIGN(a) (a + 16 - ((long)a & 15)) SND_Buffer::SND_Buffer(int size) { m_size = size; m_buffer = (unsigned char*) malloc(size+15); } SND_Buffer::~SND_Buffer() { free(m_buffer); } unsigned char* SND_Buffer::getBuffer() { return SND_ALIGN(m_buffer); } int SND_Buffer::getSize() { return m_size; } void SND_Buffer::resize(int size, bool keep) { unsigned char* buffer = (unsigned char*) malloc(size+15); // copy old data over if wanted if(keep) memcpy(SND_ALIGN(buffer), SND_ALIGN(m_buffer), SND_MIN(size, m_size)); free(m_buffer); m_buffer = buffer; m_size = size; }