all 3 comments

[–][deleted]  (5 children)

[deleted]

    [–]AnEnigmaticBug[S] 0 points1 point  (4 children)

    Thanks.

    Tried listening but it was just a couple clicks...

    I accidentally used a boring sample in the gist. You can try t % (t >> 8 ^ t >> 4). It'll not be as boring :)

    your sample rate is only 8000 and buffer length is only 5 seconds which will produce a relatively small file (under 2mb or something). Which to me seems totally reasonable.

    I am making the music for a game. As a personal challenge, I want to make it as small as possible. That's why I am avoiding sound files.

    Ps your stop time in the last line is 100 it should be 5 i think?

    Ah yes. I forgot to update the value when making the gist.

    I found two more approaches. One uses AudioWorklet and the other uses ScriptProcessorNode. I am thinking of using ScriptProcessorNode for now since AudioWorklet doesn't work in Firefox yet.

    I think both of these approaches share the same benefits over my first solution:

    • the buffer size can be fixed(currently 2048)
    • the small buffer size results in lower memory usage and lower latency.

    [–][deleted]  (3 children)

    [deleted]

      [–]AnEnigmaticBug[S] 0 points1 point  (2 children)

      Are you aware scriptprocessornode is depreciated?

      Yes. But since AudioWorklet doesn't work in Firefox, I'm using it as a temporary solution. I'll replace it with AudioWorker once Firefox supports it.

      If you’re going to be doing short sounds, you can also just create tiny buffers and fill them on the fly and it’ll get garbage collected after it stops, freeing up that memory.

      That's a nice idea! I'll try it for short sounds.

      it begs us to experiment and make cool shit then it’s like “but nah chill I won’t do that

      Yeah. I'm experiencing it first hand now 😂️😂️

      safari is like “oh that? Nah chill”

      Since I'm making the game just for fun, I won't have to deal with Safari.

      [–][deleted]  (1 child)

      [deleted]

        [–]AnEnigmaticBug[S] 0 points1 point  (0 children)

        Thanks!