From 4acdd7e029f19da5d4cfe5f69fad736ea72044dc Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 31 May 2015 20:41:35 +0200 Subject: [PATCH] #905 Show codec details for sound items --- .../flash/exporters/SoundExporter.java | 11 +++-- .../decompiler/flash/tags/DefineSoundTag.java | 26 ++++++++--- .../flash/tags/SoundStreamHead2Tag.java | 26 ++++++++--- .../flash/tags/SoundStreamHeadTag.java | 26 ++++++++--- .../decompiler/flash/tags/base/SoundTag.java | 3 +- .../flash/types/sound/SoundExportFormat.java | 26 +++++++++++ .../flash/types/sound/SoundFormat.java | 46 ++++++++++++++----- .../decompiler/flash/xfl/XFLConverter.java | 8 ++-- .../decompiler/flash/gui/TagInfoPanel.java | 8 +++- .../flash/gui/locales/MainFrame.properties | 6 +++ .../flash/gui/locales/MainFrame_hu.properties | 6 +++ 11 files changed, 149 insertions(+), 43 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundExportFormat.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java index a9c81cc03..611a6ba39 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java @@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.tags.SoundStreamBlockTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.SoundStreamHeadTypeTag; import com.jpexs.decompiler.flash.tags.base.SoundTag; +import com.jpexs.decompiler.flash.types.sound.SoundExportFormat; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; @@ -83,12 +84,12 @@ public class SoundExporter { String ext = "wav"; SoundFormat fmt = st.getSoundFormat(); switch (fmt.getNativeExportFormat()) { - case SoundFormat.EXPORT_MP3: + case MP3: if (settings.mode.hasMP3()) { ext = "mp3"; } break; - case SoundFormat.EXPORT_FLV: + case FLV: if (settings.mode.hasFlv()) { ext = "flv"; } @@ -125,14 +126,14 @@ public class SoundExporter { public void exportSound(OutputStream fos, SoundTag st, SoundExportMode mode) throws IOException { SoundFormat fmt = st.getSoundFormat(); - int nativeFormat = fmt.getNativeExportFormat(); + SoundExportFormat nativeFormat = fmt.getNativeExportFormat(); - if (nativeFormat == SoundFormat.EXPORT_MP3 && mode.hasMP3()) { + if (nativeFormat == SoundExportFormat.MP3 && mode.hasMP3()) { List datas = st.getRawSoundData(); for (ByteArrayRange data : datas) { fos.write(data.getRangeData()); } - } else if ((nativeFormat == SoundFormat.EXPORT_FLV && mode.hasFlv()) || mode == SoundExportMode.FLV) { + } else if ((nativeFormat == SoundExportFormat.FLV && mode.hasFlv()) || mode == SoundExportMode.FLV) { if (st instanceof DefineSoundTag) { FLVOutputStream flv = new FLVOutputStream(fos); flv.writeHeader(true, false); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSoundTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSoundTag.java index c10608e47..2a815c69d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSoundTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSoundTag.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.sound.MP3FRAME; import com.jpexs.decompiler.flash.types.sound.MP3SOUNDDATA; +import com.jpexs.decompiler.flash.types.sound.SoundExportFormat; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; @@ -139,23 +140,23 @@ public class DefineSoundTag extends CharacterTag implements SoundTag { } @Override - public String getExportFormat() { + public SoundExportFormat getExportFormat() { if (soundFormat == SoundFormat.FORMAT_MP3) { - return "mp3"; + return SoundExportFormat.MP3; } if (soundFormat == SoundFormat.FORMAT_ADPCM) { - return "wav"; + return SoundExportFormat.WAV; } if (soundFormat == SoundFormat.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN) { - return "wav"; + return SoundExportFormat.WAV; } if (soundFormat == SoundFormat.FORMAT_UNCOMPRESSED_NATIVE_ENDIAN) { - return "wav"; + return SoundExportFormat.WAV; } if (soundFormat == SoundFormat.FORMAT_NELLYMOSER || soundFormat == SoundFormat.FORMAT_NELLYMOSER16KHZ || soundFormat == SoundFormat.FORMAT_NELLYMOSER8KHZ) { - return "wav"; + return SoundExportFormat.WAV; } - return "flv"; + return SoundExportFormat.FLV; } private void loadID3v2(InputStream in) { @@ -361,4 +362,15 @@ public class DefineSoundTag extends CharacterTag implements SoundTag { final int[] rateMap = {5512, 11025, 22050, 44100}; return new SoundFormat(getSoundFormatId(), rateMap[getSoundRate()], getSoundType()); } + + @Override + public void getTagInfo(TagInfo tagInfo) { + super.getTagInfo(tagInfo); + SoundFormat soundFormat = getSoundFormat(); + tagInfo.addInfo("general", "codecName", soundFormat.getFormatName()); + tagInfo.addInfo("general", "exportFormat", soundFormat.getNativeExportFormat()); + tagInfo.addInfo("general", "samplingRate", soundFormat.samplingRate); + tagInfo.addInfo("general", "stereo", soundFormat.stereo); + tagInfo.addInfo("general", "sampleCount", soundSampleCount); + } } 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 0a608375b..ba8f81f4c 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 @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.types.annotations.Conditional; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; +import com.jpexs.decompiler.flash.types.sound.SoundExportFormat; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayOutputStream; @@ -154,23 +155,23 @@ public class SoundStreamHead2Tag extends Tag implements SoundStreamHeadTypeTag { } @Override - public String getExportFormat() { + public SoundExportFormat getExportFormat() { if (streamSoundCompression == SoundFormat.FORMAT_MP3) { - return "mp3"; + return SoundExportFormat.MP3; } if (streamSoundCompression == SoundFormat.FORMAT_ADPCM) { - return "wav"; + return SoundExportFormat.WAV; } if (streamSoundCompression == SoundFormat.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN) { - return "wav"; + return SoundExportFormat.WAV; } if (streamSoundCompression == SoundFormat.FORMAT_UNCOMPRESSED_NATIVE_ENDIAN) { - return "wav"; + return SoundExportFormat.WAV; } if (streamSoundCompression == SoundFormat.FORMAT_NELLYMOSER || streamSoundCompression == SoundFormat.FORMAT_NELLYMOSER16KHZ || streamSoundCompression == SoundFormat.FORMAT_NELLYMOSER8KHZ) { - return "wav"; + return SoundExportFormat.WAV; } - return "flv"; + return SoundExportFormat.FLV; } @Override @@ -252,4 +253,15 @@ public class SoundStreamHead2Tag extends Tag implements SoundStreamHeadTypeTag { String exportName = swf.getExportName(getCharacterId()); return getCharacterId() + (exportName != null ? "_" + exportName : ""); } + + @Override + public void getTagInfo(TagInfo tagInfo) { + super.getTagInfo(tagInfo); + SoundFormat soundFormat = getSoundFormat(); + tagInfo.addInfo("general", "codecName", soundFormat.getFormatName()); + tagInfo.addInfo("general", "exportFormat", soundFormat.getNativeExportFormat()); + tagInfo.addInfo("general", "samplingRate", soundFormat.samplingRate); + tagInfo.addInfo("general", "stereo", soundFormat.stereo); + tagInfo.addInfo("general", "sampleCount", streamSoundSampleCount); + } } 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 8575794bb..6dc707262 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 @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.types.annotations.Conditional; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; +import com.jpexs.decompiler.flash.types.sound.SoundExportFormat; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayOutputStream; @@ -143,23 +144,23 @@ public class SoundStreamHeadTag extends Tag implements SoundStreamHeadTypeTag { } @Override - public String getExportFormat() { + public SoundExportFormat getExportFormat() { if (streamSoundCompression == SoundFormat.FORMAT_MP3) { - return "mp3"; + return SoundExportFormat.MP3; } if (streamSoundCompression == SoundFormat.FORMAT_ADPCM) { - return "wav"; + return SoundExportFormat.WAV; } if (streamSoundCompression == SoundFormat.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN) { - return "wav"; + return SoundExportFormat.WAV; } if (streamSoundCompression == SoundFormat.FORMAT_UNCOMPRESSED_NATIVE_ENDIAN) { - return "wav"; + return SoundExportFormat.WAV; } if (streamSoundCompression == SoundFormat.FORMAT_NELLYMOSER || streamSoundCompression == SoundFormat.FORMAT_NELLYMOSER16KHZ || streamSoundCompression == SoundFormat.FORMAT_NELLYMOSER8KHZ) { - return "wav"; + return SoundExportFormat.WAV; } - return "flv"; + return SoundExportFormat.FLV; } @Override @@ -251,4 +252,15 @@ public class SoundStreamHeadTag extends Tag implements SoundStreamHeadTypeTag { String exportName = swf.getExportName(getCharacterId()); return getCharacterId() + (exportName != null ? "_" + exportName : ""); } + + @Override + public void getTagInfo(TagInfo tagInfo) { + super.getTagInfo(tagInfo); + SoundFormat soundFormat = getSoundFormat(); + tagInfo.addInfo("general", "codecName", soundFormat.getFormatName()); + tagInfo.addInfo("general", "exportFormat", soundFormat.getNativeExportFormat()); + tagInfo.addInfo("general", "samplingRate", soundFormat.samplingRate); + tagInfo.addInfo("general", "stereo", soundFormat.stereo); + tagInfo.addInfo("general", "sampleCount", streamSoundSampleCount); + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/SoundTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/SoundTag.java index d8f22152f..c839acdfa 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/SoundTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/SoundTag.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.treeitems.TreeItem; +import com.jpexs.decompiler.flash.types.sound.SoundExportFormat; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; import java.io.InputStream; @@ -28,7 +29,7 @@ import java.util.List; */ public interface SoundTag extends TreeItem { - public String getExportFormat(); + public SoundExportFormat getExportFormat(); public boolean importSupported(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundExportFormat.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundExportFormat.java new file mode 100644 index 000000000..dbad7fe21 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundExportFormat.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.types.sound; + +/** + * + * @author JPEXS + */ +public enum SoundExportFormat { + + WAV, MP3, FLV +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundFormat.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundFormat.java index 6f1d5357e..7d638e3dd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundFormat.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundFormat.java @@ -57,31 +57,25 @@ public class SoundFormat { public static final int FORMAT_SPEEX = 11; - public static final int EXPORT_WAV = 0; - - public static final int EXPORT_MP3 = 1; - - public static final int EXPORT_FLV = 2; - public SoundFormat() { } - public int getNativeExportFormat() { + public SoundExportFormat getNativeExportFormat() { switch (formatId) { case FORMAT_UNCOMPRESSED_NATIVE_ENDIAN: case FORMAT_UNCOMPRESSED_LITTLE_ENDIAN: case FORMAT_ADPCM: - return EXPORT_WAV; + return SoundExportFormat.WAV; case FORMAT_MP3: - return EXPORT_MP3; + return SoundExportFormat.MP3; case FORMAT_NELLYMOSER16KHZ: case FORMAT_NELLYMOSER8KHZ: case FORMAT_NELLYMOSER: case FORMAT_SPEEX: - return EXPORT_FLV; + return SoundExportFormat.FLV; default: - return EXPORT_FLV; + return SoundExportFormat.FLV; } } @@ -167,6 +161,36 @@ public class SoundFormat { } } + public String getFormatName() { + switch (formatId) { + case FORMAT_UNCOMPRESSED_NATIVE_ENDIAN: + return "Uncompressed native endian"; + + case FORMAT_ADPCM: + return "ADPCM"; + + case FORMAT_MP3: + return "MP3"; + + case FORMAT_UNCOMPRESSED_LITTLE_ENDIAN: + return "Uncompressed little endian"; + + case FORMAT_NELLYMOSER16KHZ: + return "NellyMoser 16kHz"; + + case FORMAT_NELLYMOSER8KHZ: + return "NellyMoser 8kHz"; + + case FORMAT_NELLYMOSER: + return "NellyMoser"; + + case FORMAT_SPEEX: + return "Speex"; + } + + return null; + } + private static void writeLE(OutputStream os, long val, int size) throws IOException { for (int i = 0; i < size; i++) { os.write((int) (val & 0xff)); 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 86a0eaa5f..262d601ab 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 @@ -1661,7 +1661,7 @@ public class XFLConverter { } String soundEnvelopeStr = ""; if (soundStreamHead != null && startSound == null) { - String soundName = "sound" + soundStreamHead.getCharacterId() + "." + soundStreamHead.getExportFormat(); + String soundName = "sound" + soundStreamHead.getCharacterId() + "." + soundStreamHead.getExportFormat().toString().toLowerCase(); ret.append(" soundName=\"").append(soundName).append("\""); ret.append(" soundSync=\"stream\""); soundEnvelopeStr += ""; @@ -1669,7 +1669,7 @@ public class XFLConverter { soundEnvelopeStr += ""; } if (startSound != null && sound != null) { - String soundName = "sound" + sound.soundId + "." + sound.getExportFormat(); + String soundName = "sound" + sound.soundId + "." + sound.getExportFormat().toString().toLowerCase(); ret.append(" soundName=\"").append(soundName).append("\""); if (startSound.soundInfo.hasInPoint) { ret.append(" inPoint44=\"").append(startSound.soundInfo.inPoint).append("\""); @@ -2141,7 +2141,7 @@ public class XFLConverter { if (ta instanceof DefineSoundTag) { DefineSoundTag s = (DefineSoundTag) ta; if (s.soundId == startSound.soundId) { - if (!files.containsKey("sound" + s.soundId + "." + s.getExportFormat())) { //Sound was not exported + if (!files.containsKey("sound" + s.soundId + "." + s.getExportFormat().toString().toLowerCase())) { //Sound was not exported startSound = null; // ignore } break; @@ -2152,7 +2152,7 @@ public class XFLConverter { } if (t instanceof SoundStreamHeadTypeTag) { soundStreamHead = (SoundStreamHeadTypeTag) t; - if (!files.containsKey("sound" + soundStreamHead.getCharacterId() + "." + soundStreamHead.getExportFormat())) { //Sound was not exported + if (!files.containsKey("sound" + soundStreamHead.getCharacterId() + "." + soundStreamHead.getExportFormat().toString().toLowerCase())) { //Sound was not exported soundStreamHead = null; // ignore } } diff --git a/src/com/jpexs/decompiler/flash/gui/TagInfoPanel.java b/src/com/jpexs/decompiler/flash/gui/TagInfoPanel.java index 88d836536..23e384537 100644 --- a/src/com/jpexs/decompiler/flash/gui/TagInfoPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/TagInfoPanel.java @@ -124,7 +124,13 @@ public class TagInfoPanel extends JPanel { return name; case 1: - return "" + item.getValue(); + Object value = item.getValue(); + if (value instanceof Boolean) { + boolean boolValue = (boolean) value; + return boolValue ? AppStrings.translate("yes") : AppStrings.translate("no"); + } + + return "" + value; } } diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index a01ce3e73..5774d0dbf 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -611,3 +611,9 @@ header.uncompressed = Uncompressed header.warning.unsupportedGfxCompression = GFX supports only uncompressed or Zlib compressed content. header.warning.minimumZlibVersion = Zlib compression needs SWF version 6 or greater. header.warning.minimumLzmaVersion = LZMA compression needs SWF version 13 or greater. + +tagInfo.codecName = Codec Name +tagInfo.exportFormat = Export Format +tagInfo.samplingRate = Sampling Rate +tagInfo.stereo = Stereo +tagInfo.sampleCount = Sample Count diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties index 843a4e5d3..9df945f87 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties @@ -610,3 +610,9 @@ header.uncompressed = T\u00f6m\u00f6r\u00edtetlen header.warning.unsupportedGfxCompression = GFX csak t\u00f6m\u00f6r\u00edtetlen \u00e9s Zlib t\u00f6m\u00f6r\u00edtett tartalmakat t\u00e1mogat. header.warning.minimumZlibVersion = Zlib t\u00f6m\u00f6r\u00edt\u00e9shez 6-os vagy nagyobb SWF verzi\u00f3ra van sz\u00fcks\u00e9g. header.warning.minimumLzmaVersion = LZMA t\u00f6m\u00f6r\u00edt\u00e9shez 13-as vagy nagyobb SWF verzi\u00f3ra van sz\u00fcks\u00e9g. + +tagInfo.codecName = Codec neve +tagInfo.exportFormat = Export\u00e1l\u00e1si form\u00e1tum +tagInfo.samplingRate = Mintav\u00e9telez\u00e9si frekvencia +tagInfo.stereo = Sztere\u00f3 +tagInfo.sampleCount = Mint\u00e1k sz\u00e1ma