MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Sound loop not seamless. Request advice.

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    7 Posts 3 Posters 1.9k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mykle1M Offline
      Mykle1 Project Sponsor Module Developer
      last edited by Mykle1

      I’m working on a new module. It is working but with one major issue. I’m trying to loop a .wav file seamlessly. I’ve done my research and know not to use MP3 files. The general online consensus is that .wav files are best for creating seamless sound loops. I’ve created and/or edited several .wav files in the app called “Audacity.” Within the app the files loop perfectly (seamlessly) with no gaps or drops. However, when I use the following function, there is the slightest gap/drop of the sound when it loops.

      if (this.config.sounds != "") {
         var sound = new Audio();
         sound.src = 'modules/MMM-SoundMachine/sounds/' + this.config.sounds + '.wav';
         sound.loop = true;
         sound.play();
         }
      

      Please advise me on how to achieve a seamless loop. Without it, this module is dead in the water. Thank you ahead of time.

      Create a working config
      How to add modules

      justjim1220J 1 Reply Last reply Reply Quote 0
      • justjim1220J Offline
        justjim1220 Module Developer @Mykle1
        last edited by

        @mykle1

        I remember having a similar issue with HTMl a long time ago, what I ended up doing was making 3 copys of the wav file and looping through them where one ended at a certain time and the other would start at the same time. But I had to time the gap, and set the time to start the next wav file at that point of the current wav file. I don’t remember the exact coding, been a while now, but after getting it to loop through the 3 copys, starting the next wav at the end of the current wav minus the gap time.

        IE: if the wav files are 1.75s, and if the gap was 0.25s, then the next wav would start at 1.5s of the current wav.

        If that makes any sense, apologies if it doesn’t.

        "Life's Too Short To Dance With Ugly People"
        Jim Hallock - 1995

        Mykle1M 1 Reply Last reply Reply Quote 0
        • Mykle1M Offline
          Mykle1 Project Sponsor Module Developer @justjim1220
          last edited by

          @justjim1220

          Makes sense but I’m not willing to make 3 copies of each sound file that will accompany the module, not to mention editing each and every one of them.

          Create a working config
          How to add modules

          justjim1220J 1 Reply Last reply Reply Quote 0
          • justjim1220J Offline
            justjim1220 Module Developer @Mykle1
            last edited by

            @mykle1

            I understand that, It was a lot of work for me

            Was thinking though, I think I only used 2 copies.

            "Life's Too Short To Dance With Ugly People"
            Jim Hallock - 1995

            1 Reply Last reply Reply Quote 0
            • Mykle1M Offline
              Mykle1 Project Sponsor Module Developer
              last edited by

              For those interested in helping me find a solution. I had intermittent success (sort of) with this function

              myAudio = new Audio('modules/MMM-SoundMachine/sounds/rain.wav');
              myAudio.addEventListener('ended', function() {
              this.currentTime = 0;
              this.play();
              }, false);
              myAudio.play();
              
              var audio = new Audio('modules/MMM-SoundMachine/sounds/rain.wav');
              
              audio.addEventListener('canplaythrough', function() {
              this.currentTime = this.duration - 10;
              this.loop = true;
              this.play();
              });
              

              Half of the time the module would error
              Failed to load resource: net::ERR_CACHE_OPERATION_NOT_SUPPORTED
              This did not stop the module from loading but the sound file still has the gap when looping.

              The other half of the time the module would not error and the gap would be gone, a seamless loop. However, the sound would be distorted, almost as if the sound were playing twice, but offset. At least I’ve made some progress.

              Still, I await assistance at your leisure, friends. :-)

              Create a working config
              How to add modules

              1 Reply Last reply Reply Quote 0
              • ? Offline
                A Former User
                last edited by

                Very interesting issue. Is it worked on RPI also?

                Mykle1M 1 Reply Last reply Reply Quote 0
                • Mykle1M Offline
                  Mykle1 Project Sponsor Module Developer @Guest
                  last edited by

                  @sean

                  Hi sean. No, I have not tried it on a Pi, yet. I only just started developing the module and came upon this issue. When/if I can solve this, the PI will get its chance.

                  Create a working config
                  How to add modules

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Enjoying MagicMirror? Please consider a donation!
                  MagicMirror created by Michael Teeuw.
                  Forum managed by Sam, technical setup by Karsten.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy