Spaces:
Build error
Build error
Update src/containers/sound-editor.jsx
Browse files
src/containers/sound-editor.jsx
CHANGED
@@ -773,17 +773,17 @@ SoundEditor.propTypes = {
|
|
773 |
const mapStateToProps = (state, { soundIndex }) => {
|
774 |
const sprite = state.scratchGui.vm.editingTarget.sprite;
|
775 |
// Make sure the sound index doesn't go out of range.
|
776 |
-
const index =
|
777 |
-
const sound =
|
778 |
const audioBuffer = state.scratchGui.vm.getSoundBuffer(index);
|
779 |
return {
|
780 |
-
isStereo: audioBuffer
|
781 |
duration: sound.sampleCount / sound.rate,
|
782 |
size: sound.asset ? sound.asset.data.byteLength : 0,
|
783 |
soundId: sound.soundId,
|
784 |
dataFormat: sound.dataFormat,
|
785 |
-
sampleRate: audioBuffer
|
786 |
-
samples: audioBuffer.getChannelData(0),
|
787 |
isFullScreen: state.scratchGui.mode.isFullScreen,
|
788 |
name: sound.name,
|
789 |
vm: state.scratchGui.vm,
|
|
|
773 |
const mapStateToProps = (state, { soundIndex }) => {
|
774 |
const sprite = state.scratchGui.vm.editingTarget.sprite;
|
775 |
// Make sure the sound index doesn't go out of range.
|
776 |
+
const index = Math.min(sprite.sounds.length - 1, Math.max(0, soundIndex));
|
777 |
+
const sound = sprite.sounds[index] ?? {};
|
778 |
const audioBuffer = state.scratchGui.vm.getSoundBuffer(index);
|
779 |
return {
|
780 |
+
isStereo: audioBuffer?.numberOfChannels !== 1,
|
781 |
duration: sound.sampleCount / sound.rate,
|
782 |
size: sound.asset ? sound.asset.data.byteLength : 0,
|
783 |
soundId: sound.soundId,
|
784 |
dataFormat: sound.dataFormat,
|
785 |
+
sampleRate: audioBuffer?.sampleRate ?? 3000,
|
786 |
+
samples: audioBuffer ? audioBuffer.getChannelData(0) : new Float32Array(1),
|
787 |
isFullScreen: state.scratchGui.mode.isFullScreen,
|
788 |
name: sound.name,
|
789 |
vm: state.scratchGui.vm,
|