CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Question Sound sinchronization

    Hello, my problem is, i´ve created a windows program that plays a sound with playsound function from mmsystem.h and then starts a timer that works with getsystemtime and the _systemtime variables.

    First, the sound is started with the playsoundfuction, and inmediatly after, the getsystemtime stores the current time in a global variable, later, a loop function calculates the time between frames, but thats not the problem, my problem is that the sound is not played inmediatly, and the storage of the first moment on the execution of the program, is not the same of the start of the sound.

    The sound plays with a bigger delay, on slow computers, but the time control variable, always starts inmediatly, so, i need a windows functions that continues the program execution when the sound is just started, and i found no flags for the playsound function with that functionality.

    (my native languaje is spanish so, sorry if you dont understand something.....)

  2. #2
    Join Date
    Aug 2007
    Location
    Birmingham, UK
    Posts
    360

    Re: Sound sinchronization

    Hello,

    I think the problem is that the playsound function isn't intended as a "real-time" sound output function. It needs to load the sound data and initialise the sound system before it can start the playback. I remember that IE suffered from this as well, with the little tick and click sounds always lagging behind the actual event (haven't used IE in years, no idea if they've fixed it now).

    The best method to get it as close to real-time as possible is by loading the audio data in your own program and to play it back in your own program, rather than through playsound. This is unfortunately not trivial, but to be compatible with most Windows versions you can look at the waveOut API in Windows.

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Sound sinchronization

    When calling PlaySound, try including the SND_ASYNC flag.

    Mike

  4. #4
    Join Date
    Feb 2012
    Posts
    2

    Re: Sound sinchronization

    thanks for the replies, but, the idea, is to continue the aplicatian in the exact moment that the sound starts to play, and i already tried to preload the sound reading it, in direct sound, but im not an expert on direct sound api, so in a big wave file, that has a list, tag, instead of a data tag, i dont know what to do and dont care right now, openings mp3 files is other thing, anyway, i downloaded bass library and the
    chan = BASS_MusicLoad(FALSE,file,0,0,BASS_MUSIC_RAMP|BASS_SAMPLE_LOOP,0)
    and the chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP)
    and then a BASS_ChannelPlay(chan,FALSE);
    reproduces a sound and continues the aplication inmediatly, when it starts

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured