mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-18 14:18:11 +00:00
Issue #684 Fixed sound streams inside DefineSprites, fixed sound stream blocks handling
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.exporters;
|
||||
|
||||
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
|
||||
@@ -118,12 +119,18 @@ public class SoundExporter {
|
||||
int nativeFormat = fmt.getNativeExportFormat();
|
||||
|
||||
if (nativeFormat == SoundFormat.EXPORT_MP3 && mode.hasMP3()) {
|
||||
if (nativeFormat == SoundFormat.EXPORT_MP3 && mode.hasMP3()) {
|
||||
List<byte[]> datas=st.getRawSoundData();
|
||||
for(byte[] data:datas){
|
||||
fos.write(data);
|
||||
}
|
||||
} else if ((nativeFormat == SoundFormat.EXPORT_FLV && mode.hasFlv()) || mode == SoundExportMode.FLV) {
|
||||
if (st instanceof DefineSoundTag) {
|
||||
FLVOutputStream flv = new FLVOutputStream(fos);
|
||||
flv.writeHeader(true, false);
|
||||
flv.writeHeader(true, false);
|
||||
List<byte[]> datas=st.getRawSoundData();
|
||||
for(byte[] data:datas){
|
||||
flv.writeTag(new FLVTAG(0, new AUDIODATA(st.getSoundFormatId(), st.getSoundRate(), st.getSoundSize(), st.getSoundType(), data)));
|
||||
}
|
||||
} else if (st instanceof SoundStreamHeadTypeTag) {
|
||||
SoundStreamHeadTypeTag sh = (SoundStreamHeadTypeTag) st;
|
||||
FLVOutputStream flv = new FLVOutputStream(fos);
|
||||
@@ -140,9 +147,13 @@ public class SoundExporter {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
List<byte[]> soundData = st.getRawSoundData();
|
||||
SWF swf = ((Tag) st).getSwf();
|
||||
SWF swf = ((Tag) st).getSwf();
|
||||
List<SWFInputStream> siss=new ArrayList<>();
|
||||
for(byte[] data:soundData){
|
||||
siss.add(new SWFInputStream(swf, data));
|
||||
}
|
||||
fmt.createWav(siss, fos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.tags;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
@@ -32,7 +33,9 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
@@ -303,11 +306,14 @@ public class DefineSoundTag extends CharacterTag implements SoundTag {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public List<byte[]> getRawSoundData() {
|
||||
List<byte[]> ret=new ArrayList<byte[]>();
|
||||
if (soundFormat == SoundFormat.FORMAT_MP3) {
|
||||
if (soundFormat == SoundFormat.FORMAT_MP3) {
|
||||
ret.add(Arrays.copyOfRange(soundData, 2, soundData.length));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
ret.add(soundData);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.tags;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
@@ -31,6 +32,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -180,7 +182,7 @@ public class SoundStreamHead2Tag extends CharacterIdTag implements SoundStreamHe
|
||||
@Override
|
||||
public List<SoundStreamBlockTag> getBlocks() {
|
||||
List<SoundStreamBlockTag> ret = new ArrayList<>();
|
||||
List<SoundStreamBlockTag> ret = new ArrayList<>();
|
||||
SoundStreamHeadTag.populateSoundStreamBlocks(0,swf.tags, this, ret);
|
||||
return ret;
|
||||
|
||||
}
|
||||
@@ -196,21 +198,17 @@ public class SoundStreamHead2Tag extends CharacterIdTag implements SoundStreamHe
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public List<byte[]> getRawSoundData() {
|
||||
List<byte[]> ret = new ArrayList<byte[]>();
|
||||
List<SoundStreamBlockTag> blocks = getBlocks();
|
||||
List<SoundStreamBlockTag> blocks = getBlocks();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
for (SoundStreamBlockTag block : blocks) {
|
||||
if (streamSoundCompression == SoundFormat.FORMAT_MP3) {
|
||||
baos.write(block.streamSoundData, 4, block.streamSoundData.length - 4);
|
||||
} else {
|
||||
baos.write(block.streamSoundData);
|
||||
for (SoundStreamBlockTag block : blocks) {
|
||||
if (streamSoundCompression == SoundFormat.FORMAT_MP3) {
|
||||
ret.add(Arrays.copyOfRange(block.streamSoundData, 4, block.streamSoundData.length));
|
||||
} else {
|
||||
ret.add(block.streamSoundData);
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.tags;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
@@ -33,6 +34,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -170,13 +172,17 @@ public class SoundStreamHeadTag extends CharacterIdTag implements SoundStreamHea
|
||||
return streamSoundType;
|
||||
}
|
||||
|
||||
|
||||
public static void populateSoundStreamBlocks(int containerId,List<? extends ContainerItem> tags, Tag head, List<SoundStreamBlockTag> output) {
|
||||
boolean found = false;
|
||||
for (ContainerItem t : tags) {
|
||||
if (t == head) {
|
||||
found = true;
|
||||
((SoundStreamHeadTypeTag)head).setVirtualCharacterId(containerId);
|
||||
continue;
|
||||
}
|
||||
if (t instanceof Container) {
|
||||
populateSoundStreamBlocks(((CharacterIdTag)t).getCharacterId(),((Container) t).getSubItems(), head, output);
|
||||
}
|
||||
if (!found) {
|
||||
continue;
|
||||
}
|
||||
@@ -186,16 +192,13 @@ public class SoundStreamHeadTag extends CharacterIdTag implements SoundStreamHea
|
||||
if (t instanceof SoundStreamHeadTypeTag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t instanceof Container) {
|
||||
populateSoundStreamBlocks(((Container) t).getSubItems(), head, output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SoundStreamBlockTag> getBlocks() {
|
||||
List<SoundStreamBlockTag> ret = new ArrayList<>();
|
||||
List<SoundStreamBlockTag> ret = new ArrayList<>();
|
||||
populateSoundStreamBlocks(0,swf.tags, this, ret);
|
||||
return ret;
|
||||
|
||||
}
|
||||
@@ -211,21 +214,17 @@ public class SoundStreamHeadTag extends CharacterIdTag implements SoundStreamHea
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public List<byte[]> getRawSoundData() {
|
||||
List<byte[]> ret = new ArrayList<byte[]>();
|
||||
List<SoundStreamBlockTag> blocks = getBlocks();
|
||||
List<SoundStreamBlockTag> blocks = getBlocks();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
for (SoundStreamBlockTag block : blocks) {
|
||||
if (streamSoundCompression == SoundFormat.FORMAT_MP3) {
|
||||
baos.write(block.streamSoundData, 4, block.streamSoundData.length - 4);
|
||||
} else {
|
||||
baos.write(block.streamSoundData);
|
||||
for (SoundStreamBlockTag block : blocks) {
|
||||
if (streamSoundCompression == SoundFormat.FORMAT_MP3) {
|
||||
ret.add(Arrays.copyOfRange(block.streamSoundData, 4, block.streamSoundData.length));
|
||||
} else {
|
||||
ret.add(block.streamSoundData);
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.tags.base;
|
||||
|
||||
import com.jpexs.decompiler.flash.types.sound.SoundFormat;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -34,7 +36,7 @@ public interface SoundTag {
|
||||
|
||||
public boolean getSoundType();
|
||||
|
||||
|
||||
public List<byte[]> getRawSoundData();
|
||||
|
||||
public int getSoundFormatId();
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.types.sound;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
@@ -20,6 +21,7 @@ import com.jpexs.helpers.utf8.Utf8Helper;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.DataLine;
|
||||
@@ -161,10 +163,12 @@ public class SoundFormat {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean createWav(List<SWFInputStream> siss, OutputStream os) {
|
||||
ensureFormat();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
for(SWFInputStream sis:siss){
|
||||
decode(sis, baos);
|
||||
}
|
||||
try {
|
||||
createWavFromPcmData(os, samplingRate, true, stereo, baos.toByteArray());
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user