Thread: Beep-Beep

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    6

    Question Beep-Beep



    Hey does anyone know how to set up this program with a command line that will have: prog sound1 duration1 sound2 duration2....


    #include <iostream.h>
    #include <stdlib.h>
    #include <windows.h>

    void soundSequence(int sounds[], int duration [], int numSounds);
    int main(int argc, char *argv[])
    {
    Beep(1000,1000);//1kHz tone for 1 second
    Sleep(1000);//Wait for 1 second!!
    Beep (2000,1000);//2kHz tone for 1 seconds
    Beep (4000,2000);//4kHz tone for 2 seconds
    Beep (6000,4000);//6 kHz tone for 4 seconds
    system("PAUSE");
    return 0;
    }


    Thanks for your help in advance.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Have a read of this
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Exclamation WARNINGS

    The beep() function is platform dependent.

    As I recall... With Win98, the frequency and duration will be ignored. You'll get a default beep. With WinXP, the frequency and duration are used only if you don't have a sound card. If you have a sound card, you get the "Windows Default" sound.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    6

    Smile

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <windows.h>
    
    void soundSequence(int sounds[], int duration [], int numSounds);
    int main(int argc, char *argv[])
    {
      //Convert the following code into a function with prototype:
      //void soundSequence(int sounds[], int duration [], int numSounds);
      //main is to read command line arguments and load up arrays to 
      //pass to function.  Allocate memory dynamically for arrays.
      //command line: prog sound1 duration1 sound2 duration2.....
      //sound of 0 will sleep for the duration.
       
      Beep(1000,1000);//1kHz tone for 1 second
      Sleep(1000);//Wait for 1 second!!
      Beep (2000,1000);//2kHz tone for 1 seconds
      Beep (4000,2000);//4kHz tone for 2 seconds
      Beep (6000,4000);//6 kHz tone for 4 seconds
      system("PAUSE");	
      return 0;
    }
    I hope this is better

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    21
    just to point out...

    You can't just compare the command line arguments with just the assignment operator

    you must use and should I think, use a function like 'strncmp'

    ex:
    /* check the first argument */
    if ( (strncmp(argv[1],"-c",2))==0 )
    {
    /* do something */
    }
    else {
    printf("Bad command line argument");
    }

    hope this helps

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    1

    Smile This might help

    int main (int argc, char **argv)
    {
    int numpts = argc - 3;
    double *data = new double[numpts];
    for (int i = 0; i < numpts; i++)
    data[i] = atof (argv[i+3]);
    if (strcmp (argc[1], "mav")
    {
    int winsize = atoi (argv[2]);
    }
    return 0;
    }


    Hope this helps some

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linux beep function
    By Calef13 in forum C++ Programming
    Replies: 7
    Last Post: 07-14-2007, 01:39 AM
  2. I need to play a pre recorded vox file using C
    By m.sudhakar in forum C Programming
    Replies: 4
    Last Post: 11-17-2006, 06:59 PM
  3. alert beep sound
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 02-14-2006, 02:24 PM
  4. Beep();
    By SirCrono6 in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2004, 04:47 PM
  5. Something Like beep()
    By Trauts in forum C++ Programming
    Replies: 3
    Last Post: 02-02-2003, 02:51 PM