fix: déformation audio par saturation du mixage
Problème: - Son complètement déformé (clipping massif) - CoreAudio capture en 32-bit mais traité comme 16-bit - Mixage additif sans normalisation Solution: 1. Sox convertit 32→16 bit automatiquement 2. GroupAudioRouter divise gain par nombre de sources Exemple: 2 inputs → groupe default = gain × 0.5 chacun Résultat: Aucun clipping détecté, audio propre
This commit is contained in:
@@ -216,6 +216,21 @@ export class GroupAudioRouter extends EventEmitter {
|
||||
this.groupBuffers.set(groupId, new Float32Array(this.config.frameSize));
|
||||
});
|
||||
|
||||
// Compter le nombre de sources par groupe pour normalisation
|
||||
const groupSourceCount = new Map();
|
||||
inputChannelsData.forEach((_, channelId) => {
|
||||
const key = `in_${channelId}`;
|
||||
const routes = this.inputToGroupRoutes.get(key);
|
||||
if (routes) {
|
||||
routes.forEach(route => {
|
||||
groupSourceCount.set(
|
||||
route.destination,
|
||||
(groupSourceCount.get(route.destination) || 0) + 1
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Pour chaque canal d'entrée
|
||||
inputChannelsData.forEach((pcmData, channelId) => {
|
||||
const key = `in_${channelId}`;
|
||||
@@ -234,9 +249,12 @@ export class GroupAudioRouter extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mixage avec gain
|
||||
// Mixage avec gain + atténuation par nombre de sources
|
||||
const sourceCount = groupSourceCount.get(route.destination) || 1;
|
||||
const mixGain = route.linearGain / sourceCount;
|
||||
|
||||
for (let i = 0; i < pcmData.length && i < groupBuffer.length; i++) {
|
||||
groupBuffer[i] += pcmData[i] * route.linearGain;
|
||||
groupBuffer[i] += pcmData[i] * mixGain;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -191,19 +191,17 @@ export class CoreAudioBackend extends EventEmitter {
|
||||
|
||||
const args = [];
|
||||
|
||||
// Spécifier le device d'entrée
|
||||
// Spécifier le device d'entrée (CoreAudio capture en 32-bit natif)
|
||||
if (this.options.inputDeviceName) {
|
||||
// Utiliser le device spécifié par son nom
|
||||
args.push('-t', 'coreaudio', this.options.inputDeviceName);
|
||||
} else {
|
||||
// Device par défaut
|
||||
args.push('-d');
|
||||
}
|
||||
|
||||
// Format de sortie (stdout)
|
||||
// Format de sortie (stdout) - convertir 32→16 bit
|
||||
args.push(
|
||||
'-t', 'raw',
|
||||
'-b', '16',
|
||||
'-t', 'raw', // Format sortie raw PCM
|
||||
'-b', '16', // Convertir vers 16-bit
|
||||
'-e', 'signed-integer',
|
||||
'-c', String(this.options.channels),
|
||||
'-r', String(this.options.sampleRate),
|
||||
|
||||
Reference in New Issue
Block a user