Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

need 16-bit program to generate tones

dnraikesdnraikes Member Posts: 3
I am a newbie with c programming, but I need an application which I can run from a dos boot disk which will generate various tones.

I am blind, and want to use it to tell me where I am in a batch script.
My preference would be to accept command-line parameters for the frequencies to play, then generate the tones accordingly for a set length of time.

Any suggestions would be appreciated.

Comments

  • Griz803Griz803 Member Posts: 100
    : I am a newbie with c programming, but I need an application which I can run from a dos boot disk which will generate various tones.
    :
    : I am blind, and want to use it to tell me where I am in a batch script.
    : My preference would be to accept command-line parameters for the frequencies to play, then generate the tones accordingly for a set length of time.
    :
    : Any suggestions would be appreciated.
    :
    That shouldn't be too difficult. First, if you have the Borland Turbo C++ version 2.0 or higher compiler, there are functions in the dos.h library that will make generating a tone over a PC speaker very easy. The first is called sound and is called with the frequency you want to
    use. The second is nosound and will turn the tone off. The third is delay and is called with the number of milliseconds to wait. During delay, the program just stops and waits. Another alternative to delay is sleep, which does the same and takes a value in seconds. If you don't have Turbo C++ (which will also compile C), you can get it from
    http://community.borland.com/article/20841 as a download link. The next couple of links give you information about and examples on taking command line arguments. http://www.its.strath.ac.uk/courses/c/subsection3_4_5.html#SECTION0004500000000000000

    http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/c_tutorial.html#command-line

    Although one deals with Unix/Linux, the command line portion of it is the same for DOS, it is simply parsed differently after it is read. I would build the program first as a simple program that makes a tone and turns it off after so much time, or uses a loop to beep off and on for so many seconds. Then turn that into a function that takes a parameter for the time it runs and use this function in a program that takes command line parameters as a way to control the length, frequency and and timing of the beeps. I hope that this gives you the basic idea. Good Luck!
  • dnraikesdnraikes Member Posts: 3
    : : I am a newbie with c programming, but I need an application which I can run from a dos boot disk which will generate various tones.
    : :
    : : I am blind, and want to use it to tell me where I am in a batch script.
    : : My preference would be to accept command-line parameters for the frequencies to play, then generate the tones accordingly for a set length of time.
    : :
    : : Any suggestions would be appreciated.
    : :
    : That shouldn't be too difficult. First, if you have the Borland Turbo C++ version 2.0 or higher compiler, there are functions in the dos.h library that will make generating a tone over a PC speaker very easy. The first is called sound and is called with the frequency you want to
    : use. The second is nosound and will turn the tone off. The third is delay and is called with the number of milliseconds to wait. During delay, the program just stops and waits. Another alternative to delay is sleep, which does the same and takes a value in seconds. If you don't have Turbo C++ (which will also compile C), you can get it from
    : http://community.borland.com/article/20841 as a download link. The next couple of links give you information about and examples on taking command line arguments. http://www.its.strath.ac.uk/courses/c/subsection3_4_5.html#SECTION0004500000000000000
    :
    : http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/c_tutorial.html#command-line
    :
    : Although one deals with Unix/Linux, the command line portion of it is the same for DOS, it is simply parsed differently after it is read. I would build the program first as a simple program that makes a tone and turns it off after so much time, or uses a loop to beep off and on for so many seconds. Then turn that into a function that takes a parameter for the time it runs and use this function in a program that takes command line parameters as a way to control the length, frequency and and timing of the beeps. I hope that this gives you the basic idea. Good Luck!
    :
    Thanks so much for the info.
    I downloaded turbo c 2.0.1, and installed it.
    My program works pretty well, but I can only get it to generate one tone.

    If I try
    ...
    sound(500);
    delay(500);
    nosound();
    sound(1500);
    delay(500);
    nosound();

    it will only play the first sound not the second one.

    My current program is as follows, and it will work for what I need, just wanted to be a little fancier.

    #include
    #include

    void gen(int freq);

    int main (int argc, char *argv[])
    {
    int func;
    if (argc != 2) {
    printf("You must supply an argument for this application
    ");
    printf(" 0) error - generates a low tone
    ");
    printf(" 1) success - generates a high tone
    ");
    return 1;
    };
    sscanf(argv[1], "%d", &func);
    printf("Supplied argument was: (%s) - (%d)
    ",argv[1],func);
    if (func==0)
    {
    gen(500);
    } else {
    gen(1000);
    };
    return 0;
    }

    void gen(int freq)
    {
    sound(freq);
    delay(1000);
    nosound();
    return;
    }


  • Griz803Griz803 Member Posts: 100
    : : : I am a newbie with c programming, but I need an application which I can run from a dos boot disk which will generate various tones.
    : : :
    : : : I am blind, and want to use it to tell me where I am in a batch script.
    : : : My preference would be to accept command-line parameters for the frequencies to play, then generate the tones accordingly for a set length of time.
    : : :
    : : : Any suggestions would be appreciated.
    : : :
    : : That shouldn't be too difficult. First, if you have the Borland Turbo C++ version 2.0 or higher compiler, there are functions in the dos.h library that will make generating a tone over a PC speaker very easy. The first is called sound and is called with the frequency you want to
    : : use. The second is nosound and will turn the tone off. The third is delay and is called with the number of milliseconds to wait. During delay, the program just stops and waits. Another alternative to delay is sleep, which does the same and takes a value in seconds. If you don't have Turbo C++ (which will also compile C), you can get it from
    : : http://community.borland.com/article/20841 as a download link. The next couple of links give you information about and examples on taking command line arguments. http://www.its.strath.ac.uk/courses/c/subsection3_4_5.html#SECTION0004500000000000000
    : :
    : : http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/c_tutorial.html#command-line
    : :
    : : Although one deals with Unix/Linux, the command line portion of it is the same for DOS, it is simply parsed differently after it is read. I would build the program first as a simple program that makes a tone and turns it off after so much time, or uses a loop to beep off and on for so many seconds. Then turn that into a function that takes a parameter for the time it runs and use this function in a program that takes command line parameters as a way to control the length, frequency and and timing of the beeps. I hope that this gives you the basic idea. Good Luck!
    : :
    : Thanks so much for the info.
    : I downloaded turbo c 2.0.1, and installed it.
    : My program works pretty well, but I can only get it to generate one tone.
    :
    : If I try
    : ...
    : sound(500);
    : delay(500);
    : nosound();
    : sound(1500);
    : delay(500);
    : nosound();
    :
    : it will only play the first sound not the second one.
    :
    : My current program is as follows, and it will work for what I need, just wanted to be a little fancier.
    :
    : #include
    : #include
    :
    : void gen(int freq);
    :
    : int main (int argc, char *argv[])
    : {
    : int func;
    : if (argc != 2) {
    : printf("You must supply an argument for this application
    ");
    : printf(" 0) error - generates a low tone
    ");
    : printf(" 1) success - generates a high tone
    ");
    : return 1;
    : };
    : sscanf(argv[1], "%d", &func);
    : printf("Supplied argument was: (%s) - (%d)
    ",argv[1],func);
    : if (func==0)
    : {
    : gen(500);
    : } else {
    : gen(1000);
    : };
    : return 0;
    : }
    :
    : void gen(int freq)
    : {
    : sound(freq);
    : delay(1000);
    : nosound();
    : return;
    : }
    :
    :
    :


    Ok, first please use code tags when posting code. Second, here is an example of what I do for a split tone.
    [code]
    void E_Tone(void)
    {
    sound(HIGH);
    delay(SHORT_TONE);
    sound(LOW);
    delay(SHORT_TONE);
    nosound();
    }
    [/code]

    The nosound will sometimes take out the second sound's activation, why I'm not positively sure, but I suspect it is a "random feature" of the library. I hope this helps. If you'd like to see full code, post again and I'll post it here.
  • dnraikesdnraikes Member Posts: 3
    : : : : I am a newbie with c programming, but I need an application which I can run from a dos boot disk which will generate various tones.
    : : : :
    : : : : I am blind, and want to use it to tell me where I am in a batch script.
    : : : : My preference would be to accept command-line parameters for the frequencies to play, then generate the tones accordingly for a set length of time.
    : : : :
    : : : : Any suggestions would be appreciated.
    : : : :
    : : : That shouldn't be too difficult. First, if you have the Borland Turbo C++ version 2.0 or higher compiler, there are functions in the dos.h library that will make generating a tone over a PC speaker very easy. The first is called sound and is called with the frequency you want to
    : : : use. The second is nosound and will turn the tone off. The third is delay and is called with the number of milliseconds to wait. During delay, the program just stops and waits. Another alternative to delay is sleep, which does the same and takes a value in seconds. If you don't have Turbo C++ (which will also compile C), you can get it from
    : : : http://community.borland.com/article/20841 as a download link. The next couple of links give you information about and examples on taking command line arguments. http://www.its.strath.ac.uk/courses/c/subsection3_4_5.html#SECTION0004500000000000000
    : : :
    : : : http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/c_tutorial.html#command-line
    : : :
    : : : Although one deals with Unix/Linux, the command line portion of it is the same for DOS, it is simply parsed differently after it is read. I would build the program first as a simple program that makes a tone and turns it off after so much time, or uses a loop to beep off and on for so many seconds. Then turn that into a function that takes a parameter for the time it runs and use this function in a program that takes command line parameters as a way to control the length, frequency and and timing of the beeps. I hope that this gives you the basic idea. Good Luck!
    : : :
    : : Thanks so much for the info.
    : : I downloaded turbo c 2.0.1, and installed it.
    : : My program works pretty well, but I can only get it to generate one tone.
    : :
    : : If I try
    : : ...
    : : sound(500);
    : : delay(500);
    : : nosound();
    : : sound(1500);
    : : delay(500);
    : : nosound();
    : :
    : : it will only play the first sound not the second one.
    : :
    : : My current program is as follows, and it will work for what I need, just wanted to be a little fancier.
    : :
    : : #include
    : : #include
    : :
    : : void gen(int freq);
    : :
    : : int main (int argc, char *argv[])
    : : {
    : : int func;
    : : if (argc != 2) {
    : : printf("You must supply an argument for this application
    ");
    : : printf(" 0) error - generates a low tone
    ");
    : : printf(" 1) success - generates a high tone
    ");
    : : return 1;
    : : };
    : : sscanf(argv[1], "%d", &func);
    : : printf("Supplied argument was: (%s) - (%d)
    ",argv[1],func);
    : : if (func==0)
    : : {
    : : gen(500);
    : : } else {
    : : gen(1000);
    : : };
    : : return 0;
    : : }
    : :
    : : void gen(int freq)
    : : {
    : : sound(freq);
    : : delay(1000);
    : : nosound();
    : : return;
    : : }
    : :
    : :
    : :
    :
    :
    : Ok, first please use code tags when posting code. Second, here is an example of what I do for a split tone.
    : [code]
    : void E_Tone(void)
    : {
    : sound(HIGH);
    : delay(SHORT_TONE);
    : sound(LOW);
    : delay(SHORT_TONE);
    : nosound();
    : }
    : [/code]
    :
    : The nosound will sometimes take out the second sound's activation, why I'm not positively sure, but I suspect it is a "random feature" of the library. I hope this helps. If you'd like to see full code, post again and I'll post it here.
    :
    Hi again,

    I still get only one tone.
    I copied your code style exactly, but unfortunately no difference.

    I even tried for three tones hoping that at least two would be produced, but just one.
  • Griz803Griz803 Member Posts: 100
    [b][red]This message was edited by Griz803 at 2006-6-15 12:53:58[/red][/b][hr]
    :
    : Hi again,
    :
    : I still get only one tone.
    : I copied your code style exactly, but unfortunately no difference.
    :
    : I even tried for three tones hoping that at least two would be produced, but just one.
    :
    Ok, well there is one alternative here that may be a factor. Some PC speakers have a really lame range of frequencies that they can produce, since they are about the cheapest speakers I've seen on the planet;-) Below is the code that I referred to, it works with my system and the cheap speaker I have, frequencies can be adjusted easily from the defined constants.
    [code]
    /* Toner is a small utility suggested to me from a post to a forum. An individual can use *
    * this as an audible warning that some function has begun, ceased or needs input. It is *
    * designed to be called from a batch file or other program with a command line parameter. *
    * They are: /E for ERROR TONE, /B for BEGINNING BEEP, /A for ATTENTION BEEP and /S for *
    * EXECUTION STOPPED BEEP. Written 6/13/06 by Dan Lane. Public Domain for Free Software. */


    /* Get some libraries that are needed. */
    #include
    #include
    #include
    #include
    #include

    /* Defines the message layout for the help and error default screens. */
    #define LN_1 " This program requires a single command line parameter.
    "
    #define LN_2 " Options are:
    "
    #define LN_3 " /A - Attention beep - 500 ms high tone.
    "
    #define LN_4 " /B - Beginning beep - 500 ms mid tone.
    "
    #define LN_5 " /S - Stopped beep - 500 ms low tone.
    "
    #define LN_6 " /E - Error tone - 250 ms high, 250 low.
    "
    #define LN_7 " /H, /h or /? - Displays this screen.
    "
    #define LN_8 " Uses only one parameter at a time. Errors show help screen.
    "
    #define LN_9 " Usage is "toner /A" for an Attention beep.
    "

    /* Defines the constants LONG_TONE and SHORT_TONE to control the tone lengths. */
    #define LONG_TONE 500
    #define SHORT_TONE 250

    /* Defines frequency constants for the tones HIGH, MID and LOW. */
    #define HIGH 4000
    #define MID 2000
    #define LOW 200

    /* Define DEBUG for testing facilities. */
    /* #define DEBUG */

    /* A few function declarations that are defined later on. */
    void E_Tone(void);
    void B_Tone(void);
    void A_Tone(void);
    void S_Tone(void);
    void Display_Help(void);

    /* Main Function, program entry point here. */
    int main(int argv, char * argc[])
    {
    if(argv!=2){
    Display_Help();
    }
    if(strcmpi(argc[1],"/A")==0){
    A_Tone();
    }
    else if(strcmpi(argc[1],"/B")==0){
    B_Tone();
    }
    else if(strcmpi(argc[1],"/S")==0){
    S_Tone();
    }
    else if(strcmpi(argc[1],"/E")==0){
    E_Tone();
    }
    else if(strcmpi(argc[1],"/H")==0 || stricmp(argc[1],"/?")==0){
    Display_Help();
    }
    #ifdef DEBUG
    A_Tone();
    getch();
    B_Tone();
    getch();
    S_Tone();
    getch();
    E_Tone();
    getch();
    Display_Help();
    #endif

    return(0);
    }

    /* The E_Tone function generates a split high, low pulsed tone from the PC Speaker. */
    void E_Tone(void)
    {
    sound(HIGH);
    delay(SHORT_TONE);
    sound(LOW);
    delay(SHORT_TONE);
    nosound();
    }

    /* The B_Tone function generates a 150 ms beep in the mid-range. */
    void B_Tone(void)
    {
    sound(MID);
    delay(LONG_TONE);
    nosound();
    }

    /* The A_Tone function generates a 150 ms beep in the moderately high range. */
    void A_Tone(void)
    {
    sound(HIGH);
    delay(LONG_TONE);
    nosound();
    }

    /* The S_Tone function generates a 150 ms beep in the moderately low range. */
    void S_Tone(void)
    {
    sound(LOW);
    delay(LONG_TONE);
    nosound();
    }


    /* The Display_Help function puts options to screen in a solid block message. */
    void Display_Help(void)
    {
    clrscr();
    puts("
    ");
    puts("
    ");
    puts(LN_1);
    puts(LN_2);
    puts(LN_3);
    puts(LN_4);
    puts(LN_5);
    puts(LN_6);
    puts(LN_7);
    puts(LN_8);
    puts(LN_9);
    }
    [/code]

    Try compiling this, I used it as an excercise and a convenience. Since it can run from abatch file and I use them to reload OSes on computers
    occasionally, it will allow me to know what is going on while not paying close attention to the screen. If the frequencies given aren't audible on your system under DOS or a console Window, then it is something else going on. Good luck and let me know how it turns out.


    P.S. I've just re-compiled my code inserting your frequencies. I don't think that they are far enough apart to be easily distinguishable by most humans. Could this be the problem you're having? Note the difference in magnitudes of frequencies in my code example (200 Hz=Low, 2000 Hz = Mid and 4000 Hz = High). Don't know for sure, just know that I could hardly tell a shift with double the time. I hope this helps and doesn't lead you astray in correcting the problem.
Sign In or Register to comment.