code to generate wav files specifying waveform, pitch, ADSR, etc.?
#2
DSP is not easy. Look into "musicdsp.org", only about coming up with an oscillator, or filter which is not low-pass. I know how to create a basic sine oscillator, or a saw based on trig "TAN()" function but that's all. I'm still dumb with things like that trick using "EXP()" to fade sound in and out. Loading and creating a 44100Hz 16-bit mono wave file is not much hassle for me anymore. Doing it in stereo begins the headaches, also trying to use a larger bit depth and/or sampling rate. Generally the specs I just listed would be enough for sound effects in an arcade game except for audiophiles. Cannot play FLAC, MP3, OGG etc. directly with such a routine.

To come up with a wave file in which the PCM data of one is attached to the end of data of the other, must read the header of both files, determine the number of sample frames and make that adjustment in the header of the output wave buffer. If one file is mono and the other stereo well, mister, you will have more work to do. Which is what I mean. Keep it simple. However the "average" gamer doesn't care if somebody doesn't know how to program continuous music, and doesn't know how to kludge sound effects which aren't boring.

Just needing to compute sensible sound with "_SNDRAW" requires some technical knowhow.  For a polyphonic synthesizer must know how to add the voices, fade them in and out and make sure the level does not exceed absolute-value ONE (or it causes ugly digital distortion which might harm your hearing and/or your studio monitors). Must compute ahead of time for at least one second at the "current" sampling rate. A wave file could be imported, depending on it being 16-bit or 32-bit integer, then each sample frame would have to be converted to a single-prec float value from -1.0 to 1.0. Perhaps 32-bit float WAV could be set directly. A few wave files could be compressed or use obscure or weird codecs. Even fewer support three or more channels which could be difficult to program.

Somebody proved to me that it's possible to create a tracker with QB64, but it doesn't edit song documents! Playing one or more sounds away from "_SNDRAW" way requires working with an audio driver and with threads, which are other dimensions of complexity. Then expecting it to work in real time after editing... oh well charge for it if you could do it.

MIDI is another matter, it depends more on hardware and stuff installed on Windows such as the "synthesizer" ripped off some Japanese company. The code to do it in that OS is easy but it's not portable eg. to Linux.
Reply


Messages In This Thread
RE: code to generate wav files specifying waveform, pitch, ADSR, etc.? - by mnrvovrfc - 07-23-2022, 07:51 AM



Users browsing this thread: 2 Guest(s)