soiz1 commited on
Commit
2fba335
·
verified ·
1 Parent(s): cba8b40

Update src/containers/sound-editor.jsx

Browse files
Files changed (1) hide show
  1. src/containers/sound-editor.jsx +5 -5
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 = soundIndex < sprite.sounds.length ? soundIndex : sprite.sounds.length - 1;
777
- const sound = state.scratchGui.vm.editingTarget.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,
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,