fixes on sample importing

This commit is contained in:
Juan Linietsky 2015-05-19 23:37:04 -03:00
parent fec6aaffd8
commit 1e50677594
4 changed files with 16 additions and 4 deletions

View file

@ -1872,7 +1872,7 @@ _Thread::_Thread() {
_Thread::~_Thread() { _Thread::~_Thread() {
if (active) { if (active) {
ERR_EXPLAIN("Reference to a Thread object object was lost while the thread is still running..") ERR_EXPLAIN("Reference to a Thread object object was lost while the thread is still running..");
} }
ERR_FAIL_COND(active==true); ERR_FAIL_COND(active==true);
} }

View file

@ -146,9 +146,13 @@ RES ResourceFormatLoaderWAV::load(const String &p_path,const String& p_original_
} }
int frames=chunksize; int frames=chunksize;
frames/=format_channels; frames/=format_channels;
frames/=(format_bits>>3); frames/=(format_bits>>3);
print_line("chunksize: "+itos(chunksize));
print_line("channels: "+itos(format_channels));
print_line("bits: "+itos(format_bits));
sample->create( sample->create(
(format_bits==8) ? Sample::FORMAT_PCM8 : Sample::FORMAT_PCM16, (format_bits==8) ? Sample::FORMAT_PCM8 : Sample::FORMAT_PCM16,
@ -156,8 +160,14 @@ RES ResourceFormatLoaderWAV::load(const String &p_path,const String& p_original_
frames ); frames );
sample->set_mix_rate( format_freq ); sample->set_mix_rate( format_freq );
int len=frames;
if (format_channels==2)
len*=2;
if (format_bits>8)
len*=2;
DVector<uint8_t> data; DVector<uint8_t> data;
data.resize(chunksize); data.resize(len);
DVector<uint8_t>::Write dataw = data.write(); DVector<uint8_t>::Write dataw = data.write();
void * data_ptr = dataw.ptr(); void * data_ptr = dataw.ptr();

View file

@ -135,6 +135,7 @@ void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t>
ERR_EXPLAIN("Sample buffer size does not match sample size."); 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); ERR_FAIL_COND(s->length_bytes!=buff_size);
DVector<uint8_t>::Read buffer_r=p_buffer.read(); DVector<uint8_t>::Read buffer_r=p_buffer.read();
const uint8_t *src = buffer_r.ptr(); const uint8_t *src = buffer_r.ptr();

View file

@ -610,6 +610,7 @@ Error EditorSampleImportPlugin::import(const String& p_path, const Ref<ResourceI
dst_format=Sample::FORMAT_IMA_ADPCM; dst_format=Sample::FORMAT_IMA_ADPCM;
_compress_ima_adpcm(data,dst_data); _compress_ima_adpcm(data,dst_data);
print_line("compressing ima-adpcm, resulting buffersize is "+itos(dst_data.size())+" from "+itos(data.size()));
} else { } else {
@ -755,10 +756,10 @@ void EditorSampleImportPlugin::_compress_ima_adpcm(const Vector<float>& p_data,D
prev+=vpdiff ; prev+=vpdiff ;
if (prev > 32767) { if (prev > 32767) {
printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev); //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev);
prev=32767; prev=32767;
} else if (prev < -32768) { } else if (prev < -32768) {
printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip down %i\n",i,xm_sample,prev,diff,vpdiff,prev); //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip down %i\n",i,xm_sample,prev,diff,vpdiff,prev);
prev = -32768 ; prev = -32768 ;
} }