Replace SoundStreamHead (no MP3 support yet)

This commit is contained in:
Jindra Petřík
2022-12-26 18:07:45 +01:00
parent 971e2ab1fe
commit 94df71e07a
15 changed files with 505 additions and 70 deletions

View File

@@ -172,6 +172,7 @@ import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
import com.jpexs.decompiler.flash.tags.base.MorphShapeTag;
import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag;
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
import com.jpexs.decompiler.flash.tags.base.SoundImportException;
import com.jpexs.decompiler.flash.tags.base.SoundStreamHeadTypeTag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.decompiler.flash.tags.base.SymbolClassTypeTag;
@@ -4032,7 +4033,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
TreeItem ti0 = items.get(0);
File file = null;
if (ti0 instanceof DefineSoundTag) {
if (ti0 instanceof SoundTag) {
file = showImportFileChooser("filter.sounds|*.mp3;*.wav|filter.sounds.mp3|*.mp3|filter.sounds.wav|*.wav", false);
}
if (ti0 instanceof ImageTag) {
@@ -4059,9 +4060,9 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (selectedFile == null) {
return;
}
if (item instanceof DefineSoundTag) {
if (item instanceof SoundTag) {
File selfile = Helper.fixDialogFile(selectedFile);
DefineSoundTag ds = (DefineSoundTag) item;
SoundTag st = (SoundTag) item;
int soundFormat = SoundFormat.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN;
if (selfile.getName().toLowerCase(Locale.ENGLISH).endsWith(".mp3")) {
soundFormat = SoundFormat.FORMAT_MP3;
@@ -4069,8 +4070,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
boolean ok = false;
try {
ok = ds.setSound(new FileInputStream(selfile), soundFormat);
ds.getSwf().clearSoundCache();
ok = st.setSound(new FileInputStream(selfile), soundFormat);
((Tag)st).getSwf().clearSoundCache();
} catch (IOException ex) {
//ignore
} catch (UnsupportedSamplingRateException ex) {
@@ -4081,6 +4082,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
ViewMessages.showMessageDialog(this, translate("error.sound.rate").replace("%saplingRate%", samplingRateKhz).replace("%supportedRates%", String.join(", ", supportedRatesKhz)), translate("error"), JOptionPane.ERROR_MESSAGE);
return;
} catch (SoundImportException ex) {
//ignore
}
if (!ok) {
@@ -4823,7 +4826,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
previewPanel.showImagePanel(timelinedContainer, swf, frame, true, Configuration.autoPlayPreviews.get(), !Configuration.animateSubsprites.get(), false, !Configuration.playFrameSounds.get(), true, false);
} else if ((treeItem instanceof SoundTag)) { //&& isInternalFlashViewerSelected() && (Arrays.asList("mp3", "wav").contains(((SoundTag) tagObj).getExportFormat())))) {
previewPanel.showImagePanel(new SerializableImage(View.loadImage("sound32")));
previewPanel.setImageReplaceButtonVisible(false, false, false, !((Tag) treeItem).isReadOnly() && (treeItem instanceof DefineSoundTag), false);
previewPanel.setImageReplaceButtonVisible(false, false, false, !((Tag) treeItem).isReadOnly() && (treeItem instanceof SoundTag), false);
try {
SoundTagPlayer soundThread = new SoundTagPlayer(null, (SoundTag) treeItem, Configuration.loopMedia.get() ? Integer.MAX_VALUE : 1, true);
if (!Configuration.autoPlaySounds.get()) {

View File

@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.gui.player.Zoom;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.decompiler.flash.types.SOUNDINFO;
import com.jpexs.decompiler.flash.types.sound.SoundFormat;
import com.jpexs.helpers.ByteArrayRange;
import java.awt.Color;
import java.awt.image.BufferedImage;
@@ -197,7 +198,9 @@ public class SoundTagPlayer implements MediaDisplay {
}
long soundLength44 = 0;
int sampleLen = 2 * (tag.getSoundFormat().stereo ? 2 : 1);
boolean isUnCompressed = tag.getSoundFormatId() == SoundFormat.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN ||
tag.getSoundFormatId() == SoundFormat.FORMAT_UNCOMPRESSED_NATIVE_ENDIAN;
int sampleLen = (isUnCompressed ? (tag.getSoundSize() ? 2 : 1) : 2) * (tag.getSoundFormat().stereo ? 2 : 1);
switch (tag.getSoundRate()) {
case 0: //5.5kHz
soundLength44 = 8 * tag.getTotalSoundSampleCount();

View File

@@ -67,6 +67,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.tags.base.ImageTag;
import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag;
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.decompiler.flash.tags.base.TextTag;
import com.jpexs.decompiler.flash.timeline.AS2Package;
import com.jpexs.decompiler.flash.timeline.AS3Package;
@@ -973,7 +974,7 @@ public class TagTreeContextMenu extends JPopupMenu {
replaceMenuItem.setVisible(true);
}
if (canReplace.test(it -> it instanceof DefineSoundTag)) {
if (canReplace.test(it -> it instanceof SoundTag)) {
replaceMenuItem.setVisible(true);
}