Bytebeat melody array help
BotB Academy Bulletins
 
 
180372
Level 21 Chipist
SRB2er
 
 
 
post #180372 :: 2023.12.07 9:56am
  
  Blast_Brothers liēkd this
So I'm trying to make a simple bytebeat, just to truly understand them

But I've been struggling on 1 thing, the notes

I've seen some bytebeats do things like

bassStuff=[12, 15, 12, 24] etc
bassLen=bassStuff.length

but idk how to make a variable that will keep track of what note should be played so that I can make note inputting easier

(oh, and how to make noise hihats i guess, I suck at that lmao haha)
 
 
180387
Level 28 Mixist
argarak
 
 
 
post #180387 :: 2023.12.07 3:30pm
  
  SRB2er, Blast_Brothers and kleeder liēkd this
here's a little demo
i quickly threw together that has a array of frequencies and a noise hat

frequency = [0.4, 0.2, 0.5, 0.1],
an array of frequencies, depends on how you're generating the sound

64 + sin(t * frequency[int(t/2000)%4]) * 50 +
sine wave function, sine waves need an incremental counter to continue generating the tone, so t is used. we modulate its frequency by using the array and accessing its components using int(t/2000) % 4.
int is very important as indices must be an integer number. the formula for an incremental array accessor is int(t/speed)%length. the modulo operator bounds t to [0 1 2 3] in this case which is ideal.
* 50 is the sine wave volume

random() * E**(-((t/200)%10 - 4))
random() generates noise between 1 and 0
E**(-((t/200)%10 - 4)) is a function that generates a decay envelope periodically
the formula is sort of like this E**(-((t/speed)%gap - volume))
experiment with the speed and gap as they both affect each other
here's a little desmos graph that i made that demonstrates this https://www.desmos.com/calculator/sprybu2v3a

hope that helps!
 
 
180410
Level 21 Chipist
Blast_Brothers
 
 
 
post #180410 :: 2023.12.07 6:46pm :: edit 2023.12.07 6:48pm
  
  argarak, SRB2er and Xaser liēkd this
To add onto this: One of the tricks you can do is define a note sequence, and then iterate through it out of order.

(t/2000) % 4 in argarak's example means that t will increase by 1 every 2000 samples, but it will be capped at the remainder of a division by 4; so 0, 1, 2, or 3. (note that they cast it to int explicitly, but at least in some bytebeat contexts using % will do this for free.) This is used as the note index, so it's reading from the array in sequence. But, you don't have to do that! For example, if you did -t/2000 % 4, it would read the array backwards. t/2000 % 2 would just alternate between the first two notes. (t-500)/2000 % 4 will read the 4 notes in sequence, but with a delay. And so on.

In bytebeat1k, defining arrays is a really space-intensive thing, so this helps you save space while having more variety. Related to this, I usually save the divided t to a variable, which I call songClock; to see an example of me using this, check out this
and this
.
 
 
180418
Level 21 Chipist
SRB2er
 
 
 
post #180418 :: 2023.12.07 11:29pm
I have actually done that songClock thing, but thank you both!

:D
 
 
180492
Level 23 Mixist
Minerscale
 
 
 
post #180492 :: 2023.12.08 8:31pm
  
  SRB2er liēkd this
Another useful formula is the conversion between a frequency and number of semitones away from a reference pitch in equal temperament. It's freq = ref_pitch*2^(n/12.0)

If you want your reference pitch to be A = 440 (as is tradition) that's

freq = 440*2^(n/12.0)

then to use that frequency in a sine wave for example that's be amplitude*sin(2*pi*freq). Be weary of changing the frequency over time a cleverer algorithm is required to set the phase of the wave to avoid popping. (the general solution to this problem involves an integral!!)
 
 

LOGIN or REGISTER to add your own comments!