add option to swap nibbles on raw sample import

issue #791
This commit is contained in:
tildearrow 2022-12-17 22:45:08 -05:00
parent 4affc48ebd
commit ceb27728d3
4 changed files with 17 additions and 4 deletions

View file

@ -3293,7 +3293,7 @@ DivSample* DivEngine::sampleFromFile(const char* path) {
#endif
}
DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign) {
DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign, bool swapNibbles) {
if (song.sample.size()>=256) {
lastError="too many samples!";
return NULL;
@ -3459,6 +3459,14 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth,
}
delete[] buf;
// swap nibbles if needed
if (swapNibbles) {
unsigned char* b=(unsigned char*)sample->getCurBuf();
for (unsigned int i=0; i<sample->getCurBufLen(); i++) {
b[i]=(b[i]<<4)|(b[i]>>4);
}
}
BUSY_END;
return sample;
}