How should i change the listener position in web audio












0















I am having troubles trying to update the context.listener's position (each requestAnimationFrame) in an application using Web Audio. I have made a test environment here with some variations but none of them seems to really work.



This is what i assume the correct approach is:



listener.positionX.value = pos.x;      
listener.positionY.value = pos.y;
listener.positionZ.value = pos.z;


The issue i am having is that the sound is being completely distorted, and turning the source volume down does not help. (this may very well be a bug in Chrome OSX, since i don't remember having any issues when i made something similar before, which i ran on Chrome Windows)



I also tried doing this (these 2 lines should be exactly the same btw), but that didn't help either:



listener.positionX.setValueAtTime(pos.x, 0); 
listener.positionX.setValueAtTime(pos.x, context.currentTime);


Then i tried the old and deprecated command to do this, and that sounds way better but still has slight distortion:



listener.setPosition(pos.x, pos.y, pos.z);


The one that seems to work best is to do a linear ramp:



listener.positionX.linearRampToValueAtTime(pos.x, context.currentTime + 0.1);      


But doing a new ramp on every frame is not really the correct approach, since ongoing ramps are cancelled and i think it takes the value before the cancelled ramp as the starting value for the new ramp. Also: when i then NOT update the value (i added that as an option in that codepen), it seems to jump back to a previous value, which leads me to think that that is maybe also the cause for the major distortion i hear when doing the ver first approach (setting the value by positionX.value = pos.x)



Am i doing something wrong, or am i overlooking something? How should i correctly set the listener's position on every frame?










share|improve this question



























    0















    I am having troubles trying to update the context.listener's position (each requestAnimationFrame) in an application using Web Audio. I have made a test environment here with some variations but none of them seems to really work.



    This is what i assume the correct approach is:



    listener.positionX.value = pos.x;      
    listener.positionY.value = pos.y;
    listener.positionZ.value = pos.z;


    The issue i am having is that the sound is being completely distorted, and turning the source volume down does not help. (this may very well be a bug in Chrome OSX, since i don't remember having any issues when i made something similar before, which i ran on Chrome Windows)



    I also tried doing this (these 2 lines should be exactly the same btw), but that didn't help either:



    listener.positionX.setValueAtTime(pos.x, 0); 
    listener.positionX.setValueAtTime(pos.x, context.currentTime);


    Then i tried the old and deprecated command to do this, and that sounds way better but still has slight distortion:



    listener.setPosition(pos.x, pos.y, pos.z);


    The one that seems to work best is to do a linear ramp:



    listener.positionX.linearRampToValueAtTime(pos.x, context.currentTime + 0.1);      


    But doing a new ramp on every frame is not really the correct approach, since ongoing ramps are cancelled and i think it takes the value before the cancelled ramp as the starting value for the new ramp. Also: when i then NOT update the value (i added that as an option in that codepen), it seems to jump back to a previous value, which leads me to think that that is maybe also the cause for the major distortion i hear when doing the ver first approach (setting the value by positionX.value = pos.x)



    Am i doing something wrong, or am i overlooking something? How should i correctly set the listener's position on every frame?










    share|improve this question

























      0












      0








      0








      I am having troubles trying to update the context.listener's position (each requestAnimationFrame) in an application using Web Audio. I have made a test environment here with some variations but none of them seems to really work.



      This is what i assume the correct approach is:



      listener.positionX.value = pos.x;      
      listener.positionY.value = pos.y;
      listener.positionZ.value = pos.z;


      The issue i am having is that the sound is being completely distorted, and turning the source volume down does not help. (this may very well be a bug in Chrome OSX, since i don't remember having any issues when i made something similar before, which i ran on Chrome Windows)



      I also tried doing this (these 2 lines should be exactly the same btw), but that didn't help either:



      listener.positionX.setValueAtTime(pos.x, 0); 
      listener.positionX.setValueAtTime(pos.x, context.currentTime);


      Then i tried the old and deprecated command to do this, and that sounds way better but still has slight distortion:



      listener.setPosition(pos.x, pos.y, pos.z);


      The one that seems to work best is to do a linear ramp:



      listener.positionX.linearRampToValueAtTime(pos.x, context.currentTime + 0.1);      


      But doing a new ramp on every frame is not really the correct approach, since ongoing ramps are cancelled and i think it takes the value before the cancelled ramp as the starting value for the new ramp. Also: when i then NOT update the value (i added that as an option in that codepen), it seems to jump back to a previous value, which leads me to think that that is maybe also the cause for the major distortion i hear when doing the ver first approach (setting the value by positionX.value = pos.x)



      Am i doing something wrong, or am i overlooking something? How should i correctly set the listener's position on every frame?










      share|improve this question














      I am having troubles trying to update the context.listener's position (each requestAnimationFrame) in an application using Web Audio. I have made a test environment here with some variations but none of them seems to really work.



      This is what i assume the correct approach is:



      listener.positionX.value = pos.x;      
      listener.positionY.value = pos.y;
      listener.positionZ.value = pos.z;


      The issue i am having is that the sound is being completely distorted, and turning the source volume down does not help. (this may very well be a bug in Chrome OSX, since i don't remember having any issues when i made something similar before, which i ran on Chrome Windows)



      I also tried doing this (these 2 lines should be exactly the same btw), but that didn't help either:



      listener.positionX.setValueAtTime(pos.x, 0); 
      listener.positionX.setValueAtTime(pos.x, context.currentTime);


      Then i tried the old and deprecated command to do this, and that sounds way better but still has slight distortion:



      listener.setPosition(pos.x, pos.y, pos.z);


      The one that seems to work best is to do a linear ramp:



      listener.positionX.linearRampToValueAtTime(pos.x, context.currentTime + 0.1);      


      But doing a new ramp on every frame is not really the correct approach, since ongoing ramps are cancelled and i think it takes the value before the cancelled ramp as the starting value for the new ramp. Also: when i then NOT update the value (i added that as an option in that codepen), it seems to jump back to a previous value, which leads me to think that that is maybe also the cause for the major distortion i hear when doing the ver first approach (setting the value by positionX.value = pos.x)



      Am i doing something wrong, or am i overlooking something? How should i correctly set the listener's position on every frame?







      javascript web-audio web-audio-api






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 18:04









      EindbaasEindbaas

      227412




      227412
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Using the .value setter and setPosition is supposed to instantly move the listener to that position. This will cause glitches. (Not all browsers have implemented this behavior so some will smoothly move somehow from the old to the new position.)



          A linear ramp (or other automation) is the correct way to move from one location to the next.



          I didn't hear any artifacts with Chrome 71 on a macbook using the built-in speakers. Perhaps I would if I used headphones?






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436230%2fhow-should-i-change-the-listener-position-in-web-audio%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Using the .value setter and setPosition is supposed to instantly move the listener to that position. This will cause glitches. (Not all browsers have implemented this behavior so some will smoothly move somehow from the old to the new position.)



            A linear ramp (or other automation) is the correct way to move from one location to the next.



            I didn't hear any artifacts with Chrome 71 on a macbook using the built-in speakers. Perhaps I would if I used headphones?






            share|improve this answer




























              0














              Using the .value setter and setPosition is supposed to instantly move the listener to that position. This will cause glitches. (Not all browsers have implemented this behavior so some will smoothly move somehow from the old to the new position.)



              A linear ramp (or other automation) is the correct way to move from one location to the next.



              I didn't hear any artifacts with Chrome 71 on a macbook using the built-in speakers. Perhaps I would if I used headphones?






              share|improve this answer


























                0












                0








                0







                Using the .value setter and setPosition is supposed to instantly move the listener to that position. This will cause glitches. (Not all browsers have implemented this behavior so some will smoothly move somehow from the old to the new position.)



                A linear ramp (or other automation) is the correct way to move from one location to the next.



                I didn't hear any artifacts with Chrome 71 on a macbook using the built-in speakers. Perhaps I would if I used headphones?






                share|improve this answer













                Using the .value setter and setPosition is supposed to instantly move the listener to that position. This will cause glitches. (Not all browsers have implemented this behavior so some will smoothly move somehow from the old to the new position.)



                A linear ramp (or other automation) is the correct way to move from one location to the next.



                I didn't hear any artifacts with Chrome 71 on a macbook using the built-in speakers. Perhaps I would if I used headphones?







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 17:50









                Raymond ToyRaymond Toy

                3,13069




                3,13069






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436230%2fhow-should-i-change-the-listener-position-in-web-audio%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen