I am not sure where should i post this. It may be a threading problem, or it may be a Java Sound problem, or it may be a Java bug (yeah... right).
The following lines of code aiming to use a midi synthesizer in order to have it play random notes.
If i use this code routing midi to any hardware port, it works fine.
If i use it to route midi to "Java Software Synthesizer" device, i can only use one (out of 16) midi channels of this device: should i attempt to concurrently use any second (or third) channel, the program breaks, and i am getting the following error:
"Invalid memory access of location 0x22795d32c rip=0x7fffffe00eca"
Please note the lines that start with "new Player".
Commenting all of them (except one), results in sending midi to one channel only - thus, no problem.
Un-commenting two lines, thus evoking a second "player" causes the error.
I tried it on Snow Leopard and on Windows, it gives a similar "invalid memory" error.
I fear that all this trouble has to do with my less-than-perfect knowledge on threading, so i would appreciate any help.
Protocol Webmaster please check your private messages for some administrative matter...
SCJP 6.0 98%, SCWCD 5 98%, Javaranch SCJP FAQ, SCWCD Links The hardest moment is not when you lose someone and tears come out of your eyes, but its when you lose someone and still you have to manage a smile!
Anyways, I don't have any idea about this. Maybe the Java Sound Synthesizer is not multitimbral (cannot play simultaneously on multiple channels), this is all that I can predict. I found a few pages which might be helpful
This message was edited 1 time. Last update was at by Ankit Garg
SCJP 6.0 98%, SCWCD 5 98%, Javaranch SCJP FAQ, SCWCD Links The hardest moment is not when you lose someone and tears come out of your eyes, but its when you lose someone and still you have to manage a smile!
The question has also been asked at the DZone forums.
It is not answered anywhere (until now) and i will notify here if and when it does, so that no one will waste any time.
I played around with your program and now I'm able to generate multiple sounds simultaneously. What I did was instead of opening the MidiDevice multiple times, I opened it once and and started multiple threads send messages to that MidiDevices receiver. That is this code was run only once
And then I started 4 threads to send ShortMessage to send messages to this Receiver object. Your technique called this code multiple times so maybe the second time you open the Java Sound Synthesizer device, that created problems...
SCJP 6.0 98%, SCWCD 5 98%, Javaranch SCJP FAQ, SCWCD Links The hardest moment is not when you lose someone and tears come out of your eyes, but its when you lose someone and still you have to manage a smile!