summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2015-12-29 16:06:45 -0300
committerreduz <reduzio@gmail.com>2015-12-29 16:06:45 -0300
commit875bff2c4e95e63c0eeca9d3fbe28bae79095a64 (patch)
tree547836e141ed43e0cd1538aa5a71dbdd0fb2a04d /drivers
parent101fe4b845c9f831498461c4d3dae050f8c159fc (diff)
-fix loading of samples in mod, s3m and xm. Fixes #2553
Diffstat (limited to 'drivers')
-rw-r--r--drivers/chibi/cp_loader_mod.cpp9
-rw-r--r--drivers/chibi/cp_loader_s3m.cpp20
-rw-r--r--drivers/chibi/cp_loader_xm.cpp16
3 files changed, 30 insertions, 15 deletions
diff --git a/drivers/chibi/cp_loader_mod.cpp b/drivers/chibi/cp_loader_mod.cpp
index 98174ff9b1..6340a6f5ea 100644
--- a/drivers/chibi/cp_loader_mod.cpp
+++ b/drivers/chibi/cp_loader_mod.cpp
@@ -446,18 +446,19 @@ CPLoader::Error CPLoader_MOD::load_song(const char *p_file,CPSong *p_song,bool p
if (sid.is_null()) {
continue; //empty sample, not stored?
}
-
+ sm->lock_data(sid);
+ uint8_t *dataptr = (uint8_t*)sm->get_data(sid);
+
int len=sm->get_size(sid);
for (int s=0;s<len;s++) {
uint8_t d=file->get_byte();
//d-=128; //convert to signed
int8_t*ds=(int8_t*)&d;
- int16_t d16=*ds;
- d16<<=8;
- sm->set_data( sid, s, d16 );
+ dataptr[s]=*ds;
}
+ sm->unlock_data(sid);
}
file->close();
diff --git a/drivers/chibi/cp_loader_s3m.cpp b/drivers/chibi/cp_loader_s3m.cpp
index c21f7bdd38..073f35791c 100644
--- a/drivers/chibi/cp_loader_s3m.cpp
+++ b/drivers/chibi/cp_loader_s3m.cpp
@@ -196,8 +196,12 @@ CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) {
if (id.is_null())
return FILE_OUT_OF_MEMORY;
+
+ sm->lock_data(id);
+ void *dataptr = sm->get_data(id);
- for (int c=0;c<(data_is_stereo?2:1);c++) {
+ int chans = (data_is_stereo?2:1);
+ for (int c=0;c<chans;c++) {
for (int i=0;i<sample_size;i++) {
if (data_is_16bits) {
@@ -206,7 +210,7 @@ CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) {
s-=32768; //toggle sign
int16_t *v=(int16_t*)&s;
- sm->set_data(id,i,*v,c);
+ ((int16_t*)dataptr)[i*chans+c]=*v;
} else {
@@ -214,16 +218,16 @@ CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) {
uint8_t s=file->get_byte();
s-=128; //toggle sign
v=(int8_t*)&s;
- int16_t v16=*v;
- v16<<=8;
- sm->set_data(id,i,v16,c);
-
+ ((int8_t*)dataptr)[i*chans+c]=*v;
+
}
-
-
+
}
}
+
+ sm->unlock_data(id);
+
sm->set_loop_begin( id, loop_begin );
sm->set_loop_end( id, loop_end );
diff --git a/drivers/chibi/cp_loader_xm.cpp b/drivers/chibi/cp_loader_xm.cpp
index 8bde6b673e..66f36954ce 100644
--- a/drivers/chibi/cp_loader_xm.cpp
+++ b/drivers/chibi/cp_loader_xm.cpp
@@ -627,6 +627,10 @@ CPLoader::Error CPLoader_XM::load_instrument_internal(CPInstrument *p_instr,bool
CPSample *sample=song->get_sample(sample_index[j]);
CPSample_ID sid=sample->get_sample_data();
+ sm->lock_data(sid);
+
+ void*dataptr=sm->get_data(sid);
+
if (sm->is_16bits( sid)) {
int16_t old=0;
@@ -638,8 +642,9 @@ CPLoader::Error CPLoader_XM::load_instrument_internal(CPInstrument *p_instr,bool
int16_t sampleval=file->get_word();
newsample=sampleval+old;
old=newsample;
-
- sm->set_data( sid, k, newsample );
+
+ ((int16_t*)dataptr)[k]=newsample;
+ //sm->set_data( sid, k, newsample );
}
} else {
@@ -653,10 +658,15 @@ CPLoader::Error CPLoader_XM::load_instrument_internal(CPInstrument *p_instr,bool
newsample=sampleval+old;
old=newsample;
- sm->set_data( sid, k, (int16_t)newsample << 8 );
+ ((int8_t*)dataptr)[k]=newsample;
+
+ //sm->set_data( sid, k, (int16_t)newsample << 8 );
}
}
+
+ sm->unlock_data(sid);
+
}
for (int j=0;j<96;j++) {