{"record":{"id":"b89a1470d84f96a4","repo":"remotion-dev/remotion","slug":"pitch-shifter-was-not-initialized","errorCode":null,"errorMessage":"Pitch shifter was not initialized.","messagePattern":"Pitch shifter was not initialized\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media/src/audio/pitch-shift.ts","lineNumber":614,"sourceCode":"\t\t\tconst previousSegmentFinalSlice = flush();\n\t\t\tif (previousSegmentFinalSlice) {\n\t\t\t\tyield previousSegmentFinalSlice;\n\t\t\t}\n\n\t\t\tsampleRate = nextSampleRate;\n\t\t\tnumberOfChannels = nextNumberOfChannels;\n\t\t\tsegmentStart = slice.timelineTimestamp;\n\t\t\tsegmentInputFrames = 0;\n\t\t\tsegmentOutputFrames = 0;\n\t\t\tshifter = new StreamingPitchShifter({\n\t\t\t\tnumberOfChannels,\n\t\t\t\tsampleRate,\n\t\t\t\ttoneFrequency,\n\t\t\t});\n\t\t}\n\n\t\tif (!shifter) {\n\t\t\tthrow new Error('Pitch shifter was not initialized.');\n\t\t}\n\n\t\tsegmentInputFrames += planar[0].length;\n\t\tconst output = shifter.append(planar);\n\t\tif (output[0].length > 0) {\n\t\t\tyield makeAudioBufferSlice({\n\t\t\t\taudio: output,\n\t\t\t\ttimelineTimestamp: segmentStart + segmentOutputFrames / sampleRate,\n\t\t\t\tsampleRate,\n\t\t\t});\n\t\t\tsegmentOutputFrames += output[0].length;\n\t\t}\n\t}\n\n\tconst finalSlice = flush();\n\tif (finalSlice) {\n\t\tyield finalSlice;\n\t}","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/remotion-dev/remotion/blob/a6a7485a9aeb04219510fbe4874f8941486424df/packages/media/src/audio/pitch-shift.ts#L596-L632","documentation":"Inside pitchShiftAudioIterator, the shifter is created lazily when a segment starts. The null check before append is a defensive invariant: if control flow ever reaches append without a shifter having been constructed, it throws this error. It should be unreachable in normal use and indicates corrupted segment/state handling in the streaming pipeline.","triggerScenarios":"Custom or patched iterator code reaching the append call while startsNewSegment failed to create a shifter; calling pitchShiftAudioIterator internals with an iterator that yields slices lacking valid sampleRate/numberOfChannels so shifter construction paths are bypassed.","commonSituations":"Forked/modified versions of pitchShiftAudioIterator; feeding empty or malformed audio buffers; upgrading @remotion/media and mixing internal helpers across versions.","solutions":["Use pitchShiftAudioIterator unmodified with a valid audio iterator as input","Ensure yielded slices have real buffers with valid sampleRate/numberOfChannels (skip empty slices)","Upgrade @remotion/media to latest — if reachable, it is a bug worth reporting","Do not mix internal pitch-shift helpers from different package versions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Only feed valid slices into pitchShiftAudioIterator\nfor await (const slice of iterator) {\n  if (!slice.buffer.buffer || slice.buffer.buffer.sampleRate <= 0) continue;\n}","typeGuard":null,"tryCatchPattern":"try {\n  yield* pitchShiftAudioIterator(audioIterator, toneFrequency);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Pitch shifter was not initialized.') {\n    console.error('Pitch shift pipeline received malformed audio segments');\n  } else throw e;\n}","preventionTips":["Use pitchShiftAudioIterator unmodified from @remotion/media","Feed it a well-formed AudioBufferIterator with valid sampleRate/numberOfChannels","Skip or filter empty/malformed slices upstream","Do not mix internal pitch-shift helpers across package versions"],"tags":["audio","pitch-shift","media","invariant"],"backgroundTag":"invariant-violation","analyzedSha":"a6a7485a9aeb04219510fbe4874f8941486424df","analyzedAt":"2026-09-02T16:25:19.997Z","contentChangedAt":"2026-09-02T16:25:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}