diff --git a/doc/base/classes.xml b/doc/base/classes.xml index d6808f0f34e..8128771b6aa 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -4177,6 +4177,7 @@ Set the sample data for a given sample as an array of floats. The length must be equal to the sample lenght or an error will be produced. For this method, a stereo sample is made from two samples. Thus, in case of a stereo sample, the array length must be twice the length returned by [method sample_get_length]. + Trying to alter a SAMPLE_FORMAT_IMA_ADPCM sample is not supported. It will throw an error to the console, but will not alter the sample data. diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 74f866afb7a..1f0a2e403ac 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -48,26 +48,51 @@ AudioServer *AudioServer::get_singleton() { void AudioServer::sample_set_signed_data(RID p_sample, const DVector& p_buffer) { + SampleFormat format = sample_get_format(p_sample); + + ERR_EXPLAIN("IMA ADPCM is not supported."); + ERR_FAIL_COND(format==SAMPLE_FORMAT_IMA_ADPCM); + int len = p_buffer.size(); ERR_FAIL_COND( len == 0 ); DVector data; - data.resize(len*2); - DVector::Write w=data.write(); - - int16_t *samples = (int16_t*)w.ptr(); - + DVector::Write w; DVector::Read r = p_buffer.read(); - for(int i=0;i32767) - sample=32767; - samples[i]=sample; + int8_t *samples8 = (int8_t*)w.ptr(); + + for(int i=0;i127) + sample=127; + samples8[i]=sample; + } + } break; + case SAMPLE_FORMAT_PCM16: { + data.resize(len*2); + w=data.write(); + + int16_t *samples16 = (int16_t*)w.ptr(); + + for(int i=0;i32767) + sample=32767; + samples16[i]=sample; + } + } break; } w = DVector::Write();