-fix loading of samples in mod, s3m and xm. Fixes #2553

This commit is contained in:
reduz 2015-12-29 16:06:45 -03:00
parent 101fe4b845
commit 875bff2c4e
4 changed files with 31 additions and 16 deletions

View file

@ -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();

View file

@ -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 );

View file

@ -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++) {

View file

@ -802,7 +802,7 @@ void Node::remove_child(Node *p_child) {
}
ERR_FAIL_COND( idx==-1 );
ERR_FAIL_COND( p_child->data.blocked > 0 );
//ERR_FAIL_COND( p_child->data.blocked > 0 );
//if (data.scene) { does not matter