Creating background Sound?

It has been a while since I played around with C++, I get bored, then I eventually get back into it. I am still a noob and a horrible coder so if their is anything pointless that I am initializing in my coding please tell me. Anyways this might be a dumb question and the answer is probably simpler than I thought, but I can not seem to figure out how to create sound while the colored screen has been implemented. Have you ever noticed that colored screen on your television when you sometimes flip the channel? Well, it looks like a rainbow, after looking at that rainbow colored screen, I just felt like making it. Although I can create the sound but only when the sound is finished then the color screen gets displayed. After playing around with it, it seem pretty neat to initialize the sound in the for-loop inside the int main(), it made the colors display at a slow pace after each sound was finished. The point is, I just want the sound to play while the colored screen is displayed fully.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <Windows.h>
#include <iostream>
#include <string>

HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);

signed int holdUp();

#ifdef max
#undef max
#endif

class Hypnosis {
private:
	int white; 
	int yellow; 
        int lightBlue; 
	int green; 
	int purple; 
	int red; 
	int blue;
	int black;

public:
	void beep() {
		Beep(2500, 5000); //I know how to extend longer sound.
		Sleep(200);
	}

	Hypnosis(int a=255, int b=239, int c=187, int d=170, int e=221, int f=204, int g=153, int h=0) {
		white=a;
		yellow=b;
		lightBlue=c;
		green=d;
		purple=e;
		red=f;
		blue=g;
		black=h;
	}

	void colors() {
		std::string width = ("          "); //10 blank spaces
		
		for (int color(white); color==white; color++) {
			SetConsoleTextAttribute(h, color);
			std::cout<<(width);
			
			for (int color(yellow); color==yellow; color++) {
				SetConsoleTextAttribute(h, color);
				std::cout<<(width);

			    for (int color(lightBlue); color==lightBlue; color++) {
				    SetConsoleTextAttribute(h, color);
				    std::cout<<(width);

				    for (int color(green); color==green; color++) {
					    SetConsoleTextAttribute(h, color);
					    std::cout<<(width);

					    for (int color(purple); color==purple; color++) {
						    SetConsoleTextAttribute(h, color);
						    std::cout<<(width);

						    for (int color(red); color==red; color++) {
							    SetConsoleTextAttribute(h, color);
							    std::cout<<(width);

							    for (int color(blue); color==blue; color++) {
								    SetConsoleTextAttribute(h, color);
								    std::cout<<(width);

								    for (int color(black); color==black; color++) {
									    SetConsoleTextAttribute(h, color);
									    std::cout<<(width);
									}
								}
							}
						}
					}
				}
			}
		}
	}
};

int main() {
	Hypnosis turnOn;
	
	turnOn.beep(); 

	for (float extendLength(112.05); extendLength<=0xFF; extendLength++) {
		//turnOn.beep(); 
		turnOn.colors();
	}

	holdUp();return 0;
}

signed int holdUp() {
	std::cin.sync(), 
		std::cin.ignore(std::numeric_limits<std::streamsize>::max()); 
	return(0);
}

Last edited on
I displayed turnOn.beep(); after the for-loop inside the int main() LOL
I guess that was a better way that works for me, unless their is another way too implement the sound while the colored screen is being displayed.

1
2
3
4
5
6
7
8
9
10
11
12
13
int main() {
	Hypnosis turnOn;


	for (float extendLength(112.05); extendLength<=0xFF; extendLength++) { 

		turnOn.colors();
	}

        turnOn.beep();

	holdUp();return 0;
}
Last edited on
Topic archived. No new replies allowed.