It clicked when I realised aplay receives some kind of
stream of data, and decodes it and send the info to the
sound card or whatever deals with the final output of sound
(need to look into how that works).

I worked with this stuff before when decoding streams of
audio from tools like SoX and using opus files.  But when
playing around a very small voice synthesis program, I
realised its not so complex to send the data through a pipe
to aplay, from C. The default settings for aplay is a sample
rate of 8000 and an encoding of samples as unsigned 8 bit
integers.

Creating a sine wave meant dumping in the formula for a sine
wave to place a value at the correct point relative to the
sample we're on and the time passed.



I didn't parametize this, such as make the amplitude and
frequency changeable in real time because I was too
interested in another idea. The machine I'm using provides a
64 bit number called a long. This means a single number
could represent multiple samples. If multiple samples fit
into the single number, what would a number be for a full
wave? If we need to produce 8000 samples per second, and
this number creates 8 samples, then the exact frequency we
can model with this number is 1000.



By setting each 8 bits in the long int to a 8 bit sample in
the 8 sample sequence, we can see what this number is, and
just set the long int to this single value.

The number is,

9261525663674299514

but because flymake in emacs complains about using this
number as a literal, I used the hexidecimal representation,
which seemed to work fine,

0x80878C857D78747A

To output audio from a C program like this, all that is need
is 2 lines:

#include <stdio.h>
int main(void) { while(1) fwrite(&(unsigned long int){0x80878C857D78747A}, 8, 1, stdout); }

Putting the hex literal between {} makes it a compound
literal, a kind of "anon" variable, that we get the pointer
for (for fwrite). fwrite sends that to stdout. That's
all. aplay takes care of the everything else so we can rest
easy listening to the relaxing 1000hz tone.

After I was done with that, I remember back to an
interesting generative audio project that is called,
bytebeat. I figured the general idea is to use bitwise
operations to change the bit values within the existing set
of bits being used to generate the sample buffer.



These few commands just moved bits around and added some
variety via the clock, similar to bytebeat. So I guess it
falls within the same genre. I didn't think about it too
deeply as to how I could fiddle with the commands to make
it sound deeper, maybe with some reverb and lower frequencies.
Mostly because I'd rather work on combining the sine wave
generation and this generative set of commands to create
something more declarative like the bytebeat system and
find a way to attach a UI to fiddle with the parameters.

Although, what occurred to me in regards to lower
frequencies is that a lower frequency is just a longer
wave. As the long int already defines 8 samples of a 1000hz
wave, we can take this values and interpolate between them
to create a longer wave.

There's also the project by Dirty Electronics / Max
Wainwrigt that uses a look up table to get samples, from
text used in their manifesto. The table data changes as the
audio and inputs affect its values, changing the audio over
time. I wanted to experiment with this idea myself, and
perhaps do something with a collection of values that
correspond to samples within voice or guitar recordings.

These are ideas that can be also found in wavetable synth,
sampling and looping, and granular synth.