Merge pull request #30 from kchadha/fix-sound-md5s

fix: fix sound md5s in generated sb2 json
This commit is contained in:
Karishma Chadha 2018-12-21 14:04:57 -05:00 committed by GitHub
commit 6015419817
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View file

@ -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}"`;
}

View file

@ -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 = {};

View file

@ -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: ''