Threads and performance!

Started by
19 comments, last by uncutno2 16 years, 11 months ago
Just a note that on Windows, precision of Sleep is controlled the same way as timeGetTime, via timeBeginPeriod.
Advertisement
can i change it?
Read this:

http://www.geisswerks.com/ryan/FAQS/timing.html
Quote:Original post by uncutno2
Thanks, this is version 3 of my synth, version 1 is 4 years old, and my current version is 8 times faster. From version 1 to version 3 i have changed the whole representation of the sound problem, and reduced representation data with 50%, which means that 50% less calculations are done calculating the same data. After that I have optimized every critical area, and separated the sound-calculating part of the system from the gui, so that they run seperately, and only share a set of controller variables (ex. volum), that dont need to be locked. For example: instead of processing a rendered sinus-wave, I only process 3 variables, the wave's frequency, volume and phase. If i want to pitch the frequency of the sin, i multiply the frequency by two (instead of recalculating the rendered sin)... Because of this i can handle about 10000 different waves or pulses every second, and they are all passed trough a set of dynamic filters which i dynamically connect together with cables within the gui. If I want an extra delay filter somewhere, I add a Delay module, and connect its cables... If I want 55 delay modules, no problems. By having a large set of primitive filters, I can create millions of different sounds and moods. The final rendering of the sin waves is done without floats or doubles, by only adding and bit-shifting. Both the waves volume and frequency changes over time, so this is not trivial.

I have now tried to turn the threads priorities to the maksimum, and my GUI thread sleeps 15 ms after each rendered frame. When using sleep(0), the system froze (no other top priority thread), so now i'm doing 10 ms sleeps (I know win32 cant guarantee anything less then 10 ms). Any other idea? Is there ANY way to squece out more power from the thread shedualing system?
That sounds pretty impressive (excuse the slight pun). I'd love to hear how it sounds.

I wrote a synthesizer once where you could connect up various filters etc. I didn't optimise it that much though, and I don't have the code any more.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Krek: Perfect! Just what I was looking for! Superthanks!

iMalc: "I'd love to hear how it sounds."
I can upload a sample, but currently Im optimizing my delay system, so it have to wait until this work is done... By combining different elements you can have hundreds of wildely different sounds, it will also later have a sequencer and a drum-machine (with sinus wave drum clicks).

The synth is supposed to be a live-synth, with a nice fullscreen gui that hides everything you dont need, and let you load/edit/adjust your synth while playing: One hand on the keyboard, and one hand on the mouse wheel controlling parameters :-), Two "smart" shortcut-keys handle all editing and fiksing, so if you dont use those, all keys are for playing only.. the keyboard is a piano-keyboard + i have midi keyboards as well... You can also "paint" sounds with the mouse, so you get sounds like the theremine instrument if you want. Pretty cool, my goal is to use it on stage some day! There will also be a SinusSynth album out once the synth is fully functional, the album will be an experiment on what music can be created by simply adding sinus-waves together, and I have some wild THX-intro-ish sounds :-) Funn stuff if your into noize and harmonies.

Cool that you guys show interest in my project, ill be glad to tell you any detail if you are interested.
The synthesizer I wrote wasn't based on sin waves. Intead, you had to set up a plucked-string-filter. This consists of a single spike value in the input which goes through a loop with, a low-pass filter, a delay, and some slight attenuation. It sounded much like a guitar, which is what it actually simluates.

It would be interesting to have an option to switch from sin-wave to saw-tooth wave, and perhaps even square-wave, in your program[smile]
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Wavetable - any wave will do.

Well, the cool thing about sin waves is that you can combine them into other types of waves, for example SAW or SQUARE.

You can find nice formulas here:
http://en.wikipedia.org/wiki/Saw_wave
http://en.wikipedia.org/wiki/Square_wave

The cool thing with this (having all waves consisting of multiple sin waves) is that when you pass your saw wave trough an equalizer or another frequency dependant filter, you simply need to filter each sin wave (An saw wave is actually a sine wave with a lot of higher frequency overtones). Only looking at the saw wave base frequency when equalizing would for example result in a lot of high frequencies passing straight through an low pass filter. By only having sin waves, all equalizers, low-pass filters, high-pass filters, cutoff + resonanse filters etc. automatically work as they are supposed to!

So instead of first creating an saw wave, and then decompose it when doing frequency filters, they all sin waves all the time. (You can actually do a pretty nice SAW wave with only 7 or 8 overtones, and since you cant hear frequencies over 22k (you cant at least play then on an 44.1k output rate)) you only need to add the ones up to this frequency.
So you are saying that you get to avoid a fourier transform when filtering? :)

I think performing a fourier is probably the better alternative because it will work regardless of the source of the sound. As is you are forcing the sound to be generated by sine waves when often it is better to simply allow PCM data as a sound source (recorded voices and so forth)
No Fourier, and until the final rendering step, each sin wave consists of 4 numbers: frequency, volume, pan and phase. So for every rendered frame (134 samples in 44.1k rate), i only move about 1k of data through the synth.

In regard to any input source, the synth is a synth and not an effect, so midi and other controllers are the only inputs...
The cool thing with this fast approach is that i can combine 30-50 filters to get the perfect sound... If i needed to filter real sounds as input, a lot less could be done per frame, and the synth would be limited alot. Most effect filters with real sound as input, dont have a lot of adjustments, so you need 3000 effects to cover all your needs.

This topic is closed to new replies.

Advertisement