Music

This is a discussion on Music within the C++ Programming forums, part of the General Programming Boards category; this is the wait function Code: void wait ( int seconds ) { clock_t endwait; endwait = clock () + ...

  1. #16
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    this is the wait function

    Code:
    void wait ( int seconds )
    {
      clock_t endwait;
      endwait = clock () + seconds * CLK_TCK ;
      while (clock() < endwait) {}
      
    }

  2. #17
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Code:
    void wait ( double seconds ) 
    {
      clock_t endwait;
    
      endwait = clock () + seconds * CLK_TCK;
      while (clock() < endwait);
    }
    If you change it to the above. A question though, is CLK_TCK 1000?

    now you can say - wait( 0.5 ), and it'll work ... hopefully


    EDIT ::

    Also, here's a REALLY simple timing class I made before - Date & Time

    To use it, do something like this

    Code:
    TimeIt TimeForBeep;
    for ( limits )
    {
      TimeForBeep.StartTimer();
      // your beep stuff here
      TimeForBeep.EndTimer();
    
      wait( 1 - TimeForBeep.GetTime() );
    
      cout<< "Whatever";
    
      TimeForBeep.Clear(); // Not really needed I suppose
    }
    EDIT:: NP Raigne
    Last edited by twomers; 09-04-2006 at 11:04 AM.

  3. #18
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    If I understand correctly you need to make your program wait the exact length of each Beep so that it is relatively right, but if you want you could use multi-threading to doit as well, that is if you want to make somehting like a audio mixer or something, and thanks for fixing my mistake in my first post twomers ( geeze i cant type today)
    Last edited by Raigne; 09-04-2006 at 11:04 AM.

  4. #19
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    i cant remember what the CLK_TCK is but i think it is 1000

    says there is an error with

    Code:
    endwait = clock () + seconds * CLK_TCK;

  5. #20
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Quote Originally Posted by peckitt99
    i cant remember what the CLK_TCK is but i think it is 1000

    says there is an error with

    Code:
    endwait = clock () + seconds * CLK_TCK;
    What's the error, peckitt99?

    Also, look at my edit on my previous post.

  6. #21
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    it says

    [warning] assignment

    sorry bout all the questions im actually new to this n gotta learn it since im doing computing forensics in uni, lol

  7. #22
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    It's warning you cause the types are different. ints doubles and clock_t's

    You have a few options, revert to an int, but instead of having seconds, use miliseconds, so 500 would be half a second ect.

    Code:
    void wait ( int miliseconds ) 
    {
      clock_t endwait;
    
      endwait = clock () + miliseconds
      while (clock() < endwait);
    }
    Or cast the result. I think the above is a better option.

  8. #23
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    ah right ok thanx,

    ill give it all ago n see if i can get it to work.

    thanks for all your help

  9. #24
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    for some reason it dont like wait(0.5). says there is a warning with the passing.

  10. #25
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Are you using the milisecond version? If so, say - wait( 500 ); 0.5 is full seconds, remember.

  11. #26
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    With the portability thing though I am sure I saw that your code was using (or you were going to use) system ("CLS") making it un-portable so therefore it is a lot easier to use Sleep ();

  12. #27
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    Windows Console Option. Still using windows, but after that, use option 5

  13. #28
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    yeah i have changed it to 500 but it still cant play both at the same time it is always waits for one to finish before doing something again.

  14. #29
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Course it does! Those functions aren't asynchronous! Sorry, I thought I'd expressed as much in an earlier post. I don't know any asynch functions to play sound.

  15. #30
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Code:
    CLK_TCK
    Did you mean CLOCKS_PER_SEC?
    The time in seconds is the value returned by the clock function, divided by CLOCKS_PER_SEC. CLK_TCK is equivalent, but considered obsolete.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone saves us from music
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 78
    Last Post: 07-02-2008, 08:59 AM
  2. Music Programming - Serial Matrix Display (Help needed)
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-13-2007, 03:28 PM
  3. Music Programming - Serial Matrix Display
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 03:16 PM
  4. Is AOL music crazy?
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-24-2006, 06:24 PM
  5. crashing when switch music type
    By lambs4 in forum Game Programming
    Replies: 7
    Last Post: 05-03-2004, 12:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21