Wednesday, January 25, 2012

C Coding Algorithm for producing Beep Sound with Different frequency


// beepcodes.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include
#include
#include

void GenerateSoundPattern(unsigned short code)
{
unsigned short temp;
while(code > 0)
    {
temp = code & 0xC000;
switch(temp)
{
 case 0x0000:
                        Beep(1000,1000);
break;
 case 0x4000:
                        Beep(1000,250);
break;
 case 0xC000:
                  return;
}
        Sleep(500);
code <<= 2;
    }

}

int main()
{
  GenerateSoundPattern(0x543C);  //01 01 01 00 00 11 11 00
  return 0;
}

No comments: