allow loading .brr samples directly

This commit is contained in:
tildearrow 2022-09-25 01:20:08 -05:00
parent d7c885774e
commit cbdf23efa7
3 changed files with 45 additions and 8 deletions

View file

@ -2649,7 +2649,7 @@ DivSample* DivEngine::sampleFromFile(const char* path) {
} }
extS+=i; extS+=i;
} }
if (extS==".dmc") { // read as .dmc if (extS==".dmc" || extS==".brr") { // read as .dmc or .brr
size_t len=0; size_t len=0;
DivSample* sample=new DivSample; DivSample* sample=new DivSample;
sample->name=stripPath; sample->name=stripPath;
@ -2696,12 +2696,48 @@ DivSample* DivEngine::sampleFromFile(const char* path) {
return NULL; return NULL;
} }
if (extS==".dmc") {
sample->rate=33144; sample->rate=33144;
sample->centerRate=33144; sample->centerRate=33144;
sample->depth=DIV_SAMPLE_DEPTH_1BIT_DPCM; sample->depth=DIV_SAMPLE_DEPTH_1BIT_DPCM;
sample->init(len*8); sample->init(len*8);
} else if (extS==".brr") {
sample->rate=32000;
sample->centerRate=32000;
sample->depth=DIV_SAMPLE_DEPTH_BRR;
sample->init(16*(len/9));
} else {
fclose(f);
BUSY_END;
lastError="wait... is that right? no I don't think so...";
delete sample;
return NULL;
}
if (fread(sample->dataDPCM,1,len,f)==0) { unsigned char* dataBuf=sample->dataDPCM;
if (extS==".brr") {
dataBuf=sample->dataBRR;
if ((len%9)==2) {
// ignore loop position
fseek(f,2,SEEK_SET);
len-=2;
if (len==0) {
fclose(f);
BUSY_END;
lastError="BRR sample is empty!";
delete sample;
return NULL;
}
} else if ((len%9)!=0) {
fclose(f);
BUSY_END;
lastError="possibly corrupt BRR sample!";
delete sample;
return NULL;
}
}
if (fread(dataBuf,1,len,f)==0) {
fclose(f); fclose(f);
BUSY_END; BUSY_END;
lastError=fmt::sprintf("could not read file! (%s)",strerror(errno)); lastError=fmt::sprintf("could not read file! (%s)",strerror(errno));

View file

@ -1556,9 +1556,9 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
if (!dirExists(workingDirSample)) workingDirSample=getHomeDir(); if (!dirExists(workingDirSample)) workingDirSample=getHomeDir();
hasOpened=fileDialog->openLoad( hasOpened=fileDialog->openLoad(
"Load Sample", "Load Sample",
{"compatible files", "*.wav *.dmc", {"compatible files", "*.wav *.dmc *.brr",
"all files", ".*"}, "all files", ".*"},
"compatible files{.wav,.dmc},.*", "compatible files{.wav,.dmc,.brr},.*",
workingDirSample, workingDirSample,
dpiScale dpiScale
); );

View file

@ -3296,6 +3296,7 @@ void FurnaceGUI::applyUISettings(bool updateFonts) {
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmw",uiColors[GUI_COLOR_FILE_WAVE],ICON_FA_FILE); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmw",uiColors[GUI_COLOR_FILE_WAVE],ICON_FA_FILE);
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".wav",uiColors[GUI_COLOR_FILE_AUDIO],ICON_FA_FILE_AUDIO_O); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".wav",uiColors[GUI_COLOR_FILE_AUDIO],ICON_FA_FILE_AUDIO_O);
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmc",uiColors[GUI_COLOR_FILE_AUDIO],ICON_FA_FILE_AUDIO_O); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmc",uiColors[GUI_COLOR_FILE_AUDIO],ICON_FA_FILE_AUDIO_O);
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".brr",uiColors[GUI_COLOR_FILE_AUDIO],ICON_FA_FILE_AUDIO_O);
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".vgm",uiColors[GUI_COLOR_FILE_VGM],ICON_FA_FILE_AUDIO_O); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".vgm",uiColors[GUI_COLOR_FILE_VGM],ICON_FA_FILE_AUDIO_O);
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".zsm",uiColors[GUI_COLOR_FILE_ZSM],ICON_FA_FILE_AUDIO_O); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".zsm",uiColors[GUI_COLOR_FILE_ZSM],ICON_FA_FILE_AUDIO_O);
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".ttf",uiColors[GUI_COLOR_FILE_FONT],ICON_FA_FONT); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".ttf",uiColors[GUI_COLOR_FILE_FONT],ICON_FA_FONT);