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:29:18 +01:00
parent 396cd97801
commit 714dd8761c
24 changed files with 67 additions and 145 deletions

View File

@@ -4493,11 +4493,10 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
*
* @param soundInfo Sound info
* @param soundTag Sound tag
* @param resample Resample to 44kHz?
* @param data Byte data
*/
public void putToCache(SOUNDINFO soundInfo, SoundTag soundTag, boolean resample, byte[] data) {
SoundInfoSoundCacheEntry key = new SoundInfoSoundCacheEntry(soundInfo, soundTag, resample);
public void putToCache(SOUNDINFO soundInfo, SoundTag soundTag, byte[] data) {
SoundInfoSoundCacheEntry key = new SoundInfoSoundCacheEntry(soundInfo, soundTag);
soundCache.put(key, data);
}
@@ -4720,11 +4719,10 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
*
* @param soundInfo Sound info
* @param soundTag Sound tag
* @param resample Resample to 44kHz
* @return Byte data
*/
public byte[] getFromCache(SOUNDINFO soundInfo, SoundTag soundTag, boolean resample) {
SoundInfoSoundCacheEntry key = new SoundInfoSoundCacheEntry(soundInfo, soundTag, resample);
public byte[] getFromCache(SOUNDINFO soundInfo, SoundTag soundTag) {
SoundInfoSoundCacheEntry key = new SoundInfoSoundCacheEntry(soundInfo, soundTag);
if (soundCache.contains(key)) {
return soundCache.get(key);
}

View File

@@ -48,6 +48,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jdk.jfr.internal.RemoveFields;
/**
* Configuration of FFDec.
@@ -1003,10 +1004,12 @@ public final class Configuration {
@ConfigurationDefaultBoolean(false)
@ConfigurationCategory("export")
@ConfigurationRemoved
public static ConfigurationItem<Boolean> lastExportResampleWav = null;
@ConfigurationDefaultBoolean(true)
@ConfigurationCategory("display")
@ConfigurationRemoved
public static ConfigurationItem<Boolean> previewResampleSound = null;
@ConfigurationDefaultBoolean(false)

View File

@@ -118,7 +118,7 @@ public class SoundExporter {
final File file = new File(outdir + File.separator + Helper.makeFileName(st.getCharacterExportFileName()) + ext);
new RetryTask(() -> {
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
exportSound(os, st, settings.mode, settings.resampleWav);
exportSound(os, st, settings.mode);
}
}, handler).run();
@@ -152,13 +152,13 @@ public class SoundExporter {
return ret;
}
public byte[] exportSound(SoundTag t, SoundExportMode mode, boolean resampleWav) throws IOException {
public byte[] exportSound(SoundTag t, SoundExportMode mode) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exportSound(baos, t, mode, resampleWav);
exportSound(baos, t, mode);
return baos.toByteArray();
}
public void exportSound(OutputStream fos, SoundTag st, SoundExportMode mode, boolean resampleWav) throws IOException {
public void exportSound(OutputStream fos, SoundTag st, SoundExportMode mode) throws IOException {
SoundFormat fmt = st.getSoundFormat();
SoundExportFormat nativeFormat = fmt.getNativeExportFormat();
@@ -202,7 +202,7 @@ public class SoundExporter {
}
} else {
List<ByteArrayRange> soundData = st.getRawSoundData();
fmt.createWav(null, soundData, fos, st.getInitialLatency(), resampleWav);
fmt.createWav(null, soundData, fos, st.getInitialLatency());
}
}
}

View File

@@ -651,7 +651,7 @@ public class AS3ScriptExporter {
return ret;
}
SoundExporter se = new SoundExporter();
se.exportSounds(handler, ASSETS_DIR, rttl, new SoundExportSettings(SoundExportMode.MP3_WAV, exportSettings.resampleWav), evl);
se.exportSounds(handler, ASSETS_DIR, rttl, new SoundExportSettings(SoundExportMode.MP3_WAV), evl);
if (CancellableWorker.isInterrupted()) {
return ret;
}

View File

@@ -95,10 +95,9 @@ public class ScriptExportSettings implements Cloneable {
boolean singleFile,
boolean ignoreFrameScripts,
boolean exportEmbed,
boolean exportEmbedFlaMode,
boolean resampleWav
boolean exportEmbedFlaMode
) {
this(mode, singleFile, ignoreFrameScripts, exportEmbed, exportEmbedFlaMode, resampleWav, "/_assets/", false, false);
this(mode, singleFile, ignoreFrameScripts, exportEmbed, exportEmbedFlaMode, "/_assets/", false, false);
}
public ScriptExportSettings(
@@ -107,7 +106,6 @@ public class ScriptExportSettings implements Cloneable {
boolean ignoreFrameScripts,
boolean exportEmbed,
boolean exportEmbedFlaMode,
boolean resampleWav,
String assetsDir,
boolean includeAllClasses,
boolean ignoreAccessibility
@@ -117,7 +115,6 @@ public class ScriptExportSettings implements Cloneable {
this.ignoreFrameScripts = ignoreFrameScripts;
this.exportEmbed = exportEmbed;
this.exportEmbedFlaMode = exportEmbedFlaMode;
this.resampleWav = resampleWav;
this.assetsDir = assetsDir;
this.includeAllClasses = includeAllClasses;
this.ignoreAccessibility = ignoreAccessibility;

View File

@@ -35,18 +35,13 @@ public class SoundExportSettings {
*/
public SoundExportMode mode;
/**
* Resample WAV
*/
public boolean resampleWav;
/**
* Constructor.
* @param mode Mode
* @param resampleWav Resample WAV
*/
public SoundExportSettings(SoundExportMode mode, boolean resampleWav) {
public SoundExportSettings(SoundExportMode mode) {
this.mode = mode;
this.resampleWav = resampleWav;
}
}

View File

@@ -343,7 +343,7 @@ public class SwfFlashDevelopExporter {
}
boolean parallel = Configuration.parallelSpeedUp.get();
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, false, true, false, false, "/_assets/", Configuration.linkAllClasses.get(), false);
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, false, true, false, "/_assets/", Configuration.linkAllClasses.get(), false);
swf.exportActionScript(handler, outFile.toPath().getParent().resolve(srcPath).toFile().getAbsolutePath(), scriptExportSettings, parallel, eventListener);
}
}

