mirror of
https://github.com/scratchfoundation/scratch-sb1-converter.git
synced 2025-03-17 02:10:01 -04:00
Merge pull request #30 from kchadha/fix-sound-md5s
fix: fix sound md5s in generated sb2 json
This commit is contained in:
commit
6015419817
3 changed files with 21 additions and 7 deletions
|
@ -1,11 +1,14 @@
|
|||
import {CRC32} from '../coders/crc32';
|
||||
import {SqueakImage} from '../coders/squeak-image';
|
||||
import {SqueakSound} from '../coders/squeak-sound';
|
||||
import {WAVFile} from '../coders/wav-file';
|
||||
|
||||
import {FieldObject} from './field-object';
|
||||
import {value as valueOf} from './fields';
|
||||
import {TYPES} from './ids';
|
||||
|
||||
import md5 from 'js-md5';
|
||||
|
||||
/**
|
||||
* @extends FieldObject
|
||||
*/
|
||||
|
@ -342,6 +345,22 @@ class SoundMediaData extends FieldObject.define({
|
|||
return 'pcm';
|
||||
}
|
||||
|
||||
get wavEncodedData () {
|
||||
if (!this._wavEncodedData) {
|
||||
this._wavEncodedData = new Uint8Array(WAVFile.encode(this.decoded, {
|
||||
sampleRate: this.rate && this.rate.value
|
||||
}));
|
||||
}
|
||||
return this._wavEncodedData;
|
||||
}
|
||||
|
||||
get md5 () {
|
||||
if (!this._md5) {
|
||||
this._md5 = md5(this.wavEncodedData);
|
||||
}
|
||||
return this._md5;
|
||||
}
|
||||
|
||||
toString () {
|
||||
return `SoundMediaData "${this.name}"`;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import {assert} from '../util/assert';
|
||||
|
||||
import {PNGFile} from '../coders/png-file';
|
||||
import {WAVFile} from '../coders/wav-file';
|
||||
|
||||
class FakeZipFile {
|
||||
constructor (file) {
|
||||
|
@ -49,11 +48,7 @@ const toSb2ImageMedia = imageMedia => {
|
|||
return imageMedia.decoded;
|
||||
};
|
||||
|
||||
const toSb2SoundMedia = soundMedia => (
|
||||
new Uint8Array(WAVFile.encode(soundMedia.decoded, {
|
||||
sampleRate: soundMedia.rate && soundMedia.rate.value
|
||||
}))
|
||||
);
|
||||
const toSb2SoundMedia = soundMedia => soundMedia.wavEncodedData;
|
||||
|
||||
const toSb2FakeZipApi = ({images, sounds}) => {
|
||||
const files = {};
|
||||
|
|
|
@ -94,7 +94,7 @@ const toSb2Json = root => {
|
|||
return {
|
||||
soundName: soundMediaData.name,
|
||||
soundID,
|
||||
md5: `${md5(soundMediaData.rawBytes)}.wav`,
|
||||
md5: `${soundMediaData.md5}.wav`,
|
||||
sampleCount: soundMediaData.sampleCount,
|
||||
rate: soundMediaData.rate,
|
||||
format: ''
|
||||
|
|
Loading…
Reference in a new issue