summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/import/resource_importer_wav.cpp114
-rw-r--r--editor/import/resource_importer_wav.h113
2 files changed, 112 insertions, 115 deletions
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index fa641871a9..41f5a892eb 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -526,119 +526,5 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
return OK;
}
-void ResourceImporterWAV::_compress_ima_adpcm(const Vector<float> &p_data, PoolVector<uint8_t> &dst_data) {
-
- /*p_sample_data->data = (void*)malloc(len);
- xm_s8 *dataptr=(xm_s8*)p_sample_data->data;*/
-
- static const int16_t _ima_adpcm_step_table[89] = {
- 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
- 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
- 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
- 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
- 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
- 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
- 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
- 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
- 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
- };
-
- static const int8_t _ima_adpcm_index_table[16] = {
- -1, -1, -1, -1, 2, 4, 6, 8,
- -1, -1, -1, -1, 2, 4, 6, 8
- };
-
- int datalen = p_data.size();
- int datamax = datalen;
- if (datalen & 1)
- datalen++;
-
- dst_data.resize(datalen / 2 + 4);
- PoolVector<uint8_t>::Write w = dst_data.write();
-
- int i, step_idx = 0, prev = 0;
- uint8_t *out = w.ptr();
- //int16_t xm_prev=0;
- const float *in = p_data.ptr();
-
- /* initial value is zero */
- *(out++) = 0;
- *(out++) = 0;
- /* Table index initial value */
- *(out++) = 0;
- /* unused */
- *(out++) = 0;
-
- for (i = 0; i < datalen; i++) {
- int step, diff, vpdiff, mask;
- uint8_t nibble;
- int16_t xm_sample;
-
- if (i >= datamax)
- xm_sample = 0;
- else {
-
- xm_sample = CLAMP(in[i] * 32767.0, -32768, 32767);
- /*
- if (xm_sample==32767 || xm_sample==-32768)
- printf("clippy!\n",xm_sample);
- */
- }
-
- //xm_sample=xm_sample+xm_prev;
- //xm_prev=xm_sample;
-
- diff = (int)xm_sample - prev;
-
- nibble = 0;
- step = _ima_adpcm_step_table[step_idx];
- vpdiff = step >> 3;
- if (diff < 0) {
- nibble = 8;
- diff = -diff;
- }
- mask = 4;
- while (mask) {
-
- if (diff >= step) {
-
- nibble |= mask;
- diff -= step;
- vpdiff += step;
- }
-
- step >>= 1;
- mask >>= 1;
- };
-
- if (nibble & 8)
- prev -= vpdiff;
- else
- prev += vpdiff;
-
- if (prev > 32767) {
- //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev);
- prev = 32767;
- } 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);
- prev = -32768;
- }
-
- step_idx += _ima_adpcm_index_table[nibble];
- if (step_idx < 0)
- step_idx = 0;
- else if (step_idx > 88)
- step_idx = 88;
-
- if (i & 1) {
- *out |= nibble << 4;
- out++;
- } else {
- *out = nibble;
- }
- /*dataptr[i]=prev>>8;*/
- }
-}
-
ResourceImporterWAV::ResourceImporterWAV() {
}
diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h
index cfce5a31ee..f78ab09e9b 100644
--- a/editor/import/resource_importer_wav.h
+++ b/editor/import/resource_importer_wav.h
@@ -48,7 +48,118 @@ public:
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
- void _compress_ima_adpcm(const Vector<float> &p_data, PoolVector<uint8_t> &dst_data);
+ static void _compress_ima_adpcm(const Vector<float> &p_data, PoolVector<uint8_t> &dst_data) {
+ /*p_sample_data->data = (void*)malloc(len);
+ xm_s8 *dataptr=(xm_s8*)p_sample_data->data;*/
+
+ static const int16_t _ima_adpcm_step_table[89] = {
+ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
+ 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
+ 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
+ 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
+ 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
+ 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
+ 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
+ 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
+ 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
+ };
+
+ static const int8_t _ima_adpcm_index_table[16] = {
+ -1, -1, -1, -1, 2, 4, 6, 8,
+ -1, -1, -1, -1, 2, 4, 6, 8
+ };
+
+ int datalen = p_data.size();
+ int datamax = datalen;
+ if (datalen & 1)
+ datalen++;
+
+ dst_data.resize(datalen / 2 + 4);
+ PoolVector<uint8_t>::Write w = dst_data.write();
+
+ int i, step_idx = 0, prev = 0;
+ uint8_t *out = w.ptr();
+ //int16_t xm_prev=0;
+ const float *in = p_data.ptr();
+
+ /* initial value is zero */
+ *(out++) = 0;
+ *(out++) = 0;
+ /* Table index initial value */
+ *(out++) = 0;
+ /* unused */
+ *(out++) = 0;
+
+ for (i = 0; i < datalen; i++) {
+ int step, diff, vpdiff, mask;
+ uint8_t nibble;
+ int16_t xm_sample;
+
+ if (i >= datamax)
+ xm_sample = 0;
+ else {
+
+ xm_sample = CLAMP(in[i] * 32767.0, -32768, 32767);
+ /*
+ if (xm_sample==32767 || xm_sample==-32768)
+ printf("clippy!\n",xm_sample);
+ */
+ }
+
+ //xm_sample=xm_sample+xm_prev;
+ //xm_prev=xm_sample;
+
+ diff = (int)xm_sample - prev;
+
+ nibble = 0;
+ step = _ima_adpcm_step_table[step_idx];
+ vpdiff = step >> 3;
+ if (diff < 0) {
+ nibble = 8;
+ diff = -diff;
+ }
+ mask = 4;
+ while (mask) {
+
+ if (diff >= step) {
+
+ nibble |= mask;
+ diff -= step;
+ vpdiff += step;
+ }
+
+ step >>= 1;
+ mask >>= 1;
+ };
+
+ if (nibble & 8)
+ prev -= vpdiff;
+ else
+ prev += vpdiff;
+
+ if (prev > 32767) {
+ //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev);
+ prev = 32767;
+ } 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);
+ prev = -32768;
+ }
+
+ step_idx += _ima_adpcm_index_table[nibble];
+ if (step_idx < 0)
+ step_idx = 0;
+ else if (step_idx > 88)
+ step_idx = 88;
+
+ if (i & 1) {
+ *out |= nibble << 4;
+ out++;
+ } else {
+ *out = nibble;
+ }
+ /*dataptr[i]=prev>>8;*/
+ }
+ }
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL);