a rocket launch sound

please any body to help me on how to add sound or
go to the extent of adding a sound in a written code...
im on a project to write a code of a rocket launch which counts from 9,8,7,6,5,4,3,2 & 1 to fire that rocket of which i am done with that but how to add the sound to after the count down is my problem now....
This is the only way I know on how to make any kind of sound.

cout << "\a";
Generally you are going to want to load a library, something like openAl, or use a GUI library's audio functions.

OpenAl - http://www.david-amador.com/2011/06/playing-sound-using-openal/
SDL2 - http://lazyfoo.net/tutorials/SDL/21_sound_effects_and_music/index.php
Qt ------ http://doc.qt.io/qt-5/qsoundeffect.html
SFML - https://www.google.com/search?q=play+sound+SFML&ie=utf-8&oe=utf-8 (take your pick)
WinApi - http://stackoverflow.com/questions/9961949/playsound-in-c-console-application

If you decide on Qt, the soundEffect object is used for small sound effects like a button getting pressed gets a small confirmation noise. There are several media-player type objects for larger media files.

Each of these libraries have their own quirks, so I can't recommend one over the other. WinApi might be the simplest to get started using, but then your program won't be cross-platform... SFML might be the easiest cross-platform option.
Last edited on
If you are using a Windows computer you might be able to use Beep(). It's not portable, though.

Here's the scale of A major - not very rocket-like I'm afraid!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <cmath>
#include <windows.h>
using namespace std;

void sound( double freq, int ms )
{
   int ifreq = freq + 0.5;   // round to nearest int
   Beep( ifreq, ms );
}

int main()
{
   double A = 440.0;                                     // tuning fork A;
   double semitoneFactor = pow( 2.0, 1.0 / 12.0 );       // factor for a semitone
   int steps[] = { 2, 2, 1, 2, 2, 2, 1 };                // intervals in a major scale
   int ms = 500;                                         // duration in milliseconds

   double freq = A;
   sound( freq, ms );
   for ( int i = 0; i < 7; i++ )
   {
      for ( int s = 1; s <= steps[i]; s++ ) freq *= semitoneFactor;
      sound( freq, ms );
   }
}

Topic archived. No new replies allowed.