/* audio/pcm.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include #include #include #include "audio/pcm.h" namespace audio { PCM::PCM(unsigned int samplerate, unsigned int bitspersample, unsigned int channels, size_t size) { pcm_size = size; pcm_buff_size = size; pcm_bitspersample = bitspersample; pcm_samplerate = samplerate; pcm_channels = channels; pcm_data = (unsigned char *) malloc(pcm_buff_size); clear(); } PCM::~PCM() { free(pcm_data); } void PCM::clear() { memset(pcm_data, 0, pcm_buff_size); } void PCM::set_size(size_t size) { assert(size <= pcm_buff_size); pcm_size = size; } void PCM::grow(size_t size) { assert (size >= pcm_buff_size); // store a pointer to the previous buffer unsigned char *old_data = pcm_data; // allocate a new, larger buffer pcm_buff_size = size; pcm_data = (unsigned char *) malloc(pcm_buff_size); // copy the content memcpy(pcm_data, old_data, pcm_size); free(old_data); } } // namespace audio