Hi,

Im trying to make a sysmple program that plays different .wav files when an appropiate key is pressed. Its going to be keyboard drumkit kind of thing,

anyway, ive got it to play the sounds, but they always seem to have a short delay, from when the key is pressed to when the sound is played. Ive checked the wav file in audacity, and theres no delay at the start, the sound plays right off,

could any give any ideas on how to solve this, ive also tryed this program with a Beep(1000,50); function, and it works perfectly, the exact speedy responce im after.

but the wav file is just very slow at responding,

heres the code, and also the wav file, please help!!

#include <iostream>
#include <windows.h>   
#include <TCHAR.H>
#include <conio.h>


int main()
{

    while(1)
    {

    if(getch()=='w')
        {
         //Beep(1000,50);  
        PlaySound(_T("kick.wav"),NULL,SND_ASYNC|SND_FILENAME);

        
        }
        
    }

  return 0;

}

Recommended Answers

All 2 Replies

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_playsound.asp
Read up on SND_MEMORY and SND_RESOURCE.
Accessing sounds in memory will be quicker than loading them off disk each time.

SND_ASYNC is good if you want to play really long files, and you want to be getting on with something else in the meantime. If you just want to play a short 'beep', and have nothing else to do, then try it without this flag.

Hi, sorry, but im still learning so your going to have to explain more,

from reading this page,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_playing_wave_resources.asp

i take it, all i have to to, is to write the following in the resource script,
soundName WAVE c:\sounds\kick.wav

and then access it as normal via

PlaySound(_T("kick.wav"),NULL,SND_MEMORY);

how do i access the resource script, the only thing i can find is a file called test.exe.embed.manifest, in the debug folder, in my project folder, and when i open it, its in hex, so how do i write that line up the top?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.