SOUND and waveforms
#1
Is there a way to set the waveform for a sound in QB64PE?

I'd like to go about doing things in BAM, if possible, the same way as it would be done in QB64PE.

For reference, here's how I've prototyped SOUND to handle things via a third parameter:

i.e.: SOUND frequencyduration, waveform

Based on "SOUND Example 1: Playing the seven octaves based on the base note DATA * 2 ^ (octave - 1)




I've got a sudden interest in audio lately (waveforms, multi-channel sounds, etc.)  Might just be a short-term interest, but who knows???
Reply
#2
You'll have to compute the waveform yourself if using "_SNDRAW" in QB64.  "SOUND" is pretty much hard-coded to be compatible with GW-BASIC at the oldest.  The Tandy BASIC set the voice for the third parameter because some Tandy computers were capable of three-channel sound.  That dialect also had "NOISE" which was pretty cool but couldn't do anything else with the noise sound and couldn't change the frequency of the pulse wave.  The QB45 version of "SOUND" carried only two parameters.

I was going to post an example program which makes use of "text-file waveforms". A text file could have 256 lines, each line having a single-precision float value from -1 to 1. These values are fed into "_SNDRAW" per sample to produce sound according to sampling rate. In this way sinewaves and pulsey-type sounds could be produced. The pitch could be changed simply by setting a rate other than one, for the counter that chooses which sample to play for the current frame.

I'm sorry if I'm going heavy with technical details, but "SOUND" is hard-coded, cannot make progress with that for your project if you want more variety with sound.
Reply
#3
If out of this we can get an improved sound library with a better sound function that accepts frequency, waveform (sine, square, sawtooth, triangle, white/brown/pink noise, maybe a way to specify a custom formula), attack/decay/sustain/release, or duration, volume, envelope(?), and pan/fader parameters, which returns a unique ID where multiple sounds can play simultaneously, start & stop routines for a given sound ID, IsPlaying (returns true/false), and the ability to alter the parameters while it's playing, that would make audio in QB64 a lot better.
Reply
#4
(08-13-2022, 06:41 PM)madscijr Wrote: If out of this we can get an improved sound library with a better sound function that accepts frequency, waveform (sine, square, sawtooth, triangle, white/brown/pink noise), attack/decay/sustain/release, or duration), volume, envelope, and pan/fader parameters, which returns a unique ID where multiple sounds can be created at once, start & stop routines, and the ability to alter the parameters while it's playing, that would make audio in QB64 a lot better.

I am all for anything that keeps QB64 (PE) rocking something silly.

Instead of monkeying around with new parameters for SOUND, I've setup a "in the interim"_WAVEFORM statement, which I can later replace with a QB64PE way of doing things.

Maybe.  Javascript is no fun to play with.  But at least I've figured out just enough of the Web Audio API.

To see latest BAM waveform in action:

Sound Tester:
Chaotic Scatter (based on Vince's awesome program):
Reply
#5
(08-13-2022, 06:41 PM)madscijr Wrote: If out of this we can get an improved sound library with a better sound function that accepts frequency, waveform (sine, square, sawtooth, triangle, white/brown/pink noise, maybe a way to specify a custom formula), attack/decay/sustain/release, or duration, volume, envelope(?), and pan/fader parameters, which returns a unique ID where multiple sounds can play simultaneously, start & stop routines for a given sound ID, IsPlaying (returns true/false), and the ability to alter the parameters while it's playing, that would make audio in QB64 a lot better.
Telling by at least two threads I've opened having to do with sound generation, which there's no reply, it seems you and I are the only ones on this forum that want this functionality, my friend.
Reply
#6
(08-14-2022, 09:47 AM)mnrvovrfc Wrote:
(08-13-2022, 06:41 PM)madscijr Wrote: If out of this we can get an improved sound library with a better sound function that accepts frequency, waveform (sine, square, sawtooth, triangle, white/brown/pink noise, maybe a way to specify a custom formula), attack/decay/sustain/release, or duration, volume, envelope(?), and pan/fader parameters, which returns a unique ID where multiple sounds can play simultaneously, start & stop routines for a given sound ID, IsPlaying (returns true/false), and the ability to alter the parameters while it's playing, that would make audio in QB64 a lot better.
Telling by at least two threads I've opened having to do with sound generation, which there's no reply, it seems you and I are the only ones on this forum that want this functionality, my friend.

I'd be happy to try to help make something usable!

Just thinking out loud to break it down and make sure I understand, a digital audio sound is made up of a bunch of brief click noises (where a single click is called a sample) played at different volumes one after another really really fast. Typically a sound is made up of many such samples played each second (the frequency is how many samples are played each second). The volume increases and/or decreases over time, which looks like a wave when the volume (y-axis) is graphed against time (x-axis). 

So basically to play a sound of a certain waveform, you would have the computer play a click at the loudness determined by the waveform for the given (miniscule) point in time. This happens many times per second for each sound (44,100 times per second for CD quality sound). So we would need a timer that fires the sound play event however many thousand times a second, to achieve the desired frequency and timbre. 

I know QB64 has a timer function that you can enable to fire at a regular interval, so for each sound we want to play, we might set up a timer, and send it the parameters so it knows what volume and when to play the next sample. 

Does that sound at all right or is that missing some important part? I started reading about modulation and they totally lost me. 

Would we really need our sound routine to run 44100 times every second per sound channel to generate CD quality sound? That sounds like an awful lot of processing power... When I'm back at a PC, I can play around with this, and try to create a proof of concept program to try out various concepts and see the process in action.
Reply
#7
(08-13-2022, 06:52 PM)CharlieJV Wrote:
(08-13-2022, 06:41 PM)madscijr Wrote: If out of this we can get an improved sound library with a better sound function that accepts frequency, waveform (sine, square, sawtooth, triangle, white/brown/pink noise), attack/decay/sustain/release, or duration), volume, envelope, and pan/fader parameters, which returns a unique ID where multiple sounds can be created at once, start & stop routines, and the ability to alter the parameters while it's playing, that would make audio in QB64 a lot better.

I am all for anything that keeps QB64 (PE) rocking something silly.

Instead of monkeying around with new parameters for SOUND, I've setup a "in the interim"_WAVEFORM statement, which I can later replace with a QB64PE way of doing things.

Maybe.  Javascript is no fun to play with.  But at least I've figured out just enough of the Web Audio API.

To see latest BAM waveform in action:

Sound Tester:
Chaotic Scatter (based on Vince's awesome program):

That's pretty nice. Can you make it work in QB64? :-D
Reply
#8
(08-06-2022, 07:41 PM)CharlieJV Wrote: Is there a way to set the waveform for a sound in QB64PE?
...
I've got a sudden interest in audio lately (waveforms, multi-channel sounds, etc.)  Might just be a short-term interest, but who knows???
(08-08-2022, 12:42 AM)mnrvovrfc Wrote: You'll have to compute the waveform yourself if using "_SNDRAW" in QB64. 

FYI here's a pretty cool example I found on the old hard drive!
Reply




Users browsing this thread: 3 Guest(s)