View File

@@ -315,7 +315,7 @@ public class SwfIntelliJIdeaExporter {
}
boolean parallel = Configuration.parallelSpeedUp.get();
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, false, true, false, false, "/_assets/", Configuration.linkAllClasses.get(), false);
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, false, true, false, "/_assets/", Configuration.linkAllClasses.get(), false);
swf.exportActionScript(handler, new File(outDir, "src").getAbsolutePath(), scriptExportSettings, parallel, eventListener);
}
}

View File

@@ -411,7 +411,7 @@ public class SwfVsCodeExporter {
libsDir.mkdirs();
boolean parallel = Configuration.parallelSpeedUp.get();
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, false, true, false, false, "/_assets/", Configuration.linkAllClasses.get(), false);
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, false, true, false, "/_assets/", Configuration.linkAllClasses.get(), false);
swf.exportActionScript(handler, srcDir.getAbsolutePath(), scriptExportSettings, parallel, eventListener);
}
}

View File

@@ -328,7 +328,7 @@ public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptRepl
//This compiled code won't be used at all in original SWF,
//it is used only by Flex to properly compile current script
AS3ScriptExporter ex = new AS3ScriptExporter();
ex.exportActionScript3(swfCopy, null, tempDir.getAbsolutePath(), removedPacks, new ScriptExportSettings(ScriptExportMode.AS_METHOD_STUBS, false, false, false /* ??? FIXME */, false, true), false, null);
ex.exportActionScript3(swfCopy, null, tempDir.getAbsolutePath(), removedPacks, new ScriptExportSettings(ScriptExportMode.AS_METHOD_STUBS, false, false, false /* ??? FIXME */, false), false, null);
//now really remove the classes from SWF copy
for (ABC a : modAbcs) {

View File

@@ -83,7 +83,7 @@ public class AS3ScriptImporter {
continue;
}
try {
File file = pack.getExportFile(scriptsFolder, new ScriptExportSettings(ScriptExportMode.AS, false, false, false, false, true));
File file = pack.getExportFile(scriptsFolder, new ScriptExportSettings(ScriptExportMode.AS, false, false, false, false));
if (file.exists()) {
Openable openable = pack.getOpenable();
SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC) openable).getSwf();

View File

@@ -2197,6 +2197,11 @@ public class Timeline {
*/
public boolean isSingleFrame(int frame) {
Frame frameObj = getFrame(frame);
for (int i = 0; i < frameObj.innerTags.size(); i++) {
if (frameObj.innerTags.get(i) instanceof SoundStreamBlockTag) {
return false;
}
}
for (int i = 0; i <= maxDepth; i++) {
if (!frameObj.layers.containsKey(i)) {
continue;
@@ -2217,7 +2222,7 @@ public class Timeline {
if (!drawable.isSingleFrame()) {
return false;
}
}
}
}
return true;

View File

@@ -296,7 +296,7 @@ public class SoundFormat {
return baosResampled.toByteArray();
}
public boolean createWav(SOUNDINFO soundInfo, List<ByteArrayRange> dataRanges, OutputStream os, int skipSamples, boolean resample) throws IOException {
public boolean createWav(SOUNDINFO soundInfo, List<ByteArrayRange> dataRanges, OutputStream os, int skipSamples) throws IOException {
byte[] decodedData = decode(soundInfo, dataRanges, skipSamples);
boolean convertedStereo = stereo;
@@ -351,10 +351,9 @@ public class SoundFormat {
convertedStereo = true;
}
byte[] resampled = resample ? resample(baosFiltered.toByteArray()) : baosFiltered.toByteArray();
try {
createWavFromPcmData(os, resample ? 44100 : samplingRate, true, convertedStereo, resampled);
createWavFromPcmData(os, samplingRate, true, convertedStereo, baosFiltered.toByteArray());
return true;
} catch (IOException ex) {
return false;

View File

@@ -29,12 +29,10 @@ public class SoundInfoSoundCacheEntry {
public SOUNDINFO soundInfo;
public SoundTag soundTag;
public boolean resample;
public SoundInfoSoundCacheEntry(SOUNDINFO soundInfo, SoundTag soundTag, boolean resample) {
public SoundInfoSoundCacheEntry(SOUNDINFO soundInfo, SoundTag soundTag) {
this.soundInfo = soundInfo;
this.soundTag = soundTag;
this.resample = resample;
}
@Override
@@ -42,7 +40,6 @@ public class SoundInfoSoundCacheEntry {
int hash = 7;
hash = 97 * hash + Objects.hashCode(this.soundInfo);
hash = 97 * hash + Objects.hashCode(this.soundTag);
hash = 97 * hash + (this.resample ? 1 : 0);
return hash;
}
@@ -58,9 +55,6 @@ public class SoundInfoSoundCacheEntry {
return false;
}
final SoundInfoSoundCacheEntry other = (SoundInfoSoundCacheEntry) obj;
if (this.resample != other.resample) {
return false;
}
if (!Objects.equals(this.soundInfo, other.soundInfo)) {
return false;
}

View File

@@ -2031,7 +2031,7 @@ public class XFLConverter {
SoundTag st = (SoundTag) symbol;
byte[] data = SWFInputStream.BYTE_ARRAY_EMPTY;
try {
data = new SoundExporter().exportSound(st, convertMp3ToWav ? SoundExportMode.WAV : SoundExportMode.MP3_WAV, false);
data = new SoundExporter().exportSound(st, convertMp3ToWav ? SoundExportMode.WAV : SoundExportMode.MP3_WAV);
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
}
@@ -6157,7 +6157,7 @@ public class XFLConverter {
}
if (useAS3 && settings.exportScript) {
try {
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, true, false, true, true, "/_assets/", Configuration.linkAllClasses.get(), true);
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false, true, false, true, "/_assets/", Configuration.linkAllClasses.get(), true);
swf.exportActionScript(handler, scriptsDir.getAbsolutePath(), scriptExportSettings, parallel, null);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error during ActionScript3 export", ex);