The ZX Ecosystem v5.1.0;_GUI_v3.1.0
Loading...
Searching...
No Matches
ZXSound.h
Go to the documentation of this file.
1
2/* *************************************************************************/
24#ifndef ZXSOUND
25#define ZXSOUND
26
27
28namespace zxeco
29{
30
31/* ****************************************************************************
32*
33* Class: Frequency
34*
35*******************************************************************************/
36
39{
40 public:
41
42 /* ---------------------- Types, consts, etc. ----------------- */
43
45 enum Note:unsigned char { NOTE_C = 0,
57 NUMNOTES
58 };
59
61 static constexpr unsigned char NUMSEMITONESINOCTAVE = NUMNOTES;
62
64
66 static const double FREQNOTES[NUMNOTES];
67
68 /* ---------------------- Constructors ------------------------ */
69
70 Frequency(double hz);
72
76
77 /* ---------------------- Methods ------------------------ */
78
79 double freqHz(void) const noexcept { return(hz_); }
81
82 Frequency operator++(int) noexcept;
84
85 Frequency & operator+=(unsigned nos) noexcept;
87
88 private:
89
90 double hz_;
91};
92
93
94/* ****************************************************************************
95*
96* Class: Beep
97*
98*******************************************************************************/
99
101class Beep
102{
103 public:
104
105 /* ---------------------- Constructors ------------------------ */
106
107 Beep(unsigned char clic = 0);
109
119 Beep(double dur, Frequency::Note note);
121
123 Beep(double dur, double pitch);
125
131 Beep(double dur, Frequency freq, double phase=0.0);
133
138 /* ---------------------- Methods ------------------------ */
139
140 double duration(void) const noexcept { return(dur_); }
142
143 Frequency frequency(void) const noexcept { return(freq_); }
145
146 double phase(void) const noexcept { return(ph_); }
148
149 private:
150
151 double dur_;
152 Frequency freq_;
153 double ph_;
154};
155
156
157} // end namespace zxeco
158
159#endif
160 // ZXSound
162
Frequency(Note n)
Constructor from a note. Exception if N is not within one octave.
static constexpr unsigned char NUMSEMITONESINOCTAVE
Number of semi-tones in one octave.
Definition: ZXSound.h:61
static const double FREQNOTES[NUMNOTES]
Frequencies of the notes of the standard octave in Hz.
Definition: ZXSound.h:66
Frequency(double hz)
Constructor from a frequency in Hz.
double duration(void) const noexcept
Return the duration in seconds of the Beep.
Definition: ZXSound.h:140
Frequency operator++(int) noexcept
(Only postfix operator) Increment one octave this frequency.
Frequency & operator+=(unsigned nos) noexcept
Increment this frequency in NOS octaves.
Beep(double dur, Frequency freq, double phase=0.0)
Constructor of an arbitrary square wave.
Beep(unsigned char clic=0)
Default constructor: the beep corresponding to the zx keyboard clic.
Beep(double dur, Frequency::Note note)
Constructor of a beep of DUR seconds and NOTE note.
Note
Musical notes in one octave.
Definition: ZXSound.h:45
double freqHz(void) const noexcept
Return the frequency in Hz.
Definition: ZXSound.h:79
double phase(void) const noexcept
Return the phase in seconds of the wave.
Definition: ZXSound.h:146
Beep(double dur, double pitch)
Constructor from a ZX-BASIC beep command.
Frequency frequency(void) const noexcept
Return the frequency in Hz of the Beep.
Definition: ZXSound.h:143
A zx beep sound.
Definition: ZXSound.h:102
The frequency of a square-wave sound.
Definition: ZXSound.h:39
The main namespace of the library, that spans across all the zx modules.
Definition: ZXChars.h:31