The ZX Ecosystem v4.3.0;_GUI_v3.0.0
Loading...
Searching...
No Matches
Namespaces | Classes
The ZX Sound

Description

Provides the ZX sound behavior.

NOTE:

-These classes are not thread-safe.

http://jafma.net

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Collaboration diagram for The ZX Sound:

Namespaces

namespace  zxeco
 The main namespace of the library, that spans across all the zx modules.
 

Classes

class  zxeco::Frequency
 The frequency of a square-wave sound. More...
 
class  zxeco::Beep
 A zx beep sound. More...
 

Class Documentation

◆ zxeco::Frequency

class zxeco::Frequency

The frequency of a square-wave sound.

Definition at line 38 of file ZXSound.h.

Public Types

enum  Note : unsigned char {
  NOTE_C = 0 , NOTE_CS , NOTE_D , NOTE_DS ,
  NOTE_E , NOTE_F , NOTE_FS , NOTE_G ,
  NOTE_GS , NOTE_A , NOTE_AS , NOTE_B ,
  NUMNOTES
}
 Musical notes in one octave. More...
 

Static Public Attributes

static constexpr unsigned char NUMSEMITONESINOCTAVE = NUMNOTES
 Number of semi-tones in one octave. More...
 
static const double FREQNOTES [NUMNOTES]
 Frequencies of the notes of the standard octave in Hz. More...
 

Public Member Functions

 Frequency (double hz)
 Constructor from a frequency in Hz. More...
 
 Frequency (Note n)
 Constructor from a note. Exception if N is not within one octave.
 
double freqHz (void) const noexcept
 Return the frequency in Hz. More...
 
Frequency operator++ (int) noexcept
 (Only postfix operator) Increment one octave this frequency.
 
Frequencyoperator+= (unsigned nos) noexcept
 Increment this frequency in NOS octaves.
 

Member Enumeration Documentation

◆ Note

enum zxeco::Frequency::Note : unsigned char

Musical notes in one octave.

Enumerator
NOTE_C 

C.

NOTE_CS 

C#.

NOTE_D 

D.

NOTE_DS 

D#.

NOTE_E 

E.

NOTE_F 

F.

NOTE_FS 

F#.

NOTE_G 

G.

NOTE_GS 

G#.

NOTE_A 

A.

NOTE_AS 

A#.

NOTE_B 

B.

Definition at line 45 of file ZXSound.h.

Constructor & Destructor Documentation

◆ Frequency()

zxeco::Frequency::Frequency ( double  hz)

Constructor from a frequency in Hz.

Exception if HZ < 0.0. If HZ == 0.0 it is a silent sound.

Member Function Documentation

◆ freqHz()

double zxeco::Frequency::freqHz ( void  ) const
inlinenoexcept

Return the frequency in Hz.

Definition at line 79 of file ZXSound.h.

Member Data Documentation

◆ NUMSEMITONESINOCTAVE

constexpr unsigned char zxeco::Frequency::NUMSEMITONESINOCTAVE = NUMNOTES
staticconstexpr

Number of semi-tones in one octave.

Definition at line 61 of file ZXSound.h.

◆ FREQNOTES

const double zxeco::Frequency::FREQNOTES[NUMNOTES]
static

Frequencies of the notes of the standard octave in Hz.

Differences in frequency between consecutive notes are not equal. Higher octaves are obtained by multiplying the C frequency by 2, 3, etc.

Definition at line 66 of file ZXSound.h.

◆ zxeco::Beep

class zxeco::Beep

A zx beep sound.

Definition at line 101 of file ZXSound.h.

Public Member Functions

 Beep (unsigned char clic=0)
 Default constructor: the beep corresponding to the zx keyboard clic. More...
 
 Beep (double dur, Frequency::Note note)
 Constructor of a beep of DUR seconds and NOTE note. More...
 
 Beep (double dur, double pitch)
 Constructor from a ZX-BASIC beep command. More...
 
 Beep (double dur, Frequency freq, double phase=0.0)
 Constructor of an arbitrary square wave. More...
 
double duration (void) const noexcept
 Return the duration in seconds of the Beep. More...
 
Frequency frequency (void) const noexcept
 Return the frequency in Hz of the Beep. More...
 
double phase (void) const noexcept
 Return the phase in seconds of the wave. More...
 

Constructor & Destructor Documentation

◆ Beep() [1/4]

zxeco::Beep::Beep ( unsigned char  clic = 0)

Default constructor: the beep corresponding to the zx keyboard clic.

The zx clic was configurable by a single value (here the argument CLIC) ranging from 0 (default) to 255, that was stored in the system variable PIP (at 23609 in decimal). The frequency of the clic was always the same, independently on the value of CLIC: 1.861286956523912e+03 Hz (1861.3 Hz). CLIC defines the duration of the clic: from exactly one period of that wave (if CLIC==0) to 256 periods of the wave (if CLIC==255), i.e., CLIC is the number of periods of the wave to play minus one. Therefore the maximum duration (CLIC==255) is 0.137539243534 seconds, while the minimum (CLIC==0) is about 53.73 millis.

◆ Beep() [2/4]

zxeco::Beep::Beep ( double  dur,
Frequency::Note  note 
)

Constructor of a beep of DUR seconds and NOTE note.

Exception if the note is outside one octave or if DUR <= 0.0.

◆ Beep() [3/4]

zxeco::Beep::Beep ( double  dur,
double  pitch 
)

Constructor from a ZX-BASIC beep command.

DUR is the duration in seconds. PITCH is the number of semitones above or below the middle C (the one labelled as N_C in the Frequency class). Exception if the frequency corresponding to PITCH is out of the range a human may hear (0Hz- 20000Hz), or if DUR <= 0.

◆ Beep() [4/4]

zxeco::Beep::Beep ( double  dur,
Frequency  freq,
double  phase = 0.0 
)

Constructor of an arbitrary square wave.

The wave will have a duration of DUR seconds, a frequency FREQ and a phase (start time) of PHASE seconds. DUR may span for an exact number of cycles or not. Exception if DUR<=0.0 or PHASE<0.0.

Member Function Documentation

◆ duration()

double zxeco::Beep::duration ( void  ) const
inlinenoexcept

Return the duration in seconds of the Beep.

Definition at line 140 of file ZXSound.h.

◆ frequency()

Frequency zxeco::Beep::frequency ( void  ) const
inlinenoexcept

Return the frequency in Hz of the Beep.

Definition at line 143 of file ZXSound.h.

◆ phase()

double zxeco::Beep::phase ( void  ) const
inlinenoexcept

Return the phase in seconds of the wave.

Definition at line 146 of file ZXSound.h.