News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Sound synth system

Started by gabor, June 07, 2009, 06:39:14 PM

Previous topic - Next topic

six_L

regards

Mark Jones

I haven't had much time to tinker with this yet, but it looks promising (and quite complex.) :U

Until then I am curious, the "song" is actually what---synth1.net.inc? That will take some studying, it is not obvious at first glance how it works. (Such is probably the hallmark of excellent code utilization.) :bg

P.S. Works great on XP x64 (where Beep is not implemented and fails silently.) Apparently this makes DirectSound the only way a user-mode-app can make any "sound" in this OS, which is a great niche role for this synth.

P.S.S. Here are a few links to check out.
http://joost.zeekat.nl/bassline.html

Here KB explains how he made the V2 singing synth used in many of the Farbrausch demos.
http://www.kebby.org/articles.html
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Biterider

Hi gabor
First of all, thanks for sharing your work!  :wink
Looking through the code i found in the common.inc file a potential bug that may be very hard to trace down.
You are using an unsave memory location to store a temporary value onto the stack. All is fine until the OS decides to perform a task switch in between the intructions you are using. In this case, the temp value will be trashed. To avoid this, decrement the stack value by 4 before you save your temp value and finally restore the original esp value.
Some macros are coded the same way, like fldc, fildc, etc.

Regards,

Biterider

Siekmanski

Thanks Gabor, for this nice example.

gabor

Hi guys!

Thanks for the comments!

Mark!
Yes, it is more complicated than it should be. This is the price of flexibility. Most of the soft synths use a very simple scheme: add some synths, drums, effects to the final mix, done.
I went a very different way: create synths, drums, etc, and add them to the final mix. The synth1.net.inc describes a synth only, main.net.inc is the main part. The song is stored there (in the bottom lines).
Since the last upload I created drums (a TR808 kick and a snare, I have a lot of trouble with hihats...) Thanks for the links!

Bitrider!
You mean the mov [esp-4],value trick? I think the stack is quite a safe place to store values. A task switch must not change the stack nor the registers. Or am I wrong? If it is preserved along the registers, the temp value stored there is safe. I haven't experienced crash or any other problems so far. Anyway, thanks for you remark!

I'll upload a newer version after I add polyphony.

Greets,
Gábor

dedndave

anything below esp is "garbage"
or, at least, that is how things were in the old world - lol
it's simple enough to reserve the value

Damos

QuoteYou are using an unsave memory location to store a temporary value onto the stack. All is fine until the OS decides to perform a task switch in between the intructions you are using. In this case, the temp value will be trashed.
i've not looked at this code but are you refering to something like what I always do using the FPU like:


fistp dword ptr[esp-4]
mov eax,[esp-4]


which I use when I want to get a value into a register from the fpu when I don't want to set up a stack frame for optimization sake?
i've always done this and I thought that each task is assigned it's own stack.
i'm not being facetious, I really need to know if my above code could cause problems if a task switch occured between the two instruction.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. - Albert Einstien

dedndave

with win32 code, i can't see anything wrong with it - lol
but, i think i might be inclined to preceed the operation with sub esp,4
in this case, it may be a byte or 2 smaller, in fact

        sub     esp,4
        fistp dword ptr[esp]
        pop     eax

i use similar code when an API function wants an address to return a value,
especially if i do not care what that returned value is (like a write count or something)
or if i only want to return the value in reg instead of memory
this is ok if it is the last parm of the invoke (first pushed), otherwise, you should use ebp or possibly adjust esp accordingly

        sub     esp,8
        INVOKE  QueryPerformanceCounter,esp
        pop     eax
        pop     edx

Biterider

Hi
all values below esp are UNSAVE. In case an interrupt is triggered in between the 2 transfer instructions, the OS may use the current stack for its own purposes. It has to keep all values >= esp untouched, but all < esp can be changed. It is only a matter of time that an app that uses such code snippets acts unexpected. Let it run for some days on control the results... I would never relay on such software for a nuclear plant controller  :bg

Biterider

Damos

yes. your code makes sense.
actually if you pushed any register on the first line you'd save another 4 bytes.

push eax
fistp dword ptr[eax]
pop eax

and maybe prevent a stall on dependancy.
Thanks debndave. :U
EDIT:
the code should of read:

push eax
fistp dword ptr[esp]
pop eax
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. - Albert Einstien

dedndave

well - sub esp,4 is faster than a push - either way

Damos

yes it's just a shame that there isn't a increment/decrement instruction that deals with words and dwords like

incw eax ;increments eax by 2
decw ebx ;increments ebx by 2
incd ecx ; increments esp by 4
decd edx; decrements esp by 4

i've always found it strange that when intel made this instruction that they never considered that to increment a register to the next word or dword in a 1 byte opcode would be very useful ::)
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. - Albert Einstien

dedndave

lol - i was thinking the same thing - dang intel
of course, you can only have so many single-byte instructions
a 2-byte would be nice

EDIT
what would have been really cool would to have a few "programmable" instructions
so the programmer could set up a short sequence and use a 2 or 3 byte opcode to make it happen
of course, the cpu microcode would have to optimize it for us - lol - i am dreaming, i guess

dedndave

better yet...

        lea     esp,[esp-256]    ;reserve 256 bytes
.
.
.
        lea     esp,[esp+256]    ;free reserved space

or...

        lea     esp,[esp-4]
        fistp dword ptr [esp]
        pop     eax

jj2007

Quote from: dedndave on July 02, 2009, 11:40:27 AM
better yet...

        lea     esp,[esp-256]    ;reserve 256 bytes


Dave,
You are wasting precious resources - I am very worried ::)

lea esp, [esp-256] ; 8 bytes
sub esp, 256 ; 6 bytes
sub esp, 128 ; 6 bytes
lea esp, [esp-128] ; 4 bytes
add esp, -128 ; 3 bytes