web-audio-recorder-ts 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +25 -3
- package/dist/index.esm.js +25 -3
- package/dist/index.umd.js +25 -3
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -99,14 +99,36 @@ class WebAudioRecorder {
|
|
|
99
99
|
}
|
|
100
100
|
try {
|
|
101
101
|
const inputBuffer = event.inputBuffer;
|
|
102
|
+
const actualChannels = inputBuffer.numberOfChannels;
|
|
102
103
|
const buffers = [];
|
|
103
|
-
// Extrair dados de cada canal
|
|
104
|
-
for (let channel = 0; channel <
|
|
104
|
+
// Extrair dados de cada canal disponível
|
|
105
|
+
for (let channel = 0; channel < actualChannels; channel++) {
|
|
105
106
|
const channelData = inputBuffer.getChannelData(channel);
|
|
106
107
|
buffers.push(new Float32Array(channelData));
|
|
107
108
|
}
|
|
109
|
+
// Se o número de canais do buffer não corresponde ao esperado, ajustar
|
|
110
|
+
if (actualChannels !== this.numChannels) {
|
|
111
|
+
if (actualChannels === 1 && this.numChannels === 2) {
|
|
112
|
+
// Mono -> Estéreo: duplicar o canal
|
|
113
|
+
buffers.push(new Float32Array(buffers[0]));
|
|
114
|
+
}
|
|
115
|
+
else if (actualChannels === 2 && this.numChannels === 1) {
|
|
116
|
+
// Estéreo -> Mono: usar apenas o primeiro canal
|
|
117
|
+
buffers.splice(1);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Outros casos: usar apenas os canais disponíveis até o limite esperado
|
|
121
|
+
while (buffers.length < this.numChannels && buffers.length > 0) {
|
|
122
|
+
// Duplicar o último canal se necessário
|
|
123
|
+
buffers.push(new Float32Array(buffers[buffers.length - 1]));
|
|
124
|
+
}
|
|
125
|
+
if (buffers.length > this.numChannels) {
|
|
126
|
+
buffers.splice(this.numChannels);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
108
130
|
// Codificar os dados
|
|
109
|
-
if (this.encoder) {
|
|
131
|
+
if (this.encoder && buffers.length > 0) {
|
|
110
132
|
this.encoder.encode(buffers);
|
|
111
133
|
}
|
|
112
134
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -96,14 +96,36 @@ class WebAudioRecorder {
|
|
|
96
96
|
}
|
|
97
97
|
try {
|
|
98
98
|
const inputBuffer = event.inputBuffer;
|
|
99
|
+
const actualChannels = inputBuffer.numberOfChannels;
|
|
99
100
|
const buffers = [];
|
|
100
|
-
// Extrair dados de cada canal
|
|
101
|
-
for (let channel = 0; channel <
|
|
101
|
+
// Extrair dados de cada canal disponível
|
|
102
|
+
for (let channel = 0; channel < actualChannels; channel++) {
|
|
102
103
|
const channelData = inputBuffer.getChannelData(channel);
|
|
103
104
|
buffers.push(new Float32Array(channelData));
|
|
104
105
|
}
|
|
106
|
+
// Se o número de canais do buffer não corresponde ao esperado, ajustar
|
|
107
|
+
if (actualChannels !== this.numChannels) {
|
|
108
|
+
if (actualChannels === 1 && this.numChannels === 2) {
|
|
109
|
+
// Mono -> Estéreo: duplicar o canal
|
|
110
|
+
buffers.push(new Float32Array(buffers[0]));
|
|
111
|
+
}
|
|
112
|
+
else if (actualChannels === 2 && this.numChannels === 1) {
|
|
113
|
+
// Estéreo -> Mono: usar apenas o primeiro canal
|
|
114
|
+
buffers.splice(1);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// Outros casos: usar apenas os canais disponíveis até o limite esperado
|
|
118
|
+
while (buffers.length < this.numChannels && buffers.length > 0) {
|
|
119
|
+
// Duplicar o último canal se necessário
|
|
120
|
+
buffers.push(new Float32Array(buffers[buffers.length - 1]));
|
|
121
|
+
}
|
|
122
|
+
if (buffers.length > this.numChannels) {
|
|
123
|
+
buffers.splice(this.numChannels);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
105
127
|
// Codificar os dados
|
|
106
|
-
if (this.encoder) {
|
|
128
|
+
if (this.encoder && buffers.length > 0) {
|
|
107
129
|
this.encoder.encode(buffers);
|
|
108
130
|
}
|
|
109
131
|
}
|
package/dist/index.umd.js
CHANGED
|
@@ -103,14 +103,36 @@
|
|
|
103
103
|
}
|
|
104
104
|
try {
|
|
105
105
|
const inputBuffer = event.inputBuffer;
|
|
106
|
+
const actualChannels = inputBuffer.numberOfChannels;
|
|
106
107
|
const buffers = [];
|
|
107
|
-
// Extrair dados de cada canal
|
|
108
|
-
for (let channel = 0; channel <
|
|
108
|
+
// Extrair dados de cada canal disponível
|
|
109
|
+
for (let channel = 0; channel < actualChannels; channel++) {
|
|
109
110
|
const channelData = inputBuffer.getChannelData(channel);
|
|
110
111
|
buffers.push(new Float32Array(channelData));
|
|
111
112
|
}
|
|
113
|
+
// Se o número de canais do buffer não corresponde ao esperado, ajustar
|
|
114
|
+
if (actualChannels !== this.numChannels) {
|
|
115
|
+
if (actualChannels === 1 && this.numChannels === 2) {
|
|
116
|
+
// Mono -> Estéreo: duplicar o canal
|
|
117
|
+
buffers.push(new Float32Array(buffers[0]));
|
|
118
|
+
}
|
|
119
|
+
else if (actualChannels === 2 && this.numChannels === 1) {
|
|
120
|
+
// Estéreo -> Mono: usar apenas o primeiro canal
|
|
121
|
+
buffers.splice(1);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// Outros casos: usar apenas os canais disponíveis até o limite esperado
|
|
125
|
+
while (buffers.length < this.numChannels && buffers.length > 0) {
|
|
126
|
+
// Duplicar o último canal se necessário
|
|
127
|
+
buffers.push(new Float32Array(buffers[buffers.length - 1]));
|
|
128
|
+
}
|
|
129
|
+
if (buffers.length > this.numChannels) {
|
|
130
|
+
buffers.splice(this.numChannels);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
112
134
|
// Codificar os dados
|
|
113
|
-
if (this.encoder) {
|
|
135
|
+
if (this.encoder && buffers.length > 0) {
|
|
114
136
|
this.encoder.encode(buffers);
|
|
115
137
|
}
|
|
116
138
|
}
|
package/package.json
CHANGED