Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411443 Posts in 69483 Topics- by 58507 Members - Latest Member: smol-asteroid

July 17, 2024, 11:15:08 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallCosyne Synthesis Engine
Pages: 1 [2]
Print
Author Topic: Cosyne Synthesis Engine  (Read 25249 times)
muku
Level 10
*****


View Profile
« Reply #20 on: April 11, 2010, 03:02:22 AM »

Sorry I didn't reply yet, muku. Just wanted to finish the new experiment first, but it's still not ready yet...
But if you want to try it out, here's the current state.

Unfortunately that doesn't run for me Sad Just sits and eats 100% CPU, no window, no sound. No error messages on the console either.

Quote
Quote from: muku
Range 0..127, for compatibility with MIDI where it's the same. Right now this just linearly scales the gain of the instrument, but I might think of something more physical here...
I already expected that somehow. MIDIII alert!

In fact it shouldn't be too hard to implement a MIDI interface so that you can actually play Cosyne from a real MIDI keyboard. I might do that sometime, but right now it's not such a high priority. I have even more grandiose dreams with producing an actual VSTi version of Cosyne so that you can compose music for it in some sequencer and then import it into your game as a simple MIDI file... but just a dream at the moment.


Quote
Hm, maybe I'm worng about this... But I currently render the samples in one go in my drawing function (whenever OpenAL needs a buffer update, what is not the case for every frame... I sometimes make the buffer as big as 8192 samples or even larger (to keep it glitch free on mostly all machines), which leads to only ~5.4 updates per second. For OpenAL streaming I fixed the buffer count to 3. That sadly leads to lots of latency :/...

So you effectively have 3*8192 samples worth of buffering, which at 44.1kHz corresponds to a latency of 0.56s... that can't be right though, while your first example lagged quite a bit, I don't think it lagged that bad? Or maybe you don't always write into the "last" buffer, so that it's sometimes better than that?

I produced a little graphic to maybe elucidate the situation:

Time moves from left to right. Let's just view time as segmented into an endless stream of equal-sized buffers (the black boxes), which you essentially emulate in OpenAL by unqueuing fully played buffers and re-enqueuing rendered buffers.

The blue line marks the current playback position of the sound card, and the red line marks the sample position at which Cosyne is currently rendering. Of course you always have to keep the render position in front of the playback position, or skipping will occur. The render position is advanced in chunks by calling Cosyne_Render(), and the playback position advances more or less continuously with time.

Cosyne effectively allows you to place events freely in the gray (empty) area at a fine resolution (64 samples) by specifying a time when calling PlayNote() and the other event functions.

It seems that OpenAL lets you determine the playback position by querying the AL_SAMPLE_OFFSET source property. So maybe you could, whenever you add a new note event, take that position, add a constant offset to it and use that as your note time, completely ignoring the Cosyne render position? That should ensure a more or less constant latency for all notes, no matter their position within a buffer.

Of course you still have to ensure that there is always a filled buffer available for the sound card, but yet the render position doesn't advance beyond your fixed latency offset. It's a bit of a balance act. Maybe you can always render just enough samples so that the render position is, say, 1.5 buffers ahead of the playback position? In other words, don't always render one full buffer in one frame, but just enough samples to ensure this, and when a buffer is filled enqueue it.

Do I make sense? I'm not sure.


Quote
Oh, that' actually really useful! Thanks for clearing that up. I always had troubles with dB scales and such... And in my synth, I also always used linear scaling, just to keep it simple. But it actually always felt unnatural to me... I surly will try your method now Smiley. - I also have the impression that the non-linear relationship between frequency and perceived loudness is a similar problem like this (keyword Psychoacoustics). But this remains an open issue in synth as well... I know that many soft-synths often have a key/pitch parameter to cope with that sort of thing, but I never really understood the maths behind it... Maybe I just need to scale the amplitude by some scale factor like (new_amp = amp * freq ^ x)? Didn't try that yet. But similar to the velocity scaling that might lead to a more natural sounding instrument on the whole range of the keyboard...

Nice that it was useful. For the frequency/amplitude thing, I'm afraid it's more complicated than that. Basically you'd have to implement something like equal-loudness contours (Fletcher-Munson or somesuch). The problem is that these only hold for pure sine waves at a given frequency, while a typical synth voice will have a spectrum which extends far into the overtones. So I think there is no way to solve this at the note level. The real way to solve it would probably be to do equalization as a post-processing step: Once you have your final output all mixed together, do a Fourier transform, scale each frequency band according to some loudness contour, and then do the inverse Fourier transform. That's of course way expensive, and I'd rather stay out of that.


Quote
Oh and just keep up the good work! I think it's really great. I guess people here are not that much into interactive audio, to play around with it just for fun...

Yeah, of course I can't expect everyone to jump on this immediately Smiley But I don't mind, I'm mainly doing this for my own interest (and to have it available for some of my game experiments in the future). That at least one other person (you) is interested in this stuff is great already. Smiley
« Last Edit: April 11, 2010, 03:05:23 AM by muku » Logged
increpare
Guest
« Reply #21 on: April 11, 2010, 03:21:43 AM »

Sorry I didn't reply yet, muku. Just wanted to finish the new experiment first, but it's still not ready yet...
But if you want to try it out, here's the current state. I've tried to combine my lib with Cosyne this time, and technically it worked fine (needs lots of CPU though). The sound is not that much interactive though. Clicking and dragging changes the filter frequency of a simple cosyne instrument, the background is done with es. Initially I wanted to bind some interactive sound function to the moving objects... Probably I try to do that next. But technically the ChangeParam-feature worked immediately. Nice!
Works okay for me, fwiw.  I had thought you had added in ambient sound effects, of someone typing in the background, but it turns out my work computer is streaming in the flapping of the blinds from the server room for some strange reason... .  The music I found to be a little monotonous for my tastes.
Logged
muku
Level 10
*****


View Profile
« Reply #22 on: April 11, 2010, 08:11:27 AM »

Haha, am I the only one who is reminded of old LucasArts adventures by this here? I love it Corny Laugh
Logged
curby
Level 0
**

bacon grills


View Profile WWW
« Reply #23 on: April 13, 2010, 06:34:27 AM »

Great stuff.  I'm a big fan of interactive audio, will check this out when I get home!   Smiley Hand Thumbs Up Left
Logged

curby: Twitter

beatnik:  Plain Sight
muku
Level 10
*****


View Profile
« Reply #24 on: April 13, 2010, 03:29:20 PM »

Just got portamento implemented, and I think it's jolly good fun:

http://www.box.net/shared/ryv9ke1nhx (Sopwith Camel anyone? Corny Laugh)
http://www.box.net/shared/ch4j9gz2i1 (yeah sorry, it's not in time and annoying)

You get the choice between either a constant-time or a constant-rate portamento, both configurable.

0rel, I'll reply to your post tomorrow; it's late...
Logged
increpare
Guest
« Reply #25 on: April 13, 2010, 03:35:08 PM »

Quote
http://www.box.net/shared/ryv9ke1nhx (Sopwith Camel anyone? )
The low registration in the early part of that really got inside my ... ears, I think ... creepy...
Logged
muku
Level 10
*****


View Profile
« Reply #26 on: April 14, 2010, 02:29:35 PM »

So I started feeling a bit bad about spamming the announcements forum. Let's move over to the devlog, people.
Logged
Nagnazul
Level 0
**


View Profile
« Reply #27 on: September 29, 2010, 12:33:41 AM »

I think this could be useful to me, I'll look into it.

Thanks for making this!
Logged
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic