Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-04-17 14:21:29 +0000
committerStijn Buys <ingar@osirion.org>2011-04-17 14:21:29 +0000
commit09d68d3d1d77d45343e3562c0b5e0cd6816d47d3 (patch)
tree6b89c585fe8cd8bd49699cdb349566d3f382010e /src/audio/pcm.cc
parent8264546908f1722b4d0f0e91c42dd791ba8535c4 (diff)
Initial Ogg Vorbis sounds effect support.
Diffstat (limited to 'src/audio/pcm.cc')
-rw-r--r--src/audio/pcm.cc31
1 files changed, 27 insertions, 4 deletions
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 <stdlib.h>
#include <string.h>
+#include <cassert>
+
#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