Cabbage Logo
Back to Cabbage Site

Tuning question

Well I’m hardly a csound noob :stuck_out_tongue: could just use a hand with tuning maths…

So I’m making binaural beats with csound. The way they are traditionally made is the frequency of a sine wave that’s played (through headphones) in one ear is less than the frequency of another sine wave that’s played in the other ear, by an amount called a “beat Frequency”

In csound something like this

aSigL poscil3 kAmp, iFreq, iSine, 0
aSigR poscil3 kAmp, iFreq - iBeatFreq, iSine, 0

The waves are combined by your brain into a single tone that seems to beat. The beats can mess with your state of consciousness- if you are sensitive to sound and focus on the sound. It’s a kind of guided mindfulness meditation.

Unfortunately the code above also results in pitches that are out of tune relative to 12-tone equal temperament, making them hard to use musically.

I’m after an algorithm to make the pitch of the perceived tone in tune with 12TET…

thanks in advance, it’s something I’ve been stuck on for a while…

edit: Oh the general topic is referred to as brainwave entrainment

You mean the iBeatFreq value? This will be relative to the current iFreq. There was a discussion here recently that might help. You can do the math yourself, but there are also semitone and octave opcodes that can help.

A student of mine once did a series of compositions based on brain states, inspired by binaural beats. It was very nice music. I look forward to hearing with you come up with.

1 Like

I mean the cps for each oscillator to make the perceived tone be in tune with 12-TET ( or really floating point midi note numbers) whilst keeping that beat frequency as accurate as possible- normally it’s a kBeatFreq, iBeatFreq from a super simple instrument of course. My instruments are passed a beat frequency (and others calculate it)- the beat frequency being the dominant brainwave frequency you try to sinc with when meditating. Anyway it’s late, will look at the link tomorrow, thanks.

In addition, cent(x) for micro-tuning! That might be more applicable in this situation I think.

when playing with binaural beats I usually rise one stereo channel by half the binaural frequency and lower the other channel by half the frequency with pvshift opcode (so all the spectrum is shifted by the same frequency amount, not the same ratio as in pvscale).
With lower notes the detuning effects will be more evident but is part of the game, I haven’t came up with anything more sophisticated.

That’s a neat method @vallste, I’ll have to give it a shot some time soon! That’s definitely useful for dealing with real time audio streams. The methods we were already discussing are a little more focused at dealing with tuned oscillators, which make pvscale a bit overkill? But it might create a different aesthetic, so definitely worth trying!

@vallste, you might as well just re-synthesise with a higher base frequency unless you’re using gnaural/idoser/something other than csound. Things other than csound often make that a pain with their silly graphs though.

@t_grey, slowly wrapping my head around it, made some progress yesterday. Still not working properly. It’s a complicated problem that’s a bit too much for my not so great coding musician’s mathematics skills.

@lorien

Glad to hear you’re making progress, at least! If you need any more tips or pointers, feel free to ask. The more complete of a code example you can post the better too!

What I can say now is the approach of calculating how many cents there are between the frequencies of the oscillators, and shifting the frequency of each oscillator up by (cents/2) doesn’t work because it’s a ratio and the number of Hz changes when you shift things around via multiplying it by a ratio. And if the number of Hz between the oscillators changes then the beat frequency changes. And keeping that beat frequency accurate is more important than being exactly in tune.

A bodgy approach I came up with a while ago was

aSigL poscil3 kAmp, iFreq + (iBeatFreq/2), iSine, 0
aSigR poscil3 kAmp, iFreq - (iBeatFreq/2), iSine, 0

which is an improvement on what everyone else seems to use, and keeps the beat frequency dead accurate, but is still out of tune.

Aside from the musical problems it matters because I’ve made binaural beats to help with developing absolute pitch…

edit: @vallste , you can see what you describe with pv opcodes done with plain oscillators above. Much faster than doing some all that transform frequency shift stuff. Make some of my vars k-rate and you can push your binaural beats around using csound function tables or envelope generators or channel opcodes and things.

Just out of curiosity, were you adding the value from cent or multiplying by it?

In this case I think it’d be used (this is pseudo-code, untested):

aSigL poscil3 kAmp, iFreq * cent(x), iSine, 0
aSigR poscil3 kAmp, iFreq * cent(-x), iSine, 0

Multiplying it just as you’ve done.

Actually I’ve got a fair bit of experience with microtuning and have written software that re-tunes midi keyboards in realtime using polyphonic aftertouch or pitch bend and channel rotation. 20 odd years since then mind you, but still I’ve done much more of this than most musos.

I’ll go over everything again, but I think the issue is getting the proper value of “x” due to not knowing the higher or lower oscillator frequencies and so being unable to calculate the ratios in cents that a beatFrequency of say 8Hz would need with an iFreq of say 80Hz. If I knew the frequency of the higher or lower oscillator to start with it’d be easy.

