aboutsummaryrefslogtreecommitdiff
path: root/servers/audio/sample_manager_sw.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--servers/audio/sample_manager_sw.cpp159
1 files changed, 69 insertions, 90 deletions
diff --git a/servers/audio/sample_manager_sw.cpp b/servers/audio/sample_manager_sw.cpp
index 623bb0f9c..b28291165 100644
--- a/servers/audio/sample_manager_sw.cpp
+++ b/servers/audio/sample_manager_sw.cpp
@@ -30,36 +30,33 @@
#include "print_string.h"
-SampleManagerSW::~SampleManagerSW()
-{
+SampleManagerSW::~SampleManagerSW() {
}
-
-
RID SampleManagerMallocSW::sample_create(AS::SampleFormat p_format, bool p_stereo, int p_length) {
- Sample *s = memnew( Sample );
+ Sample *s = memnew(Sample);
int datalen = p_length;
- if (p_format==AS::SAMPLE_FORMAT_PCM16)
- datalen*=2;
- else if (p_format==AS::SAMPLE_FORMAT_IMA_ADPCM) {
- if (datalen&1) {
+ if (p_format == AS::SAMPLE_FORMAT_PCM16)
+ datalen *= 2;
+ else if (p_format == AS::SAMPLE_FORMAT_IMA_ADPCM) {
+ if (datalen & 1) {
datalen++;
}
- datalen/=2;
- datalen+=4;
+ datalen /= 2;
+ datalen += 4;
}
if (p_stereo)
- datalen*=2;
+ datalen *= 2;
#define SAMPLE_EXTRA 16
- s->data = memalloc(datalen+SAMPLE_EXTRA); //help the interpolator by allocating a little more..
- for(int i=0;i<SAMPLE_EXTRA;i++) {
+ s->data = memalloc(datalen + SAMPLE_EXTRA); //help the interpolator by allocating a little more..
+ for (int i = 0; i < SAMPLE_EXTRA; i++) {
- uint8_t *data = (uint8_t*)s->data;
- data[datalen+i]=0;
+ uint8_t *data = (uint8_t *)s->data;
+ data[datalen + i] = 0;
}
if (!s->data) {
@@ -68,14 +65,14 @@ RID SampleManagerMallocSW::sample_create(AS::SampleFormat p_format, bool p_stere
ERR_FAIL_V(RID());
}
- s->format=p_format;
- s->length=p_length;
- s->length_bytes=datalen;
- s->stereo=p_stereo;
- s->loop_begin=0;
- s->loop_end=0;
- s->loop_format=AS::SAMPLE_LOOP_NONE;
- s->mix_rate=44100;
+ s->format = p_format;
+ s->length = p_length;
+ s->length_bytes = datalen;
+ s->stereo = p_stereo;
+ s->loop_begin = 0;
+ s->loop_end = 0;
+ s->loop_format = AS::SAMPLE_LOOP_NONE;
+ s->mix_rate = 44100;
AudioServer::get_singleton()->lock();
RID rid = sample_owner.make_rid(s);
@@ -84,27 +81,26 @@ RID SampleManagerMallocSW::sample_create(AS::SampleFormat p_format, bool p_stere
return rid;
}
-void SampleManagerMallocSW::sample_set_description(RID p_sample, const String& p_description) {
+void SampleManagerMallocSW::sample_set_description(RID p_sample, const String &p_description) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- s->description=p_description;
+ s->description = p_description;
}
String SampleManagerMallocSW::sample_get_description(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,String());
+ ERR_FAIL_COND_V(!s, String());
return s->description;
}
-
AS::SampleFormat SampleManagerMallocSW::sample_get_format(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,AS::SAMPLE_FORMAT_PCM8);
+ ERR_FAIL_COND_V(!s, AS::SAMPLE_FORMAT_PCM8);
return s->format;
}
@@ -112,89 +108,83 @@ AS::SampleFormat SampleManagerMallocSW::sample_get_format(RID p_sample) const {
bool SampleManagerMallocSW::sample_is_stereo(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,false);
+ ERR_FAIL_COND_V(!s, false);
return s->stereo;
-
}
int SampleManagerMallocSW::sample_get_length(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,-1);
+ ERR_FAIL_COND_V(!s, -1);
return s->length;
}
-void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer) {
+void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t> &p_buffer) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- int buff_size=p_buffer.size();
- ERR_FAIL_COND(buff_size==0);
-
+ int buff_size = p_buffer.size();
+ ERR_FAIL_COND(buff_size == 0);
ERR_EXPLAIN("Sample buffer size does not match sample size.");
//print_line("len bytes: "+itos(s->length_bytes)+" bufsize: "+itos(buff_size));
- ERR_FAIL_COND(s->length_bytes!=buff_size);
- DVector<uint8_t>::Read buffer_r=p_buffer.read();
+ ERR_FAIL_COND(s->length_bytes != buff_size);
+ DVector<uint8_t>::Read buffer_r = p_buffer.read();
const uint8_t *src = buffer_r.ptr();
- uint8_t *dst = (uint8_t*)s->data;
+ uint8_t *dst = (uint8_t *)s->data;
//print_line("set data: "+itos(s->length_bytes));
- for(int i=0;i<s->length_bytes;i++) {
+ for (int i = 0; i < s->length_bytes; i++) {
- dst[i]=src[i];
+ dst[i] = src[i];
}
- switch(s->format) {
+ switch (s->format) {
case AS::SAMPLE_FORMAT_PCM8: {
if (s->stereo) {
- dst[s->length]=dst[s->length-2];
- dst[s->length+1]=dst[s->length-1];
+ dst[s->length] = dst[s->length - 2];
+ dst[s->length + 1] = dst[s->length - 1];
} else {
- dst[s->length]=dst[s->length-1];
+ dst[s->length] = dst[s->length - 1];
}
} break;
case AS::SAMPLE_FORMAT_PCM16: {
if (s->stereo) {
- dst[s->length]=dst[s->length-4];
- dst[s->length+1]=dst[s->length-3];
- dst[s->length+2]=dst[s->length-2];
- dst[s->length+3]=dst[s->length-1];
+ dst[s->length] = dst[s->length - 4];
+ dst[s->length + 1] = dst[s->length - 3];
+ dst[s->length + 2] = dst[s->length - 2];
+ dst[s->length + 3] = dst[s->length - 1];
} else {
- dst[s->length]=dst[s->length-2];
- dst[s->length+1]=dst[s->length-1];
+ dst[s->length] = dst[s->length - 2];
+ dst[s->length + 1] = dst[s->length - 1];
}
} break;
-
}
-
-
-
}
const DVector<uint8_t> SampleManagerMallocSW::sample_get_data(RID p_sample) const {
Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,DVector<uint8_t>());
+ ERR_FAIL_COND_V(!s, DVector<uint8_t>());
DVector<uint8_t> ret_buffer;
ret_buffer.resize(s->length_bytes);
- DVector<uint8_t>::Write buffer_w=ret_buffer.write();
+ DVector<uint8_t>::Write buffer_w = ret_buffer.write();
uint8_t *dst = buffer_w.ptr();
- const uint8_t *src = (const uint8_t*)s->data;
+ const uint8_t *src = (const uint8_t *)s->data;
- for(int i=0;i<s->length_bytes;i++) {
+ for (int i = 0; i < s->length_bytes; i++) {
- dst[i]=src[i];
+ dst[i] = src[i];
}
buffer_w = DVector<uint8_t>::Write(); //unlock
@@ -205,76 +195,70 @@ const DVector<uint8_t> SampleManagerMallocSW::sample_get_data(RID p_sample) cons
void *SampleManagerMallocSW::sample_get_data_ptr(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,NULL);
+ ERR_FAIL_COND_V(!s, NULL);
return s->data;
-
}
-void SampleManagerMallocSW::sample_set_mix_rate(RID p_sample,int p_rate) {
+void SampleManagerMallocSW::sample_set_mix_rate(RID p_sample, int p_rate) {
- ERR_FAIL_COND(p_rate<1);
+ ERR_FAIL_COND(p_rate < 1);
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- s->mix_rate=p_rate;
-
-
+ s->mix_rate = p_rate;
}
int SampleManagerMallocSW::sample_get_mix_rate(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,-1);
+ ERR_FAIL_COND_V(!s, -1);
return s->mix_rate;
-
}
-void SampleManagerMallocSW::sample_set_loop_format(RID p_sample,AS::SampleLoopFormat p_format) {
+void SampleManagerMallocSW::sample_set_loop_format(RID p_sample, AS::SampleLoopFormat p_format) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- s->loop_format=p_format;
-
+ s->loop_format = p_format;
}
AS::SampleLoopFormat SampleManagerMallocSW::sample_get_loop_format(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,AS::SAMPLE_LOOP_NONE);
+ ERR_FAIL_COND_V(!s, AS::SAMPLE_LOOP_NONE);
return s->loop_format;
}
-void SampleManagerMallocSW::sample_set_loop_begin(RID p_sample,int p_pos) {
+void SampleManagerMallocSW::sample_set_loop_begin(RID p_sample, int p_pos) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- ERR_FAIL_INDEX(p_pos,s->length);
+ ERR_FAIL_INDEX(p_pos, s->length);
- s->loop_begin=p_pos;
+ s->loop_begin = p_pos;
}
int SampleManagerMallocSW::sample_get_loop_begin(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,-1);
+ ERR_FAIL_COND_V(!s, -1);
return s->loop_begin;
}
-void SampleManagerMallocSW::sample_set_loop_end(RID p_sample,int p_pos) {
+void SampleManagerMallocSW::sample_set_loop_end(RID p_sample, int p_pos) {
Sample *s = sample_owner.get(p_sample);
ERR_FAIL_COND(!s);
- if (p_pos>s->length)
- p_pos=s->length;
- s->loop_end=p_pos;
-
+ if (p_pos > s->length)
+ p_pos = s->length;
+ s->loop_end = p_pos;
}
int SampleManagerMallocSW::sample_get_loop_end(RID p_sample) const {
const Sample *s = sample_owner.get(p_sample);
- ERR_FAIL_COND_V(!s,-1);
+ ERR_FAIL_COND_V(!s, -1);
return s->loop_end;
}
@@ -282,7 +266,6 @@ int SampleManagerMallocSW::sample_get_loop_end(RID p_sample) const {
bool SampleManagerMallocSW::is_sample(RID p_sample) const {
return sample_owner.owns(p_sample);
-
}
void SampleManagerMallocSW::free(RID p_sample) {
@@ -294,12 +277,9 @@ void SampleManagerMallocSW::free(RID p_sample) {
memfree(s->data);
memdelete(s);
-
}
SampleManagerMallocSW::SampleManagerMallocSW() {
-
-
}
SampleManagerMallocSW::~SampleManagerMallocSW() {
@@ -308,13 +288,12 @@ SampleManagerMallocSW::~SampleManagerMallocSW() {
List<RID> owned_list;
sample_owner.get_owned_list(&owned_list);
- while(owned_list.size()) {
+ while (owned_list.size()) {
Sample *s = sample_owner.get(owned_list.front()->get());
- String err="Leaked sample of size: "+itos(s->length_bytes)+" description: "+s->description;
+ String err = "Leaked sample of size: " + itos(s->length_bytes) + " description: " + s->description;
ERR_PRINT(err.utf8().get_data());
free(owned_list.front()->get());
owned_list.pop_front();
}
-
}