#905 Show codec details for sound items

This commit is contained in:
honfika@gmail.com
2015-05-31 20:41:35 +02:00
parent 0aab513562
commit 4acdd7e029
11 changed files with 149 additions and 43 deletions

View File

@@ -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<ByteArrayRange> 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);

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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
}

View File

@@ -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));

View File

@@ -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 += "<SoundEnvelope>";
@@ -1669,7 +1669,7 @@ public class XFLConverter {
soundEnvelopeStr += "</SoundEnvelope>";
}
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
}
}