Sure iFreq could be calculated by multiplying a cent ratio by a lower or higher frequency, it’s the perceptual mid point of a range bounded by lower and higher frequencies and thus will be the halfway point in some number of cents, but we don’t have those lower or higher frequencies, just that iFreq perceptual mid point and the difference between the lower and higher frequencies. Of course the cent ratios (really number of cents * the ratio of 1 cent) would change according to what those frequencies are, because the range in cents changes as these frequencies change, though the difference between the frequencies stays the same.

And so I get stuck.

edits: grammar

@lorien I use pvshift because all upper harmonic will be shifted the same hz amount, the partials will be out of tune (compared to the ideal sound) but the hz difference between left and right channel will be constant. It can be applied to any signal (noise, reverb…).
If I would use a wavetable approch i’d use a bunch of sinusoidal oscillators and move their frequencies (adding or subtracting). If you use a single complex waveform oscillator for channel, i suppose that left and right fundamentals will be at correct hz distance but all the other harmonics will be not.

@vallste Fair enough. I’ve made a mess out of my mental states with just adding an octave higher and lower with the same beat frequency though, don’t dare anything other than sine waves anymore after going somewhat crazy. What works for you works for you though!

I’ve made similar impossible sounds with additive synthesis where each harmonic is a binaural beat and the beat frequencies relate to each other via the harmonic series too, turned out prettier through speakers and not so good for meditating.

Yes, I’m not sure that meditating will be helped by binaural beats, maybe irritating is more appropriate :grin:
By the way, find here some “music” I’ve made involving them, find it here

I’m quite sure all the alarms about idoser being a drug delivered via internet was a fake news :laughing:

Maybe you aren’t so susceptible. I’ve listened to idoser’s “morphine” on the dental chair and the dentist left and I didn’t even notice, I was SO out of it the nurse asked “are you alright?!”, I was only under a local at the time. I’ve seen binaural beats do similar things for many people. I’ve used them during overnight coach rides. Also quitting smoking: just kept myself sedated for two days with gnaural’s default map while the cravings went away.

Like a drug (note I’m not saying simulating a real drug is at all possible with binaural beats) but with the opportunity to take the headphones off/have a coffee/wash your face and so back out has been my experience. And without the negative health effects.

Stuff those idoser jerks though, that IS awful marketing. At least they upset shrinks though.

I’ll listen to that through speakers later, thanks. I have house stuff to do for a few hours now.

Trying to be more serious on this issue: I can not stand listening via speakers (i just hear beating as periodical volume oscillations), the effect is way better with headphones to isolate the perception between the two ears and consequently between brain hemispheres.

Which is exactly why I said I’d listen through speakers thank you, I’m being rather serious: I have no idea what’s happening psychoacoustically in this pice of music you’ve identified as being intentionally psychoactive. You’ve basically said “here you are, this is gonna mess with your head” without anything else aside from using complex waves and phase vocodong.

Simple tripled sinewaves- centre, octave higer and lower, all on the same beat frequency have caused months of odd behaviors until I figured out what was causing it and deleted my octave doubles.

I know an awful lot about psychology and states of mind for reasons I’m not going into. If I listen through speakers any messing with the way my neurons behave is going to be comparatively minor compared to what could happen carefully listening through headphones.

No offense, and thank you, but seriously, you are trying to sync up your brainwaves with binaural beats made from complex waves and I know full well what’s happening with the harmonics, so I’m treating this with a little care.

No offense taken, I find your experience a very interesting subject (since I don’t know anything except what I’ve read in some articles).
I’m just speaking from a Csound programming standpoinint.
Take care, Stefano

Well I made the mistake of listening to some stuff from 10 years ago first because it comes up first, sorry. I’m thrown back to my composition student days in the mid '90s… Later stuff downloading.

Here’s one of those impossible sounds of mine i mentioned @rorywalsh, you said you’d like to hear some.

I did this last year. It’s multiple binaural beats stacked in a harmonic series when the beat frequencies are stacked up in a harmonic series too. They fade in, it’s at it’s most complex at the halfway point.

I suggest normal listening via speakers rather than attempting a complex wave like this as a meditation: synchronising one’s brainwaves not being the easiest of tasks to do consciously and complex waves only making things harder. Walk around while it’s playing, it’s a real mutant sound I synthesised, it changes as you move around!

Also @vallste if you’ve been having trouble getting any psyche effect from binaural beats and have trained your ears to a high level, it’s most likely either focus or belief. They’re a high tech extension of shamanic drumming, which human kind has used to alter states of consciousness for millennia.

If you want to see this kind of thing at work watch any good metal concert on youtube, note the guitarists and their palm muting producing a “chunking” sound full of loads of even harmonics, note how out of their minds the audience is (and I’m sure they aren’t ALL stoned on chemicals), and look into isochronic tones.

And if anyone can help solve this problem? I’ve been stuck on it for ages.

Also everyone reading, please note I’m on this forum thanks to Rory telling Linux geeks to come ask here if you have any trouble building Cabbage, and I’m maintaining the package for all the arch linux based distros voluntarily because I’m attempting (sorry rory, ha) to use it both for binaural beats and to make a decent and open digital theremin. I didn’t quite realise it’d be a kinda sorta academic forum, but no worries (yes I’m an aussie), in one past life I was a head tutor in computer science too.