{"id":363,"date":"2025-12-10T15:34:20","date_gmt":"2025-12-10T14:34:20","guid":{"rendered":"https:\/\/komfortakustyczny.pl\/?page_id=363"},"modified":"2025-12-10T15:40:57","modified_gmt":"2025-12-10T14:40:57","slug":"pomiar","status":"publish","type":"page","link":"https:\/\/komfortakustyczny.pl\/index.php\/pomiar\/","title":{"rendered":"Pomiar"},"content":{"rendered":"\n<div id=\"sound-meter\">\n  <button id=\"startButton\">Start pomiaru ha\u0142asu<\/button>\n  <button id=\"stopButton\" disabled>Zatrzymaj pomiar<\/button>\n  \n  <div style=\"margin-top:15px;\">\n    Aktualny estymowany poziom (umowne dB)*: <span id=\"level\">0<\/span> <\/br>\n*nale\u017cy zwr\u00f3ci\u0107 uwag\u0119, \u017ce wykonany pomiar jest tylko pomiarem pogl\u0105dowym (szacowanym).\n  <\/div>\n\n  <div style=\"margin-top:10px; width:300px; height:20px; border:1px solid #ccc;\">\n    <div id=\"bar\" style=\"height:100%; width:0%; background:#4caf50;\"><\/div>\n  <\/div>\n<\/div>\n\n<script>\n(function () {\n  const startButton = document.getElementById('startButton');\n  const stopButton = document.getElementById('stopButton');\n  const levelSpan = document.getElementById('level');\n  const bar = document.getElementById('bar');\n\n  let audioContext = null;\n  let analyser = null;\n  let dataArray = null;\n  let stream = null;\n  let running = false;\n\n  async function initAudio() {\n    stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });\n\n    audioContext = new (window.AudioContext || window.webkitAudioContext)();\n    const source = audioContext.createMediaStreamSource(stream);\n\n    analyser = audioContext.createAnalyser();\n    analyser.fftSize = 2048;\n\n    dataArray = new Uint8Array(analyser.fftSize);\n    source.connect(analyser);\n  }\n\n  function update() {\n    if (!running || !analyser) return;\n\n    analyser.getByteTimeDomainData(dataArray);\n\n    let sumSquares = 0;\n    for (let i = 0; i < dataArray.length; i++) {\n      const sample = (dataArray[i] - 128) \/ 128;\n      sumSquares += sample * sample;\n    }\n\n    const rms = Math.sqrt(sumSquares \/ dataArray.length);\n    const db = Math.round(20 * Math.log10(rms || 0.000001) + 100);\n    const clamped = Math.max(0, Math.min(db, 100));\n\n    levelSpan.textContent = clamped;\n    bar.style.width = clamped + '%';\n\n    requestAnimationFrame(update);\n  }\n\n  startButton.addEventListener('click', async () => {\n    try {\n      await initAudio();\n      running = true;\n      update();\n\n      startButton.disabled = true;\n      stopButton.disabled = false;\n      startButton.textContent = 'Pomiar aktywny';\n    } catch (e) {\n      alert('Nie uda\u0142o si\u0119 uzyska\u0107 dost\u0119pu do mikrofonu: ' + e.message);\n    }\n  });\n\n  stopButton.addEventListener('click', () => {\n    running = false;\n\n    if (audioContext) {\n      audioContext.close();\n      audioContext = null;\n    }\n\n    if (stream) {\n      stream.getTracks().forEach(track => track.stop());\n      stream = null;\n    }\n\n    levelSpan.textContent = \"0\";\n    bar.style.width = \"0%\";\n\n    startButton.disabled = false;\n    stopButton.disabled = true;\n    startButton.textContent = 'Start pomiaru ha\u0142asu';\n  });\n})();\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>Start pomiaru ha\u0142asu Zatrzymaj pomiar Aktualny estymowany poziom (umowne dB)*: 0 *nale\u017cy zwr\u00f3ci\u0107 uwag\u0119, \u017ce wykonany pomiar jest tylko pomiarem pogl\u0105dowym (szacowanym).<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"class_list":["post-363","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/komfortakustyczny.pl\/index.php\/wp-json\/wp\/v2\/pages\/363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/komfortakustyczny.pl\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/komfortakustyczny.pl\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/komfortakustyczny.pl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/komfortakustyczny.pl\/index.php\/wp-json\/wp\/v2\/comments?post=363"}],"version-history":[{"count":5,"href":"https:\/\/komfortakustyczny.pl\/index.php\/wp-json\/wp\/v2\/pages\/363\/revisions"}],"predecessor-version":[{"id":370,"href":"https:\/\/komfortakustyczny.pl\/index.php\/wp-json\/wp\/v2\/pages\/363\/revisions\/370"}],"wp:attachment":[{"href":"https:\/\/komfortakustyczny.pl\/index.php\/wp-json\/wp\/v2\/media?parent=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}