Music in Interactive programs and delay();

This is a discussion on Music in Interactive programs and delay(); within the C++ Programming forums, part of the General Programming Boards category; I have been thinking about making an interactive program(game most likely) that has some composed music in the background. I ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    14

    Music in Interactive programs and delay();

    I have been thinking about making an interactive program(game most likely) that has some composed music in the background. I don't know how i could do this without creating my own kind of time function. I've tried many things and have already made my own(im sure there already is one but its good practice for me =\) note function which is basically just void note(char letter[], int volume, length) and is being used with delay. Problem is: delay sucks. It stops everything. I'm very new to programing so if the solution is obvious don't do anything drastic =\. Thanks in advance. Il post some of my old code too, i cant think of anything and am very stuck =(

    Code:
    void note(char note[], int num);
    
    int expo(int num, int power);
    
    main()
    {
        clrscr();
    
    
        getch();
        return 0;
    
    }
    
    int expo(int num, int power)
    {
        int newnum=1;
    
        if (power == 0)
    	return 1;
        else
    	for (power; power>0; power--)
    	    newnum *=num;
    
        return newnum;
    }
    
    void note(char note[], int num)
    {
        if (strcmp(note, "C") == 0)
    	{
    	    sound(16.35*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "C#") == 0)
    	{
    	    sound(17.32*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "D") == 0)
    	{
    	    sound(18.35*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "D#") == 0)
    	{
    	    sound(19.45*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "E") == 0)
    	{
    	    sound(20.60*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "F") == 0)
    	{
    	    sound(21.83*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "F#") == 0)
    	{
    	    sound(23.12*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "G") == 0)
    	{
    	    sound(24.50*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "G#") == 0)
    	{
    	    sound(25.96*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "A") == 0)
    	{
    	    sound(27.50*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "Bb") == 0)
    	{
    	    sound(29.14*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
        if (strcmp(note, "B") == 0)
    	{
    	    sound(30.87*expo(2, num));
    	    delay(1000);
    	    nosound();
    	}
    }
    ~fin

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I don't think there's any other func than Sleep() available to halt the thread..
    Anyway. You can just run the note func in an own thread. That would not halt anything in your prog.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Delay time between inputs
    By Cabbie in forum C Programming
    Replies: 6
    Last Post: 02-18-2008, 03:32 AM
  2. Create a delay without using Sleep
    By Bag a Bones in forum C++ Programming
    Replies: 12
    Last Post: 01-25-2006, 09:35 PM
  3. Delay
    By Perica in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2002, 09:45 PM
  4. delay() in Bc++ 5.5
    By Chiki Chiki Chalem in forum C++ Programming
    Replies: 1
    Last Post: 07-07-2002, 09:58 AM
  5. Delay
    By Alberan in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2002, 07:37 AM

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