I recently made a small project in Unity with NO meshes or lighting, just an empty game object, a few drum sounds and a script with which I am using a PS2 Rock Band drum kit to trigger the sounds. The trouble is, there is a delay from when I strike a drum pad and when the actual sound is triggered. This makes it TOTALLY pointless and literally impossible to try to play a drum beat in any kind of consistent timing.
I know it is not the pads that have the latency because when I look at the game controller config in windows the lights for each button light up with no delay upon hitting them. I have also tested triggering the sounds from the space bar on my keyboard and also my dual shock 3 controller all with the same delay.
Also I HAVE used a small drum program some one made, along with a gamepad to midi utility and I was able to play with no delay at all and even had some successful jam sessions with other musicians so I know for a fact it can be done.
When I added a light and a plane in the mix, which basically light up when a pad is struck/key is pressed it IS indeed lighting up immediately which means it is not an input delay.
I originally used .wav(PCM) files but I also tried a copy of the kick drum in ogg format. this brought the file size of the kick to 10k from 83k(wav) but the latency is still the same. the light lights up but the sound plays a split second after it lights up.
I have tried enabling decompress on load and have tried different levels of compression on the wav as well as the ogg just to see if it would change anything but it stays the same with the delayed response
I have also looked into weather there was silence in the beginning of the sound files and even tried cutting the first split second of one of the sounds just in case my eyes and judgment had deceived me but this also did not fix the delay problem.
I have tried changing the timing in my project settings to where the frame rate is in the 3,000+ fps range and it still has the same delay.
If any one knows a fix for this I would appreciate it very much.
Is there any way you could post the sound file(s) in question, or otherwise make them available?
sure, when i get home from work i will post the sound files as well as my unity(exported) file.
I’ve already suggested everything Unity-related I can think of in the first thread you made about this, but honestly if there is a general latency on Unity playing (uncompressed) sounds I’ve never noticed it. I’ve been working on a weapon this evening and the firing sound is perfectly synchronized with the mouse or keyboard input and the graphical firing effect, and this is at ~50fps in the editor in a heavy scene.
Obviously you’d notice any delays more if you were using a drum for input or had more experience with music/audio than I do, but have you tried this on another computer just to check it’s not your audio drivers or something? I can’t seem to replicate this here, so it’s either hardware-specific, a problem with your audio file, or my ears and/or brain. The last two have been destroyed by decades of loud music and alcohol, so who knows.
Well, it’s been a while since I pursued an answer to this problem but I finally got around to posting an example online so if any one could view my web player example and tell me if they are able to strike keys and hear sounds with out a noticeable delay. I have tested this on 3 computers and I get the same problem with a delay from the time i strike the key and the time the sound is fired off. You may have to hit your key hard enough for you to hear the key’s sound(not the drum sound but the actual key it self) in order to notice a delay.
I appreciate anyone willing to help me with this issue and help me figure out a solution to the huge latency gap I’m getting in my project.
on a side note if you really pay attention you can see that the light appears instantly when the key is pressed which seems to prove that its not a delay regaurding input.
here’s the link to the player: http://sidewalksurfer.net23.net/DrumTest0_25.html
Could you provide some general information on how its setup?
For example I assume that the audio clips are already assigned to the Audio Component(s) before the user can interact with the drums, right? (be it in a code setup or in form of having the clips and audio components already in the scene)
I ask to rule out the case where you have nothing loaded at all and then try to dynamically instantiate the audio from disk (WWW) or Resources in which case the delay is unavoidable as the data would first have to be gotten and the first block of it decompressed to play back.
Also what Unity Version are you on? the post 3.0 releases got some work in relation to audio which makes a difference
To answer the your last question first I am using version 3.3.0f4 (63135).
As far as my setup, I have vars set up which are of type : AudioClip and then i drag each sound from my assets to each slot created by the vars in the Unity editor.
the code is as follows:
var kk : AudioClip;
var sn : AudioClip;
var hhc : AudioClip;
var hho : AudioClip;
var tom : AudioClip;
var kkNoRepeat : int;
var snNoRepeat : int;
var hhcNoRepeat : int;
var hhoNoRepeat : int;
var tomNoRepeat : int;
var lightShow : Light;
var litAmount : float;
litAmount = 2.0;
function Update () {
if(Input.GetButton(“FootPedal”)||Input.GetButton(“Jump”)){
if(kkNoRepeat < 1){
kkNoRepeat += 1;
AudioSource.PlayClipAtPoint(kk, transform.position);
//AudioSource.PlayOneShot(kk);
litAmount = 2.0;
lightShow.intensity = litAmount;
}
}
else{
kkNoRepeat = 0;
litAmount -= 0.01;
lightShow.intensity = litAmount;
}
if(Input.GetButton(“BluePad”)||Input.GetButton(“Fire1”)){
if(snNoRepeat < 1){
snNoRepeat += 1;
AudioSource.PlayClipAtPoint(sn, transform.position);
litAmount = 2.0;
lightShow.intensity = litAmount;
}
}
else{
snNoRepeat = 0;
litAmount -= 0.01;
lightShow.intensity = litAmount;
}
if(Input.GetButton(“YellowPad”)||Input.GetButton(“Fire2”)){
if(hhcNoRepeat < 1){
hhcNoRepeat += 1;
AudioSource.PlayClipAtPoint(hhc, transform.position);
litAmount = 2.0;
lightShow.intensity = litAmount;
}
}
else{
hhcNoRepeat = 0;
litAmount -= 0.01;
lightShow.intensity = litAmount;
}
if(Input.GetButton(“RedPad”)||Input.GetButton(“Fire3”)){
if(hhoNoRepeat < 1){
hhoNoRepeat += 1;
AudioSource.PlayClipAtPoint(hho, transform.position);
litAmount = 2.0;
lightShow.intensity = litAmount;
}
}
else{
hhoNoRepeat = 0;
litAmount -= 0.01;
lightShow.intensity = litAmount;
}
if(Input.GetButton(“GreenPad”)){
if(tomNoRepeat < 1){
tomNoRepeat += 1;
AudioSource.PlayClipAtPoint(tom, transform.position);
litAmount = 2.0;
lightShow.intensity = litAmount;
}
}
else{
tomNoRepeat = 0;
litAmount -= 0.01;
lightShow.intensity = litAmount;
}
}
the part of the code regarding light was added to test how fast a light would respond compared to sounds being triggered and it lights up right away with no latency with the light at all as far as i can tell. I probably woulndt need the whole no repeat thing if i just use GetButtonDown but thats besides the point 
well, ive posted my code and no one has said anything. can any one help me with this problem or is unity just not suited for audio accuracy?
I think there may be some limitations as to how accurate Unity will be for this sort of thing. But, it’s certainly possible there’s something particular to your setup that’s exacerbating the problem.
I tried the web player, and although there wasn’t a particularly noticeable delay associated with playing a single drum sound, there’s certainly some noticeable inaccuracy overall. It could’ve just been me, but I’m guessing it might just be an inherent limitation of using Unity for this (among other things, you’re going to be limited by the granularity of the update cycle, which will depend on the machine on which the app is run, whether it’s a standalone or web player, etc.).
It might help if you were to re-post your code with ‘code’ tags (that’d make it easier to read). If you’re really stuck, you could also post a Unity package or project, in which case someone might be able to check it out and point out any obvious problems.
I just wanted to chime in to say that I have similar issues with a music-based application, and that I did indeed notice the latency on your WebPlayer.