new Signal naming

robbi-inspect
Khaled Aldayeh 2024-01-09 21:19:13 +01:00
parent 653b9220f8
commit 5e334d3bfd
4 changed files with 65 additions and 55 deletions

View File

@ -2,6 +2,7 @@
<div>
<button @click="startMicrophone">Start Microphone</button>
<button @click="stopMicrophone">Stop Microphone</button>
<canvas ref="visualizationCanvas" width="800" height="200"></canvas>
<div v-if="errorMessage">{{ errorMessage }}</div>
</div>
</template>

View File

@ -6,7 +6,7 @@
poster="/images/poster.png"
>
<div class="container-fluid overflow-auto" >
<div class="row"> <BandProcessor /> </div>
<div class="row"> <BandProcessor /> <ChannelStreamer /> </div>
<div class="row ">
<div class="col-12 col-lg-4 bg-img d-none d-lg-block" style="background-image: url('/images/login.svg');background-size: cover;height: 100vh;" >
</div>
@ -78,6 +78,7 @@ import backgroundImagePath from '~/assets/image/login4.png';
import {useUserStore} from '@/stores/user';
import {mapState,mapActions} from "pinia";
import BandProcessor from "@/components/BandProcessor";
import ChannelStreamer from "@/pages/ChannelStreamer";
export default {
setup() {
@ -90,7 +91,7 @@ export default {
}
},
//Components BEGIN
components: {BandProcessor},
components: {BandProcessor,ChannelStreamer},
//Components END
mounted() {
// if (this.is_login){

View File

View File

@ -2,10 +2,12 @@ class OctaveBandProcessor extends AudioWorkletProcessor {
constructor() {
super()
// Define center frequencies for 9 octave bands
this.centerFrequencies = [63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000]
this.filters = []
this.lastUpdateTimestamp = 0
this.updateInterval = 0.125 // Update every 0.125 seconds
this.filteredMicSignal =[]
// Create an A-weighting filter for specific frequencies
this.createAWeightingFilter()
@ -47,22 +49,28 @@ class OctaveBandProcessor extends AudioWorkletProcessor {
}
process(inputs, outputs) {
const numOutputChannels = outputs.length
for (let i = 0; i < numOutputChannels; i++) {
const outputChannel = outputs[i][0]
const inputChannel = inputs[i][0]
const numOutputoctaves = filters.length
for (let i = 0; i < numOutputoctaves; i++) {
// const outputChannel = outputs[i][0]
const mic = inputs[0]
const maskingsig = inputs[1]
const harmonic = inputs[2]
// Apply the filter to the input channel
const filteredSignal = this.filters[i].process(inputChannel)
const filteredMicSignal[i] = this.filters[i].process(mic)
const filteredMaskSignal = this.filters[i].process(maskingsig)
const filteredHarmoSignal = this.filters[i].process(harmonic)
// Apply A-weighting only to the microphone signal (channel 0)
if (i === 0) {
const aWeightedSignal = this.aWeightingFilter.process(filteredSignal)
const aWeightedSignal[i] = this.aWeightingFilter.process(filteredMicSignal)
this.calculateRMSLevel(aWeightedSignal)
outputChannel.set(aWeightedSignal)
} else {
// For other channels, pass the signal without A-weighting
outputChannel.set(filteredSignal)
}
// Check if it's time to update percentiles
const currentTime = this.currentTime
@ -86,8 +94,8 @@ class OctaveBandProcessor extends AudioWorkletProcessor {
updatePercentiles(channelIndex) {
for (let i = 0; i < this.centerFrequencies.length; i++) {
const analyzer = this.analyzers[i][channelIndex]
const levelData = new Float32Array(analyzer.frequencyBinCount)
//const analyzer = this.analyzers[i][channelIndex]
//const levelData = new Float32Array(analyzer.frequencyBinCount)
analyzer.getFloatFrequencyData(levelData)
// Calculate percentiles for each octave band and each channel
@ -114,59 +122,59 @@ class OctaveBandProcessor extends AudioWorkletProcessor {
] //David
// Create a custom IIR filter node with the A-weighting coefficients
this.aWeightingFilter = new IIRFilterNode(audioContext, {
this.aWeightingFilter = new IIRFilterNode(audioContext, { //infinit Impuls Response
feedforward: aWeightingCoefficients,
feedback: [1],
})
}
combineAndCalculate() {
let LAF10_90_total = 0 // Initialize the total LAF10%-90%
// combineAndCalculate() {
// let LAF10_90_total = 0 // Initialize the total LAF10%-90%
for (let i = 0; i < this.centerFrequencies.length; i++) {
const micAnalyzer = this.analyzers[i][0] // Analyzer for microphone audio (identifier 0)
const audioFile1Analyzer = this.analyzers[i][3] // Analyzer for audioFile1 (identifier 3)
const audioFile2Analyzer = this.analyzers[i][4] // Analyzer for audioFile2 (identifier 4)
// for (let i = 0; i < this.centerFrequencies.length; i++) {
// const micAnalyzer = this.analyzers[i][0] // Analyzer for microphone audio (identifier 0)
// const audioFile1Analyzer = this.analyzers[i][3] // Analyzer for audioFile1 (identifier 3)
// const audioFile2Analyzer = this.analyzers[i][4] // Analyzer for audioFile2 (identifier 4)
// Calculate percentiles for the microphone audio
const micPercentile10 = this.calculatePercentile(micAnalyzer, 10)
const micPercentile90 = this.calculatePercentile(micAnalyzer, 90)
// // Calculate percentiles for the microphone audio
// const micPercentile10 = this.calculatePercentile(micAnalyzer, 10)
// const micPercentile90 = this.calculatePercentile(micAnalyzer, 90)
// Calculate percentiles for audioFile1
const audioFile1Percentile10 = this.calculatePercentile(
audioFile1Analyzer,
10,
)
const audioFile1Percentile90 = this.calculatePercentile(
audioFile1Analyzer,
90,
)
// // Calculate percentiles for audioFile1
// const audioFile1Percentile10 = this.calculatePercentile(
// audioFile1Analyzer,
// 10,
// )
// const audioFile1Percentile90 = this.calculatePercentile(
// audioFile1Analyzer,
// 90,
// )
// Calculate percentiles for audioFile2
const audioFile2Percentile10 = this.calculatePercentile(
audioFile2Analyzer,
10,
)
const audioFile2Percentile90 = this.calculatePercentile(
audioFile2Analyzer,
90,
)
// // Calculate percentiles for audioFile2
// const audioFile2Percentile10 = this.calculatePercentile(
// audioFile2Analyzer,
// 10,
// )
// const audioFile2Percentile90 = this.calculatePercentile(
// audioFile2Analyzer,
// 90,
// )
// Calculate LAF10%-90% for microphone audio, audioFile1, and audioFile2 separately
const micLAF10_90 = micPercentile10 - micPercentile90
const audioFile1LAF10_90 = audioFile1Percentile10 - audioFile1Percentile90
const audioFile2LAF10_90 = audioFile2Percentile10 - audioFile2Percentile90
// // Calculate LAF10%-90% for microphone audio, audioFile1, and audioFile2 separately
// const micLAF10_90 = micPercentile10 - micPercentile90
// const audioFile1LAF10_90 = audioFile1Percentile10 - audioFile1Percentile90
// const audioFile2LAF10_90 = audioFile2Percentile10 - audioFile2Percentile90
// Calculate combined LAF10%-90% for microphone audio, audioFile1, and audioFile2
const combinedLAF10_90 =
micLAF10_90 + audioFile1LAF10_90 + audioFile2LAF10_90
// // Calculate combined LAF10%-90% for microphone audio, audioFile1, and audioFile2
// const combinedLAF10_90 =
// micLAF10_90 + audioFile1LAF10_90 + audioFile2LAF10_90
// Add the combined LAF10%-90% to the total
LAF10_90_total += combinedLAF10_90
}
// // Add the combined LAF10%-90% to the total
// LAF10_90_total += combinedLAF10_90
// }
// return LAF10_90_total;
}
// // return LAF10_90_total;
// }
}
registerProcessor("octave", OctaveBandProcessor)