Removed resampling from CLI and all source code

Frames with streamed sound are not taken as same.
This commit is contained in:
Jindra Petřík
2025-11-16 22:37:09 +01:00
parent 396cd97801
commit 714dd8761c
24 changed files with 67 additions and 145 deletions
@@ -510,7 +510,6 @@ public class CommandLineArgumentParser {
boolean cliMode = false;
boolean air = false;
boolean exportEmbed = false;
boolean resampleWav = false;
boolean transparentBackground = false;
Selection selection = new Selection();
Selection selectionIds = new Selection();
@@ -549,9 +548,6 @@ public class CommandLineArgumentParser {
case "-exportembed":
exportEmbed = true;
break;
case "-resamplewav":
resampleWav = true;
break;
case "-ignorebackground":
transparentBackground = true;
break;
@@ -681,7 +677,7 @@ public class CommandLineArgumentParser {
} else if (command.equals("proxy")) {
parseProxy(args);
} else if (command.equals("export")) {
parseExport(selectionClasses, selection, selectionIds, args, handler, traceLevel, format, zoom, charset, exportEmbed, resampleWav, transparentBackground, urlResolver, subLength);
parseExport(selectionClasses, selection, selectionIds, args, handler, traceLevel, format, zoom, charset, exportEmbed, transparentBackground, urlResolver, subLength);
System.exit(0);
} else if (command.equals("compress")) {
parseCompress(args);
@@ -2121,7 +2117,6 @@ public class CommandLineArgumentParser {
double zoom,
String charset,
boolean exportEmbed,
boolean resampleWav,
boolean transparentBackground,
UrlResolver urlResolver,
int subFrameLength) {
@@ -2321,7 +2316,7 @@ public class CommandLineArgumentParser {
if (exportAll || exportFormats.contains("sound")) {
System.out.println("Exporting sounds...");
new SoundExporter().exportSounds(handler, outDir + (multipleExportTypes ? File.separator + SoundExportSettings.EXPORT_FOLDER_NAME : ""), new ReadOnlyTagList(extags), new SoundExportSettings(enumFromStr(formats.get("sound"), SoundExportMode.class), resampleWav), evl);
new SoundExporter().exportSounds(handler, outDir + (multipleExportTypes ? File.separator + SoundExportSettings.EXPORT_FOLDER_NAME : ""), new ReadOnlyTagList(extags), new SoundExportSettings(enumFromStr(formats.get("sound"), SoundExportMode.class)), evl);
}
if (exportAll || exportFormats.contains("binarydata")) {
@@ -2395,7 +2390,7 @@ public class CommandLineArgumentParser {
singleScriptFile = false;
}
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(enumFromStr(formats.get("script"), ScriptExportMode.class), singleScriptFile, false, exportEmbed, false, resampleWav);
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(enumFromStr(formats.get("script"), ScriptExportMode.class), singleScriptFile, false, exportEmbed, false);
boolean exportAllScript = exportAll || exportFormats.contains("script");
boolean exportAs2Script = exportAllScript || exportFormats.contains("script_as2");
boolean exportAs3Script = exportAllScript || exportFormats.contains("script_as3");
@@ -154,9 +154,7 @@ public class ExportDialog extends AppDialog {
private JTextField zoomTextField = new JTextField(4);
private JCheckBox embedCheckBox;
private JCheckBox resampleWavCheckBox;
private JCheckBox transparentFrameBackgroundCheckBox;
@SuppressWarnings("unchecked")
@@ -182,11 +180,7 @@ public class ExportDialog extends AppDialog {
public boolean isEmbedEnabled() {
return embedCheckBox.isSelected();
}
public boolean isResampleWavEnabled() {
return resampleWavCheckBox.isSelected();
}
}
public boolean isTransparentFrameBackgroundEnabled() {
return transparentFrameBackgroundCheckBox.isSelected();
@@ -217,9 +211,6 @@ public class ExportDialog extends AppDialog {
if (embedCheckBox.isVisible()) {
Configuration.lastExportEnableEmbed.set(embedCheckBox.isSelected());
}
if (resampleWavCheckBox.isVisible()) {
Configuration.lastExportResampleWav.set(resampleWavCheckBox.isSelected());
}
if (transparentFrameBackgroundCheckBox.isVisible()) {
Configuration.lastExportTransparentBackground.set(transparentFrameBackgroundCheckBox.isSelected());
}
@@ -410,20 +401,7 @@ public class ExportDialog extends AppDialog {
if (Configuration.lastExportEnableEmbed.get()) {
embedCheckBox.setSelected(true);
}
}
resampleWavCheckBox = new JCheckBox(translate("resampleWav"));
resampleWavCheckBox.setVisible(false);
if (embedCheckBox.isVisible() || visibleOptionClasses.contains(SoundExportMode.class)) {
/*gbc.gridy++;
resampleWavCheckBox.setVisible(true);
comboPanel.add(resampleWavCheckBox, gbc);
if (Configuration.lastExportResampleWav.get()) {
resampleWavCheckBox.setSelected(true);
}*/
resampleWavCheckBox.setSelected(false);
}
}
transparentFrameBackgroundCheckBox = new JCheckBox(translate("transparentFrameBackground"));
transparentFrameBackgroundCheckBox.setVisible(false);
@@ -290,8 +290,6 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
private boolean muted = false;
private boolean resample = false;
private boolean mutable = false;
private boolean alwaysDisplay = false;
@@ -1026,11 +1024,6 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
}
}
@Override
public void setResample(boolean resample) {
this.resample = resample;
}
private static void drawGridSwf(Graphics2D g, Rectangle realRect, double zoom) {
g.setColor(Configuration.gridColor.get());
double x;
@@ -4788,7 +4781,6 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
this.frozen = frozen;
this.frozenButtons = frozenButtons;
this.muted = muted;
this.resample = false; //Configuration.previewResampleSound.get();
this.mutable = mutable;
depthStateUnderCursor = null;
hilightedEdge = null;
@@ -5986,7 +5978,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
loopCount = Math.max(1, soundInfo.loopCount);
}
sp = new SoundTagPlayer(soundInfo, st, loopCount, false, resample);
sp = new SoundTagPlayer(soundInfo, st, loopCount, false);
sp.addEventListener(new MediaDisplayListener() {
@Override
public void mediaDisplayStateChanged(MediaDisplay source) {
@@ -2298,7 +2298,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (export.isOptionEnabled(SoundExportMode.class)) {
ret.addAll(new SoundExporter().exportSounds(handler, selFile2 + File.separator + SoundExportSettings.EXPORT_FOLDER_NAME, sounds,
new SoundExportSettings(export.getValue(SoundExportMode.class), export.isResampleWavEnabled()), evl));
new SoundExportSettings(export.getValue(SoundExportMode.class)), evl));
}
if (export.isOptionEnabled(BinaryDataExportMode.class)) {
@@ -2362,7 +2362,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
singleScriptFile = false;
}
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), singleScriptFile, false, export.isEmbedEnabled(), false, export.isResampleWavEnabled());
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), singleScriptFile, false, export.isEmbedEnabled(), false);
String singleFileName = Path.combine(scriptsFolder, openable.getShortFileName() + scriptExportSettings.getFileExtension());
try (FileTextWriter writer = scriptExportSettings.singleFile ? new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(singleFileName)) : null) {
scriptExportSettings.singleFileWriter = writer;
@@ -2416,7 +2416,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (export.isOptionEnabled(SoundExportMode.class)) {
new SoundExporter().exportSounds(handler, Path.combine(selFile, SoundExportSettings.EXPORT_FOLDER_NAME), swf.getTags(),
new SoundExportSettings(export.getValue(SoundExportMode.class), export.isResampleWavEnabled()), evl);
new SoundExportSettings(export.getValue(SoundExportMode.class)), evl);
}
if (export.isOptionEnabled(BinaryDataExportMode.class)) {
@@ -2469,7 +2469,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
singleScriptFile = false;
}
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), singleScriptFile, false, export.isEmbedEnabled(), false, export.isResampleWavEnabled());
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), singleScriptFile, false, export.isEmbedEnabled(), false);
String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension());
try (FileTextWriter writer = scriptExportSettings.singleFile ? new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(singleFileName)) : null) {
scriptExportSettings.singleFileWriter = writer;
@@ -2519,7 +2519,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (export.isOptionEnabled(SoundExportMode.class)) {
for (SoundExportMode exportMode : SoundExportMode.values()) {
new SoundExporter().exportSounds(handler, Path.combine(selFile, SoundExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf.getTags(),
new SoundExportSettings(exportMode, export.isResampleWavEnabled()), evl);
new SoundExportSettings(exportMode), evl);
}
}
@@ -2586,7 +2586,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
singleScriptFile = false;
}
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(exportMode, singleScriptFile, false, export.isEmbedEnabled(), false, export.isResampleWavEnabled());
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(exportMode, singleScriptFile, false, export.isEmbedEnabled(), false);
String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension());
try (FileTextWriter writer = scriptExportSettings.singleFile ? new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(singleFileName)) : null) {
scriptExportSettings.singleFileWriter = writer;
@@ -6187,7 +6187,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
previewPanel.setImageReplaceButtonVisible(false, false, false, !((SoundTag) treeItem).isReadOnly() && ((SoundTag) treeItem).importSupported(), false, false, false);
if (!(treeItem instanceof SoundStreamHeadTypeTag)) {
try {
SoundTagPlayer soundThread = new SoundTagPlayer(null, (SoundTag) treeItem, Configuration.loopMedia.get() ? Integer.MAX_VALUE : 1, true, false); // Configuration.previewResampleSound.get());
SoundTagPlayer soundThread = new SoundTagPlayer(null, (SoundTag) treeItem, Configuration.loopMedia.get() ? Integer.MAX_VALUE : 1, true);
if (!Configuration.autoPlaySounds.get()) {
soundThread.pause();
}
@@ -54,8 +54,6 @@ public class SoundTagPlayer implements MediaDisplay {
private boolean closed = false;
private boolean resample = false;
private final Object playLock = new Object();
private final SoundTag tag;
@@ -75,17 +73,13 @@ public class SoundTagPlayer implements MediaDisplay {
private long lengthInMicroSec = 0;
private double microsecPerByte = 0;
private double microsecPerByteResampled = 0;
private double positionMicrosec = 0;
private Long newPositionMicrosec = null;
private byte[] wavData = null;
private byte[] wavDataResampled = null;
private boolean active = false;
private static int totalInstances = 0;
@@ -166,7 +160,7 @@ public class SoundTagPlayer implements MediaDisplay {
private static final int FRAME_DIVISOR = 8000;
public SoundTagPlayer(final SOUNDINFO soundInfo, final SoundTag tag, int loops, boolean async, boolean resample) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
public SoundTagPlayer(final SOUNDINFO soundInfo, final SoundTag tag, int loops, boolean async) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
this.tag = tag;
this.loopCount = loops;
@@ -188,13 +182,11 @@ public class SoundTagPlayer implements MediaDisplay {
setPausedFlag(true);
}
this.resample = resample;
thread = new Thread("Sound tag player") {
@Override
public void run() {
try {
openSound(soundInfo, tag, resample);
openSound(soundInfo, tag);
} catch (IOException | LineUnavailableException | UnsupportedAudioFileException ex) {
Logger.getLogger(SoundTagPlayer.class.getName()).log(Level.SEVERE, null, ex);
}
@@ -216,20 +208,16 @@ public class SoundTagPlayer implements MediaDisplay {
thread.start();
}
private void openSound(SOUNDINFO soundInfo, SoundTag tag, boolean resample) throws IOException, LineUnavailableException, UnsupportedAudioFileException {
private void openSound(SOUNDINFO soundInfo, SoundTag tag) throws IOException, LineUnavailableException, UnsupportedAudioFileException {
SWF swf = (SWF) tag.getOpenable();
wavData = swf.getFromCache(soundInfo, tag, false);
wavDataResampled = swf.getFromCache(soundInfo, tag, true);
if (wavData == null || wavDataResampled == null) {
wavData = swf.getFromCache(soundInfo, tag);
if (wavData == null) {
List<ByteArrayRange> soundData = tag.getRawSoundData();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tag.getSoundFormat().createWav(soundInfo, soundData, baos, tag.getInitialLatency(), false);
tag.getSoundFormat().createWav(soundInfo, soundData, baos, tag.getInitialLatency());
wavData = baos.toByteArray();
swf.putToCache(soundInfo, tag, false, wavData);
baos = new ByteArrayOutputStream();
tag.getSoundFormat().createWav(soundInfo, soundData, baos, tag.getInitialLatency(), true);
wavDataResampled = baos.toByteArray();
swf.putToCache(soundInfo, tag, true, wavDataResampled);
swf.putToCache(soundInfo, tag, wavData);
baos = new ByteArrayOutputStream();
}
long soundLength44 = 0;
@@ -255,7 +243,6 @@ public class SoundTagPlayer implements MediaDisplay {
break;
}
microsecPerByteResampled = 1000000d / (44100d * sampleLen);
lengthInMicroSec = soundLength44 * 1000000 / 44100;
synchronized (playLock) {
@@ -300,7 +287,7 @@ public class SoundTagPlayer implements MediaDisplay {
}
private void reloadAudioStream() throws IOException, UnsupportedAudioFileException, LineUnavailableException {
audioStream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(resample ? wavDataResampled : wavData));
audioStream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(wavData));
if (sourceLine != null) {
sourceLine.drain();
@@ -330,7 +317,7 @@ public class SoundTagPlayer implements MediaDisplay {
}
if (!getPausedFlag()) {
if (newPositionMicrosec != null) {
long newPosBytes = (long) (newPositionMicrosec / (resample ? microsecPerByteResampled : microsecPerByte));
long newPosBytes = (long) (newPositionMicrosec / microsecPerByte);
audioStream.close();
reloadAudioStream();
audioStream.skip(newPosBytes);
@@ -346,7 +333,7 @@ public class SoundTagPlayer implements MediaDisplay {
}
sourceLine.write(data, 0, numReadBytes);
synchronized (playLock) {
positionMicrosec = (resample ? microsecPerByteResampled : microsecPerByte) * posBytes;
positionMicrosec = microsecPerByte * posBytes;
}
}
}
@@ -491,11 +478,6 @@ public class SoundTagPlayer implements MediaDisplay {
}
}
public void setResample(boolean resample) {
this.resample = resample;
rewind();
}
@Override
public void gotoFrame(int frame) {
synchronized (playLock) {
@@ -43,8 +43,6 @@ public interface MediaDisplay extends Closeable {
public void setLoop(boolean loop);
public void setResample(boolean resample);
public void gotoFrame(int frame);
public void setBackground(Color color);
@@ -69,8 +69,6 @@ public class PlayerControls extends JPanel implements MediaDisplayListener {
private final JButton loopButton;
private final JToggleButton resampleButton;
private MediaDisplay display;
private JProgressBar progress;
@@ -90,9 +88,7 @@ public class PlayerControls extends JPanel implements MediaDisplayListener {
private static final Icon loopIcon = View.getIcon("loopon16");
private static final Icon noLoopIcon = View.getIcon("loopoff16");
private static final Icon resampleIcon = View.getIcon("resample16");
//private final JLabel percentLabel = new JLabel("100%");
private final ZoomPanel zoomPanel;
@@ -293,16 +289,9 @@ public class PlayerControls extends JPanel implements MediaDisplayListener {
boolean loop = Configuration.loopMedia.get();
loopButton.setIcon(loop ? loopIcon : noLoopIcon);
resampleButton = new JToggleButton(resampleIcon);
resampleButton.setToolTipText(AppStrings.translate("preview.resample"));
resampleButton.setMargin(new Insets(4, 2, 2, 2));
resampleButton.addActionListener(this::resampleButtonActionPerformed);
resampleButton.setSelected(false); //Configuration.previewResampleSound.get());
buttonsPanel.add(pauseButton);
buttonsPanel.add(stopButton);
buttonsPanel.add(loopButton);
//buttonsPanel.add(resampleButton);
controlPanel.add(buttonsPanel, BorderLayout.CENTER);
progress = new JProgressBar();
@@ -443,13 +432,7 @@ public class PlayerControls extends JPanel implements MediaDisplayListener {
loopButton.setIcon(loop ? loopIcon : noLoopIcon);
display.setLoop(loop);
}
private void resampleButtonActionPerformed(ActionEvent evt) {
boolean resample = resampleButton.isSelected();
Configuration.previewResampleSound.set(resample);
display.setResample(resample);
}
private void gotoFrameButtonActionPerformed(ActionEvent evt) {
final JPanel gotoPanel = new JPanel(new BorderLayout());
final JTextField frameField = new JTextField("" + display.getCurrentFrame());