You are here:

C++/c++ coding to control all hardware


hello sir.
coming to my question directly-
can i give any beep sound to my audio out put(speakers, not the one on mother board) and scan a beep signal from audio input(Mick) by coding in c++?
or suggest me any other language to do this.

I presume that you mean via your audio hardware - sound card or integrated audio on the motherboard.

The answer is:

a) No. Not using ISO standard C++ as it has no idea what hardware will be available on all the types of system that C++ is designed to be used on - telephone exchange hardware for example probably has no such audio requirements. Hence the standard library supports general utilities such as collection types, maths functions, and stream IO with support for memory and file streams.

On the other hand there is an alert (or bell) escape code for C and C++ character and string literals which you may be able to get to beep through your main audio speakers. It is output using the C/C++ literal character escape code '\a' (a for alert), so you could try:

   std::cout << '\a' << std::endl;
(it did not work using Visual C++ 2008 under Vista 64 bit but did using g++ 4.2.4 under Ubuntu 8.04 64 bit running in a virtual machine on the same system - go figure. So your mileage may vary.)

b) Yes if you have operating system support, the development files required to access these facilities or a third party library that wraps them for you. E.g. on a PC running a MS Windows operating system you could look at the DirectSound portion of the DirectX libraries or maybe the older audio multimedia APIs (Application Program Interface) or even the Beep Win32 API function (although this did not work on my system and might beep through the PC speaker!). In order to utilise the DirectX API you would require the DirectX SDK (Software Development Kit). To do general Windows programming you require the Windows Platform SDK (or a third party equivalent - such as the header files and libraries provided by the MinGW project).

For more on the various Microsoft support options for audio see the Microsoft developer network (MSDN) and the MSDN library. This can be found online at:

( you might like to try searches like: "audio recording". I found I had to add refinements to restrict the results to:

   Win32 & COM Windows, Graphics and Multimedia Library,  Documentation & Articles
to get an initial useful set of results. You might like to try "audio directx" as another starter.

Note: b) also requires you to have device driver support for the hardware and operating system in question, and have it successfully installed and operating.

You will notice that in order to do what you want from a modern desktop operating system you do not hit the hardware directly but go through operating system APIs and a device driver:

   [Application Program]- uses ->[operating system audio APIs]- uses ->[device driver]- accesses ->[hardware]

In some cases you may find that the hardware manufacturer will provide their own SDK that has additional features specific to their hardware. Hopefully this is less needed these days.

As to possible other languages - C is an obvious first thought as many operating systems have C APIs anyway. Then of course any language that can use system C APIs - which could include FORTRAN, Visual Basic etc. or newer managed environments such as Java which seems to have a sound API ( and .NET which may have some audio support in the framework (I noticed references to managed DirectX articles in some of the search results I got on MSDN). For .NET C# would be an obvious choice of language but there are now quite a few languages built around .NET. I would not be surprised if there are ways to access such base system audio facilities from most languages - however you would have to check first how easy it is (e.g. has someone done the work to interface the facilities to the language in question already? Is there an easy way to access such facilities from within the language in question? Etc.)

If you have no operating system or an operating system that lets you have direct access to the hardware such as MS-DOS then you can of course hit the hardware directly  - but you _will_ have to have a very intimate knowledge of the exact specification of the hardware and its setup on your motherboard to do this and you may need to use assembler as well as C or C++ to get things up and running (some C and C++ implementations have extra features to support hardware access and maybe even inline assembler). If you change your motherboard for one with different hardware or wish to use a shiny new sound card's capabilities then you will have to learn the specifics of the new hardware and re-work your code to work with it. Basically you will have to have the knowledge that is used by device driver writers - and this level of information may not be made publicly available by the audio hardware vendor. Either that or use vendor supplied libraries / drivers (in case of some operating system support).

All in all I would say it is much easier to let an operating system and device driver for your hardware take care of much of these details for you and concentrate on coding to operating system APIs directly or through an even easier to use (depending on what you are trying to do) library.

Hope this has helped a bit.


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2017 All rights reserved.