MCPcopy Create free account
hub / github.com/NVIDIA/personaplex / process

Method process

client/src/audio-processor.ts:132–183  ·  view source on GitHub ↗
(inputs, outputs, parameters)

Source from the content-addressed store, hash-verified

130 }
131
132 process(inputs, outputs, parameters) {
133 let delay = this.currentSamples() / sampleRate;
134 if (this.canPlay()) {
135 this.maxDelay = Math.max(this.maxDelay, delay);
136 this.minDelay = Math.min(this.minDelay, delay);
137 }
138 const output = outputs[0][0];
139 if (!this.canPlay()) {
140 if (this.actualAudioPlayed > 0) {
141 this.totalAudioPlayed += output.length / sampleRate;
142 }
143 this.remainingPartialBufferSamples -= output.length;
144 return true;
145 }
146 if (this.firstOut) {
147 console.log(this.timestamp(), "Audio resumed", asMs(this.currentSamples()), this.remainingPartialBufferSamples);
148 }
149 let first = this.frames[0];
150 let out_idx = 0;
151 while (out_idx < output.length && this.frames.length) {
152 let first = this.frames[0];
153 let to_copy = Math.min(first.length - this.offsetInFirstBuffer, output.length - out_idx);
154 output.set(first.subarray(this.offsetInFirstBuffer, this.offsetInFirstBuffer + to_copy), out_idx);
155 this.offsetInFirstBuffer += to_copy;
156 out_idx += to_copy;
157 if (this.offsetInFirstBuffer == first.length) {
158 this.offsetInFirstBuffer = 0;
159 this.frames.shift();
160 }
161 }
162 if (this.firstOut) {
163 this.firstOut = false;
164 for (let i = 0; i < out_idx; i++) {
165 output[i] *= i / out_idx;
166 }
167 }
168 if (out_idx < output.length) {
169 console.log(this.timestamp(), "Missed some audio", output.length - out_idx);
170 this.partialBufferSamples += this.partialBufferIncrement;
171 this.partialBufferSamples = Math.min(this.partialBufferSamples, this.maxPartialWithIncrements);
172 console.log("Increased partial buffer to", asMs(this.partialBufferSamples));
173 // We ran out of a buffer, let's revert to the started state to replenish it.
174 this.resetStart();
175 for (let i = 0; i < out_idx; i++) {
176 output[i] *= (out_idx - i) / out_idx;
177 }
178 }
179 this.totalAudioPlayed += output.length / sampleRate;
180 this.actualAudioPlayed += out_idx / sampleRate;
181 this.timeInStream += out_idx / sampleRate;
182 return true;
183 }
184}
185registerProcessor("moshi-processor", MoshiProcessor);

Callers

nothing calls this directly

Calls 6

currentSamplesMethod · 0.95
canPlayMethod · 0.95
timestampMethod · 0.95
resetStartMethod · 0.95
asMsFunction · 0.85
logMethod · 0.45

Tested by

no test coverage detected