Skip to content

Commit

Permalink
Added: #2375 Sound sync event/start/stop handling (for playback in FF…
Browse files Browse the repository at this point in the history
…Dec)

Fixed: #2375 Added limit of simultaneously played sounds
  • Loading branch information
jindrapetrik committed Nov 30, 2024
1 parent c31df61 commit beba0cf
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### Added
- FLA export - accessibility for AS3 files
- [#2375] Sound sync event/start/stop handling (for playback in FFDec)

### Fixed
- [#2375] Added limit of simultaneously played sounds

## [22.0.1] - 2024-11-20
### Added
Expand Down Expand Up @@ -3672,6 +3676,7 @@ Major version of SWF to XML export changed to 2.
[alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9
[alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8
[alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7
[#2375]: https://www.free-decompiler.com/flash/issues/2375
[#2366]: https://www.free-decompiler.com/flash/issues/2366
[#2367]: https://www.free-decompiler.com/flash/issues/2367
[#2372]: https://www.free-decompiler.com/flash/issues/2372
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1701,9 +1701,11 @@ public void toHtmlCanvas(StringBuilder result, double unitDivisor, List<Integer>
*/
public void getSounds(int frame, int time, ButtonTag mouseOverButton, int mouseButton, List<Integer> sounds, List<String> soundClasses, List<SOUNDINFO> soundInfos) {
Frame fr = getFrame(frame);
sounds.addAll(fr.sounds);
soundClasses.addAll(fr.soundClasses);
soundInfos.addAll(fr.soundInfos);
if (time == 0) {
sounds.addAll(fr.sounds);
soundClasses.addAll(fr.soundClasses);
soundInfos.addAll(fr.soundInfos);
}
for (int d = maxDepth; d >= 0; d--) {
DepthState ds = fr.layers.get(d);
if (ds != null) {
Expand All @@ -1724,7 +1726,7 @@ public void getSounds(int frame, int time, ButtonTag mouseOverButton, int mouseB
}
}
}
((Timelined) c).getTimeline().getSounds(dframe, time, mouseOverButton, mouseButton, sounds, soundClasses, soundInfos);
((Timelined) c).getTimeline().getSounds(dframe, 0, mouseOverButton, mouseButton, sounds, soundClasses, soundInfos);
}
}
}
Expand Down Expand Up @@ -1849,6 +1851,9 @@ public boolean isSingleFrame(int frame) {
if (character == null) {
continue;
}
if (!frameObj.sounds.isEmpty()) { //consider timelines with sound as not singleframe
return false;
}
if (character instanceof DrawableTag) {
DrawableTag drawable = (DrawableTag) character;
if (!drawable.isSingleFrame()) {
Expand Down
Binary file modified libsrc/ffdec_lib/testdata/sounds/sounds.swf
Binary file not shown.
51 changes: 39 additions & 12 deletions libsrc/ffdec_lib/testdata/sounds/sounds/DOMDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<DOMFontItem name="Font 1" itemID="604e2b4c-00000400" font="TimesNewRomanPSMT" size="0" id="1" sourceLastImported="1615735628" embedRanges="1|2"/>
</fonts>
<media>
<DOMSoundItem name="19_20.wav" itemID="674b53d9-00000826" sourceExternalFilepath="./LIBRARY/19_20.wav" sourceLastImported="1732989848" externalFileSize="363600" href="19_20.wav" soundDataHRef="M 9 1732989871.dat" format="44kHz 16bit Stereo" sampleCount="90879"/>
<DOMSoundItem name="203066__enjoypa__counting-from-1-to-20.mp3" itemID="63aa97da-00000200" sourceExternalFilepath="./LIBRARY/203066__enjoypa__counting-from-1-to-20.mp3" sourceLastImported="1672124292" externalFileSize="320619" href="203066__enjoypa__counting-from-1-to-20.mp3" soundDataHRef="M 4 1672124303.dat" format="44kHz 16bit Stereo" sampleCount="881280" exportFormat="1" exportBits="7" dataLength="319739" exportNative="true" cacheFormat="5kHz 8bit Stereo" cachedSampleCount="110160"/>
<DOMSoundItem name="514508_gis-sweden_background-techno-loop131bpm_part.mp3" itemID="63aa96ed-000001f2" sourceExternalFilepath="Y:/sounds/sounds/LIBRARY/514508_gis-sweden_background-techno-loop131bpm_part.mp3" sourceLastImported="1672095296" externalFileSize="964275" href="514508_gis-sweden_background-techno-loop131bpm_part.mp3" soundDataHRef="M 3 1672066332.dat" format="44kHz 16bit Stereo" sampleCount="2626560" exportFormat="1" exportBits="7" dataLength="952947" exportNative="true" cacheFormat="5kHz 8bit Stereo" cachedSampleCount="328320"/>
<DOMSoundItem name="four.wav" itemID="656a2b47-0000021d" sourceExternalFilepath="./LIBRARY/four.wav" sourceLastImported="1701452860" externalFileSize="70740" href="four.wav" soundDataHRef="M 8 1701456682.dat" format="44kHz 16bit Stereo" sampleCount="17664"/>
Expand All @@ -18,9 +19,10 @@
<Include href="Symbol 1.xml" loadImmediate="false" itemID="63a9b1e8-000001df" lastModified="1672066786"/>
<Include href="Symbol 2.xml" loadImmediate="false" itemID="63aa96f3-000001f4" lastModified="1672124690"/>
<Include href="Symbol 3.xml" loadImmediate="false" itemID="656a2a12-00000207" lastModified="1701457078"/>
<Include href="Symbol 4.xml" loadImmediate="false" itemID="674b49dd-0000081e" lastModified="1732989887"/>
</symbols>
<timelines>
<DOMTimeline name="Scene 1" currentFrame="14">
<DOMTimeline name="Scene 1" currentFrame="16">
<layers>
<DOMLayer name="Scripts layer" color="#9933CC" autoNamed="false">
<frames>
Expand Down Expand Up @@ -85,7 +87,7 @@
</DOMLayer>
<DOMLayer name="Prev next buttons" color="#4FFF4F" locked="true" autoNamed="false">
<frames>
<DOMFrame index="0" duration="16" keyMode="9728">
<DOMFrame index="0" duration="17" keyMode="9728">
<elements>
<DOMSymbolInstance libraryItemName="btnNext" symbolType="button">
<matrix>
Expand Down Expand Up @@ -348,20 +350,45 @@
</elements>
</DOMFrame>
<DOMFrame index="15" keyMode="9728">
<elements>
<DOMStaticText selected="true" width="446" height="33.25" includeOutlines="true" isSelectable="false">
<matrix>
<Matrix tx="22" ty="342"/>
</matrix>
<textRuns>
<DOMTextRun>
<characters>009 Stop</characters>
<textAttrs>
<DOMTextAttrs aliasText="false" size="30" face="TimesNewRomanPSMT"/>
</textAttrs>
</DOMTextRun>
</textRuns>
</DOMStaticText>
</elements>
</DOMFrame>
<DOMFrame index="16" keyMode="9728">
<elements>
<DOMStaticText width="446" height="33.25" includeOutlines="true" isSelectable="false">
<matrix>
<Matrix tx="22" ty="342"/>
</matrix>
<textRuns>
<DOMTextRun>
<characters>Stop</characters>
<characters>010 Sync</characters>
<textAttrs>
<DOMTextAttrs aliasText="false" size="30" face="TimesNewRomanPSMT"/>
</textAttrs>
</DOMTextRun>
</textRuns>
</DOMStaticText>
<DOMSymbolInstance libraryItemName="Symbol 4" selected="true" centerPoint3DX="227.95" centerPoint3DY="165">
<matrix>
<Matrix tx="128.95" ty="99"/>
</matrix>
<transformationPoint>
<Point x="99" y="66"/>
</transformationPoint>
</DOMSymbolInstance>
</elements>
</DOMFrame>
</frames>
Expand All @@ -371,6 +398,15 @@
</timelines>
<PrinterSettings/>
<publishHistory>
<PublishItem publishSize="2350918" publishTime="1732989691"/>
<PublishItem publishSize="2350795" publishTime="1732989464"/>
<PublishItem publishSize="2351941" publishTime="1732988997"/>
<PublishItem publishSize="2351946" publishTime="1732988949"/>
<PublishItem publishSize="2350796" publishTime="1732987972"/>
<PublishItem publishSize="2350799" publishTime="1732987952"/>
<PublishItem publishSize="2350796" publishTime="1732987887"/>
<PublishItem publishSize="2350640" publishTime="1732987816"/>
<PublishItem publishSize="2668301" publishTime="1732987673"/>
<PublishItem publishSize="2349467" publishTime="1701459083"/>
<PublishItem publishSize="2274335" publishTime="1701458989"/>
<PublishItem publishSize="2349466" publishTime="1701457906"/>
Expand All @@ -382,14 +418,5 @@
<PublishItem publishSize="2309682" publishTime="1672124695" publishDebug="true"/>
<PublishItem publishSize="2309682" publishTime="1672124676" publishDebug="true"/>
<PublishItem publishSize="2309682" publishTime="1672124659" publishDebug="true"/>
<PublishItem publishSize="2309682" publishTime="1672124621" publishDebug="true"/>
<PublishItem publishSize="2309634" publishTime="1672124607"/>
<PublishItem publishSize="2309677" publishTime="1672124588" publishDebug="true"/>
<PublishItem publishSize="2309679" publishTime="1672124562" publishDebug="true"/>
<PublishItem publishSize="2309681" publishTime="1672124532" publishDebug="true"/>
<PublishItem publishSize="2309658" publishTime="1672124466" publishDebug="true"/>
<PublishItem publishSize="2309608" publishTime="1672124456"/>
<PublishItem publishSize="2309671" publishTime="1672124395" publishDebug="true"/>
<PublishItem publishSize="2275411" publishTime="1672069975"/>
</publishHistory>
</DOMDocument>
Binary file not shown.
97 changes: 97 additions & 0 deletions libsrc/ffdec_lib/testdata/sounds/sounds/LIBRARY/Symbol 4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<DOMSymbolItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ns.adobe.com/xfl/2008/" name="Symbol 4" itemID="674b49dd-0000081e" lastModified="1732989887">
<timeline>
<DOMTimeline name="Symbol 4" currentFrame="41">
<layers>
<DOMLayer name="Layer 2" color="#9933CC" current="true" isSelected="true">
<frames>
<DOMFrame index="0" duration="16" keyMode="9728" soundName="19_20.wav">
<SoundEnvelope>
<SoundEnvelopePoint level0="32768" level1="32768"/>
</SoundEnvelope>
<elements/>
</DOMFrame>
</frames>
</DOMLayer>
<DOMLayer name="Layer 3" color="#FF800A">
<frames>
<DOMFrame index="0" duration="3" keyMode="9728">
<elements/>
</DOMFrame>
<DOMFrame index="3" duration="12" keyMode="9728" soundName="19_20.wav">
<SoundEnvelope>
<SoundEnvelopePoint level0="32768" level1="32768"/>
</SoundEnvelope>
<elements/>
</DOMFrame>
</frames>
</DOMLayer>
<DOMLayer name="Layer 4" color="#FF4FFF">
<frames>
<DOMFrame index="0" duration="6" keyMode="9728">
<elements/>
</DOMFrame>
<DOMFrame index="6" duration="8" keyMode="9728" soundName="19_20.wav" soundSync="start">
<SoundEnvelope>
<SoundEnvelopePoint level0="32768" level1="32768"/>
</SoundEnvelope>
<elements/>
</DOMFrame>
</frames>
</DOMLayer>
<DOMLayer name="Layer 5" color="#4FFFFF">
<frames>
<DOMFrame index="0" duration="15" keyMode="9728">
<elements/>
</DOMFrame>
<DOMFrame index="15" duration="27" keyMode="9728" soundName="Yung Raf - Nothing To Lose.mp3" outPoint44="51311" soundZoomLevel="2">
<SoundEnvelope>
<SoundEnvelopePoint level0="32768" level1="32768"/>
</SoundEnvelope>
<elements/>
</DOMFrame>
</frames>
</DOMLayer>
<DOMLayer name="Layer 6" color="#808080">
<frames>
<DOMFrame index="0" duration="18" keyMode="9728">
<elements/>
</DOMFrame>
<DOMFrame index="18" duration="18" keyMode="9728" soundName="Yung Raf - Nothing To Lose.mp3" soundSync="stop">
<SoundEnvelope>
<SoundEnvelopePoint level0="32768" level1="32768"/>
</SoundEnvelope>
<elements/>
</DOMFrame>
</frames>
</DOMLayer>
<DOMLayer name="Layer 1" color="#4FFF4F">
<frames>
<DOMFrame index="0" keyMode="9728">
<elements>
<DOMShape>
<fills>
<FillStyle index="1">
<SolidColor color="#FF00FF"/>
</FillStyle>
</fills>
<strokes>
<StrokeStyle index="1">
<SolidStroke scaleMode="normal">
<fill>
<SolidColor/>
</fill>
</SolidStroke>
</StrokeStyle>
</strokes>
<edges>
<Edge fillStyle1="1" strokeStyle="1" edges="!3960 2640|0 2640!0 2640|0 0!0 0|3960 0!3960 0|3960 2640"/>
</edges>
</DOMShape>
</elements>
</DOMFrame>
</frames>
</DOMLayer>
</layers>
</DOMTimeline>
</timeline>
</DOMSymbolItem>
12 changes: 9 additions & 3 deletions libsrc/ffdec_lib/testdata/sounds/sounds/META-INF/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreatorTool>Adobe Flash Professional CS6 - build 481</xmp:CreatorTool>
<xmp:CreateDate>2021-03-14T08:29:20+01:00</xmp:CreateDate>
<xmp:MetadataDate>2023-12-01T10:51:51-08:00</xmp:MetadataDate>
<xmp:ModifyDate>2023-12-01T10:51:51-08:00</xmp:ModifyDate>
<xmp:MetadataDate>2024-11-30T09:27:52-08:00</xmp:MetadataDate>
<xmp:ModifyDate>2024-11-30T09:27:52-08:00</xmp:ModifyDate>
</rdf:Description>
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/">
Expand All @@ -16,7 +16,7 @@
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#"
xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#">
<xmpMM:InstanceID>xmp.iid:EF6458507290EE1191BEAA90054676FA</xmpMM:InstanceID>
<xmpMM:InstanceID>xmp.iid:DBB644B932AFEF11A208DFE3564218EE</xmpMM:InstanceID>
<xmpMM:DocumentID>xmp.did:21E4449F4B7EED119DEE8735AA8CEAC4</xmpMM:DocumentID>
<xmpMM:OriginalDocumentID>xmp.did:D6D3FE199784EB1187FEAE6972EC5115</xmpMM:OriginalDocumentID>
<xmpMM:History>
Expand Down Expand Up @@ -159,6 +159,12 @@
<stEvt:when>2021-03-14T08:29:20+01:00</stEvt:when>
<stEvt:softwareAgent>Adobe Flash Professional CS6 - build 481</stEvt:softwareAgent>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<stEvt:action>created</stEvt:action>
<stEvt:instanceID>xmp.iid:DBB644B932AFEF11A208DFE3564218EE</stEvt:instanceID>
<stEvt:when>2021-03-14T08:29:20+01:00</stEvt:when>
<stEvt:softwareAgent>Adobe Flash Professional CS6 - build 481</stEvt:softwareAgent>
</rdf:li>
</rdf:Seq>
</xmpMM:History>
<xmpMM:DerivedFrom rdf:parseType="Resource">
Expand Down
Binary file not shown.
Binary file modified libsrc/ffdec_lib/testdata/sounds/sounds/bin/SymDepend.cache
Binary file not shown.
39 changes: 30 additions & 9 deletions src/com/jpexs/decompiler/flash/gui/ImagePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
*/
public final class ImagePanel extends JPanel implements MediaDisplay {


private static final int MAX_SOUND_CHANNELS = 8; //TODO: Maybe add to Advanced settings

private static final Logger logger = Logger.getLogger(ImagePanel.class.getName());

private final List<MediaDisplayListener> listeners = new ArrayList<>();
Expand Down Expand Up @@ -3689,7 +3692,7 @@ private void drawFrame(Timer thisTimer, boolean display) {
}
}

if (!shownAgain && autoPlayed) {
if (autoPlayed) { //!shownAgain
if (!muted) {
List<Integer> sounds = new ArrayList<>();
List<String> soundClasses = new ArrayList<>();
Expand Down Expand Up @@ -3870,13 +3873,37 @@ public void run() {
}

private void playSound(SoundTag st, SOUNDINFO soundInfo, Timer thisTimer) {
synchronized (ImagePanel.this) {
if (soundInfo.syncNoMultiple || soundInfo.syncStop) {
for (int s = soundPlayers.size() - 1; s >= 0; s--) {
SoundTagPlayer sp = soundPlayers.get(s);
if (sp.getTag() == st) {
if (soundInfo.syncNoMultiple) {
//already playing same sound, return
return;
}
if (soundInfo.syncStop) {
sp.stop();
}
}
}

if (soundInfo.syncStop) {
return;
}
}

if (soundPlayers.size() > MAX_SOUND_CHANNELS) {
return;
}
}
final SoundTagPlayer sp;
try {
int loopCount = 1;
if (soundInfo != null && soundInfo.hasLoops) {
loopCount = Math.max(1, soundInfo.loopCount);
}

sp = new SoundTagPlayer(soundInfo, st, loopCount, false, resample);
sp.addEventListener(new MediaDisplayListener() {
@Override
Expand Down Expand Up @@ -4009,13 +4036,7 @@ public void run() {
long delay = getMsPerFrame();
if (isSingleFrame) {
drawFrame(thisTimer, true);
/*synchronized (ImagePanel.this) {
thisTimer.cancel();
if (timer == thisTimer) {
timer = null;
}
}*/


fireMediaDisplayStateChanged();
} else {
//Time before drawing current frame
Expand Down
Loading

0 comments on commit beba0cf

Please sign in to comment.