From 09d68d3d1d77d45343e3562c0b5e0cd6816d47d3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 17 Apr 2011 14:21:29 +0000 Subject: Initial Ogg Vorbis sounds effect support. --- src/audio/pcm.cc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/audio/pcm.cc') diff --git a/src/audio/pcm.cc b/src/audio/pcm.cc index b04e080..2ef7381 100644 --- a/src/audio/pcm.cc +++ b/src/audio/pcm.cc @@ -7,6 +7,8 @@ #include #include +#include + #include "audio/pcm.h" #include "audio/wavfile.h" @@ -15,12 +17,12 @@ 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_size = size; pcm_channels = channels; - - pcm_data = (unsigned char *) malloc(pcm_size); + pcm_data = (unsigned char *) malloc(pcm_buff_size); clear(); } @@ -31,7 +33,28 @@ PCM::~PCM() void PCM::clear() { - memset(pcm_data, 0, pcm_size); + 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 -- cgit v1.2.3