diff --git a/scripts/wt-tool/wt-tool.py b/scripts/wt-tool/wt-tool.py index 1fd9e14c989..facc7209b6f 100755 --- a/scripts/wt-tool/wt-tool.py +++ b/scripts/wt-tool/wt-tool.py @@ -40,7 +40,8 @@ def read_wt_header(fn): flags = {} flags["is_sample"] = (fl[0] & 0x01 != 0) flags["loop_sample"] = (fl[0] & 0x02 != 0) - flags["format"] = "int16" if (fl[0] & 0x04 != 0) else "float32" + + flags["format"] = "int16-full-range" if (fl[0] == 0xC) else "int16" if (fl[0] & 0x04 != 0) else "float32" flags["samplebytes"] = 2 if (fl[0] & 0x04 != 0) else 4 header["flags"] = flags @@ -74,7 +75,7 @@ def explode(fn, wav_dir): wav_file.writeframes(bdata) -def create(fn, wavdir, norm): +def create(fn, wavdir, norm, intform): onlyfiles = [f for f in listdir(wavdir) if (isfile(join(wavdir, f)) and f.endswith(".wav"))] onlyfiles.sort() @@ -122,8 +123,8 @@ def create(fn, wavdir, norm): newrec[2 * i + 1] = nms newdb.append(newrec) databuffer = newdb - elif (norm == "peak"): - print("Normalizing to peak") + elif (norm == "peak" or norm == "peak16"): + print("Normalizing to " + norm) peakp = 0 peakm = 0 for d in databuffer: @@ -141,6 +142,11 @@ def create(fn, wavdir, norm): peakp = -peakm print("Peak value is ", peakp) newdb = [] + + den = 16384.0 + if (norm == "peak16"): + den = den * 2 + for d in databuffer: newrec = bytearray(len(d)) @@ -149,7 +155,7 @@ def create(fn, wavdir, norm): ms = d[2 * i + 1] if(ms >= 128): ms -= 256 - r = int((ls + ms * 256) * 16384.0 / peakp) + r = int((ls + ms * 256) * den / peakp) nls = int(r % 256) nms = int(r / 256) @@ -169,7 +175,7 @@ def create(fn, wavdir, norm): outf.write(b'vawt') outf.write(nf.to_bytes(4, byteorder='little')) outf.write((len(onlyfiles)).to_bytes(2, byteorder='little')) - outf.write(bytes([4, 0])) + outf.write(bytes([4 if (intform == "i15") else 12, 0])) for d in databuffer: outf.write(d) @@ -199,7 +205,10 @@ def main(): Modes are 'none' leave input untouched; 'half' input wav are divided by 2 (so 2^16 range becomes 2^15 range); 'peak' input wav are scanned and re-peaked to 2^15. +'peak16' input wav are scanned and re-peaked to 2^15. """) + parser.add_option("-i", "--int-range", dest="intrange", default="i15", metavar="INTRANGE", + help = "Int range for creating i16 files. Either i15 or i16") (options, args) = parser.parse_args() act = options.action @@ -208,7 +217,7 @@ def main(): parser.print_help() print("\nYou must specify a file and wav_dir for create") else: - create(options.file, options.wav_dir, options.normalize) + create(options.file, options.wav_dir, options.normalize, options.intrange) elif act == "explode": if(options.file is None or options.wav_dir is None): parser.print_help() diff --git a/src/common/dsp/Wavetable.cpp b/src/common/dsp/Wavetable.cpp index 16b761f57f0..b3896130478 100644 --- a/src/common/dsp/Wavetable.cpp +++ b/src/common/dsp/Wavetable.cpp @@ -247,11 +247,14 @@ bool Wavetable::BuildWT(void *wdata, wt_header &wh, bool AppendSilence) &((short *)wdata)[this->size * j], this->size); if (this->flags & wtf_int16_is_16) { - i16toi15_block(&this->TableI16WeakPointers[0][j][FIRoffsetI16], - &this->TableI16WeakPointers[0][j][FIRoffsetI16], this->size); + i162float_block(&this->TableI16WeakPointers[0][j][FIRoffsetI16], + this->TableF32WeakPointers[0][j], this->size); + } + else + { + i152float_block(&this->TableI16WeakPointers[0][j][FIRoffsetI16], + this->TableF32WeakPointers[0][j], this->size); } - i152float_block(&this->TableI16WeakPointers[0][j][FIRoffsetI16], - this->TableF32WeakPointers[0][j], this->size); } } else diff --git a/src/common/dsp/oscillators/WindowOscillator.cpp b/src/common/dsp/oscillators/WindowOscillator.cpp index 3792103f28a..97c0d17a81a 100644 --- a/src/common/dsp/oscillators/WindowOscillator.cpp +++ b/src/common/dsp/oscillators/WindowOscillator.cpp @@ -196,7 +196,7 @@ inline unsigned int BigMULr16(unsigned int a, unsigned int b) return c >> 16u; } -void WindowOscillator::ProcessWindowOscs(bool stereo, bool FM) +template void WindowOscillator::ProcessWindowOscs(bool stereo) { const unsigned int M0Mask = 0x07f8; unsigned int SizeMask = (oscdata->wt.size << 16) - 1; @@ -332,8 +332,9 @@ void WindowOscillator::ProcessWindowOscs(bool stereo, bool FM) #endif iWin[0] = (iWin[0] + iWin[1] + iWin[2] + iWin[3]) >> 13; - iWave[0] = (iWave[0] + iWave[1] + iWave[2] + iWave[3]) >> 13; - iWaveP1[0] = (iWaveP1[0] + iWaveP1[1] + iWaveP1[2] + iWaveP1[3]) >> 13; + iWave[0] = (iWave[0] + iWave[1] + iWave[2] + iWave[3]) >> (13 + (Full16 ? 1 : 0)); + iWaveP1[0] = + (iWaveP1[0] + iWaveP1[1] + iWaveP1[2] + iWaveP1[3]) >> (13 + (Full16 ? 1 : 0)); iWave[0] = (int)((1.f - FTable) * iWave[0] + FTable * iWaveP1[0]); @@ -414,7 +415,30 @@ void WindowOscillator::process_block(float pitch, float drift, bool stereo, bool } } - ProcessWindowOscs(stereo, FM); + bool is16 = oscdata->wt.flags & wtf_int16_is_16; + + if (FM) + { + if (is16) + { + ProcessWindowOscs(stereo); + } + else + { + ProcessWindowOscs(stereo); + } + } + else + { + if (is16) + { + ProcessWindowOscs(stereo); + } + else + { + ProcessWindowOscs(stereo); + } + } // int32 -> float conversion __m128 scale = _mm_load1_ps(&OutAttenuation); diff --git a/src/common/dsp/oscillators/WindowOscillator.h b/src/common/dsp/oscillators/WindowOscillator.h index 9223d2f5bb6..25d293b58fe 100644 --- a/src/common/dsp/oscillators/WindowOscillator.h +++ b/src/common/dsp/oscillators/WindowOscillator.h @@ -77,7 +77,7 @@ class WindowOscillator : public Oscillator void applyFilter(); template void update_lagvals(); - void ProcessWindowOscs(bool stereo, bool FM); + template void ProcessWindowOscs(bool stereo); lag FMdepth[MAX_UNISON]; lag l_morph; diff --git a/src/common/dsp/vembertech/basic_dsp.h b/src/common/dsp/vembertech/basic_dsp.h index 639f3a1e76b..6eea0fd9da7 100644 --- a/src/common/dsp/vembertech/basic_dsp.h +++ b/src/common/dsp/vembertech/basic_dsp.h @@ -54,6 +54,15 @@ inline void i152float_block(short *s, float *f, int n) } } +inline void i162float_block(short *s, float *f, int n) +{ + const float scale = 1.f / (16384.f * 2); + for (int i = 0; i < n; i++) + { + f[i] = (float)s[i] * scale; + } +} + inline void i16toi15_block(short *s, short *o, int n) { for (int i = 0; i < n; i++)