mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-24 05:25:12 +00:00
add more raw sample import options
This commit is contained in:
parent
c8222fd491
commit
dba96812aa
2 changed files with 76 additions and 21 deletions
|
@ -3676,13 +3676,11 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth,
|
|||
return NULL;
|
||||
}
|
||||
if (channels<1) {
|
||||
lastError="invalid channel count";
|
||||
return NULL;
|
||||
channels=1;
|
||||
}
|
||||
if (depth!=DIV_SAMPLE_DEPTH_8BIT && depth!=DIV_SAMPLE_DEPTH_16BIT) {
|
||||
if (channels!=1) {
|
||||
lastError="channel count has to be 1 for non-8/16-bit format";
|
||||
return NULL;
|
||||
channels=1;
|
||||
}
|
||||
}
|
||||
BUSY_BEGIN;
|
||||
|
@ -3767,6 +3765,7 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth,
|
|||
samples=lenDivided*2;
|
||||
break;
|
||||
case DIV_SAMPLE_DEPTH_8BIT:
|
||||
case DIV_SAMPLE_DEPTH_MULAW:
|
||||
samples=lenDivided;
|
||||
break;
|
||||
case DIV_SAMPLE_DEPTH_BRR:
|
||||
|
@ -3836,11 +3835,45 @@ 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);
|
||||
switch (depth) {
|
||||
case DIV_SAMPLE_DEPTH_1BIT:
|
||||
case DIV_SAMPLE_DEPTH_1BIT_DPCM:
|
||||
// reverse bit order
|
||||
for (unsigned int i=0; i<sample->getCurBufLen(); i++) {
|
||||
b[i]=(
|
||||
((b[i]&128)?1:0)|
|
||||
((b[i]&64)?2:0)|
|
||||
((b[i]&32)?4:0)|
|
||||
((b[i]&16)?8:0)|
|
||||
((b[i]&8)?16:0)|
|
||||
((b[i]&4)?32:0)|
|
||||
((b[i]&2)?64:0)|
|
||||
((b[i]&1)?128:0)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case DIV_SAMPLE_DEPTH_YMZ_ADPCM:
|
||||
case DIV_SAMPLE_DEPTH_QSOUND_ADPCM:
|
||||
case DIV_SAMPLE_DEPTH_ADPCM_A:
|
||||
case DIV_SAMPLE_DEPTH_ADPCM_B:
|
||||
case DIV_SAMPLE_DEPTH_VOX:
|
||||
// swap nibbles
|
||||
for (unsigned int i=0; i<sample->getCurBufLen(); i++) {
|
||||
b[i]=(b[i]<<4)|(b[i]>>4);
|
||||
}
|
||||
break;
|
||||
case DIV_SAMPLE_DEPTH_MULAW:
|
||||
// Namco to G.711
|
||||
// Namco: smmmmxxx
|
||||
// G.711: sxxxmmmm (^0xff)
|
||||
for (unsigned int i=0; i<sample->getCurBufLen(); i++) {
|
||||
b[i]=(((b[i]&7)<<4)|(((b[i]>>3)&15)^((b[i]&0x80)?15:0))|(b[i]&0x80))^0xff;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5766,23 +5766,45 @@ bool FurnaceGUI::loop() {
|
|||
pendingRawSampleBigEndian=false;
|
||||
}
|
||||
|
||||
ImGui::BeginDisabled(pendingRawSampleDepth!=DIV_SAMPLE_DEPTH_8BIT && pendingRawSampleDepth!=DIV_SAMPLE_DEPTH_16BIT);
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text("Channels");
|
||||
ImGui::SameLine();
|
||||
if (ImGui::InputInt("##RSChans",&pendingRawSampleChannels)) {
|
||||
if (pendingRawSampleDepth==DIV_SAMPLE_DEPTH_8BIT || pendingRawSampleDepth==DIV_SAMPLE_DEPTH_16BIT) {
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text("Channels");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(120.0f*dpiScale);
|
||||
if (ImGui::InputInt("##RSChans",&pendingRawSampleChannels)) {
|
||||
}
|
||||
ImGui::Text("(will be mixed down to mono)");
|
||||
ImGui::Checkbox("Unsigned",&pendingRawSampleUnsigned);
|
||||
}
|
||||
ImGui::Text("(will be mixed down to mono)");
|
||||
ImGui::Checkbox("Unsigned",&pendingRawSampleUnsigned);
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ImGui::BeginDisabled(pendingRawSampleDepth!=DIV_SAMPLE_DEPTH_16BIT);
|
||||
ImGui::Checkbox("Big endian",&pendingRawSampleBigEndian);
|
||||
ImGui::EndDisabled();
|
||||
if (pendingRawSampleDepth==DIV_SAMPLE_DEPTH_16BIT) {
|
||||
ImGui::Checkbox("Big endian",&pendingRawSampleBigEndian);
|
||||
}
|
||||
|
||||
ImGui::BeginDisabled(pendingRawSampleDepth==DIV_SAMPLE_DEPTH_16BIT);
|
||||
ImGui::Checkbox("Swap nibbles",&pendingRawSampleSwapNibbles);
|
||||
ImGui::EndDisabled();
|
||||
if (pendingRawSampleDepth==DIV_SAMPLE_DEPTH_YMZ_ADPCM ||
|
||||
pendingRawSampleDepth==DIV_SAMPLE_DEPTH_QSOUND_ADPCM ||
|
||||
pendingRawSampleDepth==DIV_SAMPLE_DEPTH_ADPCM_A ||
|
||||
pendingRawSampleDepth==DIV_SAMPLE_DEPTH_ADPCM_B ||
|
||||
pendingRawSampleDepth==DIV_SAMPLE_DEPTH_VOX) {
|
||||
ImGui::Checkbox("Swap nibbles",&pendingRawSampleSwapNibbles);
|
||||
}
|
||||
|
||||
if (pendingRawSampleDepth==DIV_SAMPLE_DEPTH_MULAW) {
|
||||
ImGui::Text("Encoding:");
|
||||
ImGui::Indent();
|
||||
if (ImGui::RadioButton("G.711",pendingRawSampleSwapNibbles==0)) {
|
||||
pendingRawSampleSwapNibbles=0;
|
||||
}
|
||||
if (ImGui::RadioButton("Namco",pendingRawSampleSwapNibbles==1)) {
|
||||
pendingRawSampleSwapNibbles=1;
|
||||
}
|
||||
ImGui::Unindent();
|
||||
}
|
||||
|
||||
if (pendingRawSampleDepth==DIV_SAMPLE_DEPTH_1BIT ||
|
||||
pendingRawSampleDepth==DIV_SAMPLE_DEPTH_1BIT_DPCM) {
|
||||
ImGui::Checkbox("Reverse bit order",&pendingRawSampleSwapNibbles);
|
||||
}
|
||||
|
||||
if (ImGui::Button("OK")) {
|
||||
DivSample* s=e->sampleFromFileRaw(pendingRawSample.c_str(),(DivSampleDepth)pendingRawSampleDepth,pendingRawSampleChannels,pendingRawSampleBigEndian,pendingRawSampleUnsigned,pendingRawSampleSwapNibbles);
|
||||
|
|
Loading…
Reference in a new issue