Skip to content

Commit 5ccb92f

Browse files
committed
Trying to workaround the bug in loadPCMFromByteArray
1 parent ce8a90d commit 5ccb92f

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/scratch/ScratchSound.as

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class ScratchSound {
5858
this.soundName = name;
5959
if (sndData != null) {
6060
try {
61-
var info:* = WAVFile.decode(sndData);
61+
var info:Object = WAVFile.decode(sndData);
6262
if ([1, 3, 17].indexOf(info.encoding) == -1) throw Error('Unsupported WAV format');
6363
soundData = sndData;
6464
if (info.encoding == 17)

src/sound/WAVFile.as

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class WAVFile {
9191
result.sampleCount = (result.bitsPerSample == 8) ? result.sampleDataSize : result.sampleDataSize / 2;
9292
} else if (encoding == 3) {
9393
result.sampleCount = Math.floor(result.sampleDataSize / (result.bitsPerSample >>> 3));
94+
waveData.position = result.sampleDataStart;
9495
} else if (encoding == 17) {
9596
if (formatChunk.length < 20) throw Error("WAVFile: adpcm format chunk is too small");
9697
if (result.channels != 1) throw Error("WAVFile: adpcm supports only one channel (monophonic)");

src/sound/mp3/MP3Loader.as

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class MP3Loader {
5757
function convertNextChunk():void {
5858
buf.position = 0;
5959
var count:int = mp3Snd.extract(buf, 4000);
60-
if (count == 0) { // finished!
60+
if (count == 0 || convertedSamples >= mp3SampleCount) { // finished!
6161
if (Scratch.app.lp) Scratch.app.lp.setTitle('Compressing...');
6262
setTimeout(compressSamples, 50);
6363
return;

src/ui/media/MediaLibrary.as

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,16 @@ spriteFeaturesFilter.visible = false; // disable features filter for now
686686
SCRATCH::allow3d {
687687
sound = new Sound();
688688
try {
689-
if (snd && snd.format == 'float')
690-
sound.loadPCMFromByteArray(data, snd.sampleCount / snd.channels, "float", snd.channels == 2, snd.rate);
691-
else {
689+
var sampleCount:uint = 0;
690+
if (snd && snd.format == 'float') {
691+
sampleCount = snd.sampleCount / snd.channels;
692+
sound.loadPCMFromByteArray(snd.soundData, sampleCount, "float", snd.channels == 2, snd.rate);
693+
} else {
692694
data.position = 0;
693695
sound.loadCompressedDataFromByteArray(data, data.length);
696+
sampleCount = sound.length * 44.1;
694697
}
695-
MP3Loader.extractSamples(origName, sound, sound.length * 44.1, function (out:ScratchSound):void {
698+
MP3Loader.extractSamples(origName, sound, sampleCount, function (out:ScratchSound):void {
696699
snd = out;
697700
startSoundUpload(out, origName, uploadComplete);
698701
});

0 commit comments

Comments
 (0)