Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code to generate wav files specifying waveform, pitch, ADSR, etc.?
#3
(07-23-2022, 07:51 AM)mnrvovrfc Wrote: 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.

All I'm looking to do is generate some basic sounds - white noise, brown noise, sine, square, sawtooth, triangle, etc. waveforms, at a certain pitch and volume. Generate and write the WAV files (if not found in the program directory) and then play them back on demand asynchronously however QB64 does that. If we have sample code for the basic waveforms and writing the WAV file, then we really just have to tweak the code to get different variations... I have found tons of info on the WAV format, just been avoiding & procrastinating doing the actual WORK of reading and digesting it all, and giving it a solid effort, LoL. But once the basic functionality is working, you can build on it and the rest of the dominos will fall more easily.
Reply


Messages In This Thread
RE: code to generate wav files specifying waveform, pitch, ADSR, etc.? - by madscijr - 07-23-2022, 04:48 PM



Users browsing this thread: 4 Guest(s)