POORLY WORKING Opus export

This commit is contained in:
tildearrow 2025-10-22 20:57:38 -05:00
parent e485c05a80
commit 1bf5e8baaa
5 changed files with 243 additions and 20 deletions

View file

@ -34,28 +34,59 @@ void FurnaceGUI::drawExportAudio(bool onWindow) {
}
if (ImGui::RadioButton(_("multiple files (one per chip)"),audioExportOptions.mode==DIV_EXPORT_MODE_MANY_SYS)) {
audioExportOptions.mode=DIV_EXPORT_MODE_MANY_SYS;
}
audioExportOptions.format=DIV_EXPORT_FORMAT_S16;
}
if (ImGui::RadioButton(_("multiple files (one per channel)"),audioExportOptions.mode==DIV_EXPORT_MODE_MANY_CHAN)) {
audioExportOptions.mode=DIV_EXPORT_MODE_MANY_CHAN;
}
ImGui::Unindent();
if (audioExportOptions.mode!=DIV_EXPORT_MODE_MANY_SYS) {
ImGui::Text(_("Bit depth:"));
ImGui::Text(_("File format:"));
ImGui::Indent();
if (ImGui::RadioButton(_("16-bit integer"),audioExportOptions.format==DIV_EXPORT_FORMAT_S16)) {
if (ImGui::RadioButton(_("Wave (16-bit integer)"),audioExportOptions.format==DIV_EXPORT_FORMAT_S16)) {
audioExportOptions.format=DIV_EXPORT_FORMAT_S16;
}
if (ImGui::RadioButton(_("32-bit float"),audioExportOptions.format==DIV_EXPORT_FORMAT_F32)) {
if (ImGui::RadioButton(_("Wave (32-bit float)"),audioExportOptions.format==DIV_EXPORT_FORMAT_F32)) {
audioExportOptions.format=DIV_EXPORT_FORMAT_F32;
}
#ifdef HAVE_OGG
if (ImGui::RadioButton(_("Opus (lossy compression)"),audioExportOptions.format==DIV_EXPORT_FORMAT_OPUS)) {
audioExportOptions.format=DIV_EXPORT_FORMAT_OPUS;
}
if (ImGui::RadioButton(_("FLAC (Free Lossless Audio Codec)"),audioExportOptions.format==DIV_EXPORT_FORMAT_FLAC)) {
audioExportOptions.format=DIV_EXPORT_FORMAT_FLAC;
}
if (ImGui::RadioButton(_("Vorbis (lossy compression)"),audioExportOptions.format==DIV_EXPORT_FORMAT_VORBIS)) {
audioExportOptions.format=DIV_EXPORT_FORMAT_VORBIS;
}
#endif
#ifdef HAVE_MP3_EXPORT
if (ImGui::RadioButton(_("MP3 (lossy compression)"),audioExportOptions.format==DIV_EXPORT_FORMAT_MPEG_L3)) {
audioExportOptions.format=DIV_EXPORT_FORMAT_MPEG_L3;
}
#endif
ImGui::Unindent();
}
bool rateCheck=(
audioExportOptions.format==DIV_EXPORT_FORMAT_OPUS && (
audioExportOptions.sampleRate!=8000 &&
audioExportOptions.sampleRate!=12000 &&
audioExportOptions.sampleRate!=16000 &&
audioExportOptions.sampleRate!=24000 &&
audioExportOptions.sampleRate!=48000
)
);
pushWarningColor(false,rateCheck);
if (ImGui::InputInt(_("Sample rate"),&audioExportOptions.sampleRate,100,10000)) {
if (audioExportOptions.sampleRate<8000) audioExportOptions.sampleRate=8000;
if (audioExportOptions.sampleRate>384000) audioExportOptions.sampleRate=384000;
}
if (rateCheck) {
ImGui::SetItemTooltip(_("Opus only supports the following sample rates: 8000, 12000, 16000, 24000 and 48000."));
}
popWarningColor();
if (audioExportOptions.mode!=DIV_EXPORT_MODE_MANY_SYS) {
if (ImGui::InputInt(_("Channels in file"),&audioExportOptions.chans,1,1)) {
@ -64,6 +95,56 @@ void FurnaceGUI::drawExportAudio(bool onWindow) {
}
}
if (audioExportOptions.format==DIV_EXPORT_FORMAT_MPEG_L3) {
ImGui::Text(_("Bit rate mode:"));
ImGui::Indent();
if (ImGui::RadioButton(_("Constant"),audioExportOptions.bitRateMode==DIV_EXPORT_BITRATE_CONSTANT)) {
audioExportOptions.bitRateMode=DIV_EXPORT_BITRATE_CONSTANT;
}
if (ImGui::RadioButton(_("Variable"),audioExportOptions.bitRateMode==DIV_EXPORT_BITRATE_VARIABLE)) {
audioExportOptions.bitRateMode=DIV_EXPORT_BITRATE_VARIABLE;
}
if (ImGui::RadioButton(_("Average"),audioExportOptions.bitRateMode==DIV_EXPORT_BITRATE_AVERAGE)) {
audioExportOptions.bitRateMode=DIV_EXPORT_BITRATE_AVERAGE;
}
ImGui::Unindent();
}
int minBitRate=6000;
int maxBitRate=256000;
if (audioExportOptions.format==DIV_EXPORT_FORMAT_MPEG_L3) {
if (audioExportOptions.sampleRate>=32000) {
minBitRate=32000;
maxBitRate=320000;
} else if (audioExportOptions.sampleRate>=16000) {
minBitRate=8000;
maxBitRate=160000;
} else {
minBitRate=8000;
maxBitRate=64000;
}
}
if (audioExportOptions.format!=DIV_EXPORT_FORMAT_S16 && audioExportOptions.format!=DIV_EXPORT_FORMAT_F32) {
if (audioExportOptions.format==DIV_EXPORT_FORMAT_FLAC) {
if (ImGui::SliderFloat(_("Compression level"),&audioExportOptions.vbrQuality,0,8)) {
if (audioExportOptions.vbrQuality<0) audioExportOptions.vbrQuality=0;
if (audioExportOptions.vbrQuality>8) audioExportOptions.vbrQuality=8;
}
} else if (audioExportOptions.format==DIV_EXPORT_FORMAT_VORBIS || (audioExportOptions.format==DIV_EXPORT_FORMAT_MPEG_L3 && audioExportOptions.bitRateMode==DIV_EXPORT_BITRATE_VARIABLE)) {
if (ImGui::SliderFloat(_("Quality"),&audioExportOptions.vbrQuality,0,10)) {
if (audioExportOptions.vbrQuality<0) audioExportOptions.vbrQuality=0;
if (audioExportOptions.vbrQuality>10) audioExportOptions.vbrQuality=10;
}
} else {
if (ImGui::InputInt(_("Bit rate"),&audioExportOptions.bitRate,1000,10000)) {
}
if (audioExportOptions.bitRate<minBitRate) audioExportOptions.bitRate=minBitRate;
if (audioExportOptions.bitRate>maxBitRate) audioExportOptions.bitRate=maxBitRate;
}
}
if (ImGui::InputInt(_("Loops"),&audioExportOptions.loops,1,2)) {
if (audioExportOptions.loops<0) audioExportOptions.loops=0;
}
@ -123,8 +204,33 @@ void FurnaceGUI::drawExportAudio(bool onWindow) {
ImGui::SameLine();
}
if (isOneOn) {
if (isOneOn && !rateCheck) {
if (ImGui::Button(_("Export"),ImVec2(200.0f*dpiScale,0))) {
switch (audioExportOptions.format) {
case DIV_EXPORT_FORMAT_S16:
case DIV_EXPORT_FORMAT_F32:
audioExportFilterName=_("Wave file");
audioExportFilterExt=".wav";
break;
case DIV_EXPORT_FORMAT_OPUS:
case DIV_EXPORT_FORMAT_VORBIS:
audioExportFilterName=_("Ogg files");
audioExportFilterExt=".ogg";
break;
case DIV_EXPORT_FORMAT_FLAC:
audioExportFilterName=_("FLAC files");
audioExportFilterExt=".flac";
break;
case DIV_EXPORT_FORMAT_MPEG_L3:
audioExportFilterName=_("MPEG Layer 3 files");
audioExportFilterExt=".mp3";
break;
default:
audioExportFilterName=_("all files");
audioExportFilterExt="*";
break;
}
switch (audioExportOptions.mode) {
case DIV_EXPORT_MODE_ONE:
openFileDialog(GUI_FILE_EXPORT_AUDIO_ONE);
@ -139,7 +245,11 @@ void FurnaceGUI::drawExportAudio(bool onWindow) {
ImGui::CloseCurrentPopup();
}
} else {
ImGui::Text(_("select at least one channel"));
if (rateCheck) {
ImGui::Text(_("check sample rate"));
} else {
ImGui::Text(_("select at least one channel"));
}
}
}