ozdemirburak / morse-code-translator

Translate text to Morse code and vice versa, with the option to play Morse code audio.
https://morsecodetranslator.com
MIT License
216 stars 57 forks source link

Wave export #17

Closed chris--jones closed 4 years ago

chris--jones commented 4 years ago

This is my resolution for #16 - it adds the following methods to the export:

A demo of these functions can be found here: https://chris--jones.github.io/morsify/

@ozdemirburak - Some things to note: Rather than duplicate all the nodes for both the offline and regular audio context I was able to render via the offline context and store the buffer as an AudioBufferSourceNode which can then be played via the audio context.

This approach keeps the audio data in memory so that multiple export operations can be applied (e.g. you can download multiple times from the same morsify.audio() instance, but you still cannot play multiple times because I do not re-instantiate the AudioBufferSourceNode (I believe this behaviour is unchanged).

I did move the context variables into the audio function - I wasn't sure why they should exist beyond the lifetime of the audio function, but it was causing issues for the offline rendering; I think enforcing the recreation of context / buffer source for play operations should also allow for multiple play operations against the same morsify.audio() instance if desirable.

I also split out processing the gain values as this also provides the total duration time required for the offline audio context.

ozdemirburak commented 4 years ago

This looks perfect @chris--jones. Definitely, one of the best pull requests I've ever received or reviewed.

Can you also add your references that inspired you (if exists) to the functions as comments?

// https://github.com/mattdiamond/Recorderjs/blob/master/src/recorder.js
const encodeWAV = (sampleRate, samples) => {

Thanks again.

chris--jones commented 4 years ago

This looks perfect @chris--jones. Definitely, one of the best pull requests I've ever received or reviewed.

Can you also add your references that inspired you (if exists) to the functions as comments?

// https://github.com/mattdiamond/Recorderjs/blob/master/src/recorder.js
const encodeWAV = (sampleRate, samples) => {

Thanks again.

Yep, good callout - I do want to credit those who's articles and code samples helped greatly. Oh, and I also forgot to update the README.md - so I'll address that as well...

ozdemirburak commented 4 years ago

Perfect, thanks again @chris--jones.

chris--jones commented 4 years ago

Perfect, thanks again @chris--jones.

No worries, this was the most fun coding I've done in a while đŸ˜„