From 18c02a48a5735831e7c7953380d285080265f8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 18 Dec 2023 16:25:30 +0100 Subject: [PATCH] Fixed #2153 FLA Export - sound streams were limited to first stream block --- CHANGELOG.md | 2 ++ .../flash/tags/SoundStreamHead2Tag.java | 5 ++++- .../flash/tags/SoundStreamHeadTag.java | 7 ++++-- .../decompiler/flash/xfl/XFLConverter.java | 22 ++++++++++++------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d765234..d441209f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ All notable changes to this project will be documented in this file. - [#2148] AS1/2 callmethod by register value - [#2148] AS2 Do not return undefined for setters - [#2143] FLA Export / Sound playback - taking MP3 initial latency into account +- [#2153] FLA Export - sound streams were limited to first stream block ### Changed - [#2120] Exported assets no longer take names from assigned classes if there is more than 1 assigned class @@ -3362,6 +3363,7 @@ Major version of SWF to XML export changed to 2. [#2142]: https://www.free-decompiler.com/flash/issues/2142 [#2148]: https://www.free-decompiler.com/flash/issues/2148 [#2143]: https://www.free-decompiler.com/flash/issues/2143 +[#2153]: https://www.free-decompiler.com/flash/issues/2153 [#2120]: https://www.free-decompiler.com/flash/issues/2120 [#1130]: https://www.free-decompiler.com/flash/issues/1130 [#1220]: https://www.free-decompiler.com/flash/issues/1220 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHead2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHead2Tag.java index c9af04352..05bc5fa62 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHead2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHead2Tag.java @@ -149,6 +149,9 @@ public class SoundStreamHead2Tag extends SoundStreamHeadTypeTag { @Override public SoundExportFormat getExportFormat() { if (streamSoundCompression == SoundFormat.FORMAT_MP3) { + if (getInitialLatency() > 0) { + return SoundExportFormat.WAV; + } return SoundExportFormat.MP3; } if (streamSoundCompression == SoundFormat.FORMAT_ADPCM) { @@ -293,6 +296,6 @@ public class SoundStreamHead2Tag extends SoundStreamHeadTypeTag { @Override public int getInitialLatency() { - return 0; + return latencySeek; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java index 0a3c4b347..079e21052 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java @@ -147,8 +147,11 @@ public class SoundStreamHeadTag extends SoundStreamHeadTypeTag { } @Override - public SoundExportFormat getExportFormat() { + public SoundExportFormat getExportFormat() { if (streamSoundCompression == SoundFormat.FORMAT_MP3) { + if (getInitialLatency() > 0) { + return SoundExportFormat.WAV; + } return SoundExportFormat.MP3; } if (streamSoundCompression == SoundFormat.FORMAT_ADPCM) { @@ -302,6 +305,6 @@ public class SoundStreamHeadTag extends SoundStreamHeadTypeTag { @Override public int getInitialLatency() { - return 0; + return latencySeek; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index d251bc84a..6422646ee 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -1977,7 +1977,7 @@ public class XFLConverter { soundRate = head.getSoundRate(); soundType = head.getSoundType(); soundSize = head.getSoundSize(); - soundSampleCount = head.getSoundSampleCount(); + soundSampleCount = 0; //head.getSoundSampleCount(); boolean found = false; for (Tag t : tags) { if (found && (t instanceof SoundStreamBlockTag)) { @@ -2105,16 +2105,22 @@ public class XFLConverter { logger.log(Level.SEVERE, null, ex); } + byte[] decodedData = null; + try { + decodedData = st.getSoundFormat().decode(null, st.getRawSoundData(), seekSamples); + if (soundSampleCount == 0) { + soundSampleCount = decodedData.length / (2 * (st.getSoundType() ? 2 : 1)); + } + } catch (IOException ex) { + logger.log(Level.SEVERE, null, ex); + } + + String datFileName = null; - if (seekSamples > 0) { + if (seekSamples > 0 && decodedData != null) { long ts = getTimestamp(swf); datFileName = "M " + (datfiles.size() + 1) + " " + ts + ".dat"; - try { - byte[] decodedData = st.getSoundFormat().decode(null, st.getRawSoundData(), seekSamples); - datfiles.put(datFileName, decodedData); - } catch (IOException ex) { - logger.log(Level.SEVERE, null, ex); - } + datfiles.put(datFileName, decodedData); } String symbolFile = symbol.getFlaExportName() + "." + exportFormat;