I have a problem with sound latency. I have made a program where different sounds are played when typing different keys, either on a regular pc keyboard or on a music keyboard. There is one sound file of about 10 seconds length used within each octave, and the sound file is transposed to different frequencies when pressing different keys. The problem is that there often is a delay before the sound occurs when pressing a key, which doesn’t work, and sometimes the system even breaks down and I don’t get any sound at all. I wonder therefore if these problems could be solved, and the program could work as an ordinary keyboard instrument. I am working in C for Windows and the code I’m using is something like this:
result = FMOD_System_CreateSound(systemx, "soundfile.wav", FMOD_CREATESAMPLE | FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound);
case ‘D’: keynumber = 0; break;
case ‘F’: keynumber = 1; break;
case ‘G’: keynumber = 2; break;
case ‘H’: keynumber = 3; break;
case ‘J’: keynumber = 4; break;
result = FMOD_System_PlaySound(systemx, FMOD_CHANNEL_FREE, sound, 1, &channel);
frequency = scale[keynumber];
keyflag = 0;
case WM_KEYUP :
keyflag = 1;
I also wonder what would be the best strategy if I want more than one key sound to sound simultaneously. Should I then for instance play each sound in a different channel.
It would be greatly appreciated if someone could help me with this. Thanks in advance.
- Varun asked 5 years ago
End-to-end latency on a PC is a complicated topic, and there are a lot of places that delay can be introduced: keyboard hardware, operating system input drivers, FMOD itself, audio drivers, audio hardware.
You can try calling FMOD_System_SetDSPBufferSize() before initialising the system. Smaller and fewer mixblocks will improve the internal latency of FMOD. Also using FMOD_System_SetOutput(FMOD_OUTPUTTYPE_ASIO) to switch to an ASIO audio driver might help.
If you’re not getting any sound at all, what return codes are you getting from PlaySound? If you’re trying to hold down multiple keys to play a chord you need to look into keyboard ghosting issues http://www.microsoft.com/appliedscience … ained.mspx
Thank you very much , that was useful. I have tried using ASIO and it helps. I have also tried using the different ferquencies of the same sound in seperate channels and only use setpause to start and stop the sounds, and I don’t have the problem of sounds stopping anymore. I just hope this approach doesn’t require to much resources. I will also experiment with buffersize later. However, I have one question that I wonder if you maybe could answer. If I wanted to make the program into an embedded system with Windows CE to use for a keyboard instrument, could I then use basically the same program or is there other things I would have to consider?
- Varun answered 5 years ago
Please login first to submit.