LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
Macros | Functions | Variables
sound.c File Reference

Sound and music functions. More...

Include dependency graph for sound.c:

Macros

#define eigth   (sixteenth*2)
 
#define half   (quarter*2)
 
#define quarter   (eigth*2)
 
#define sixteenth   8
 
#define whole   (half*2)
 

Functions

void PlayNote (uint8_t note, uint8_t duration)
 Plays a single note. More...
 
void PlaySequence (uint8_t *seq)
 Plays a sequence of notes. More...
 
void PlayTone (uint16_t tone, uint8_t duration)
 Plays a single tone. More...
 
void SndToneOff ()
 Stops playing a tone. More...
 
void SndToneOn (uint16_t tone)
 Starts playing a tone. More...
 

Variables

static const uint8_t midiOffset =57
 The first note in notes[] is midi-code 57. More...
 
uint8_t * musicPtr
 Is used in the timer callback to play sequences. More...
 
static const uint16_t notes [] PROGMEM
 
uint8_t sndBigBenSeq []
 Big Ben Tone sequence. More...
 
uint8_t sndErrorSeq [] ={57,20,0,0}
 Tone sequence for error messages. More...
 
uint8_t sndSeqPlaying
 Is !=0 while a sequence is playing. More...
 
uint8_t sndSig1 []
 Sequence for alert output 1. More...
 
uint8_t sndSig2 []
 Sequence for alert output 2. More...
 
uint8_t sndSuccessSeq [] ={80,5,0,10,92,5,0,0}
 Tone sequence for success. More...
 
uint8_t sndToneCnt
 Down-counter for tone duration. Can be tested to 0 to wait for end of tone. More...
 

Detailed Description

Sound and music functions.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

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. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Playing sounds and music is done using timer interrupts. So the functions are non-blocking.

Macro Definition Documentation

◆ eigth

#define eigth   (sixteenth*2)

◆ half

#define half   (quarter*2)

◆ quarter

#define quarter   (eigth*2)

◆ sixteenth

#define sixteenth   8

◆ whole

#define whole   (half*2)

Function Documentation

◆ PlayNote()

void PlayNote ( uint8_t  note,
uint8_t  duration 
)

Plays a single note.

Parameters
noteThe note as a midi value (e.g. A4 (440Hz) = 69)
durationLength in multiple of 10ms

The note value "0" can be used to play silence. Notes from 57 to 117 can be used. Other values produce undefined tones.

References midiOffset, and PlayTone().

Referenced by PlaySequence(), and SndTimerCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PlaySequence()

void PlaySequence ( uint8_t *  seq)

Plays a sequence of notes.

Parameters
seqa pointer to the note data

The data format is one byte note and one byte duration. The data has to be terminated with 0x00 0x00

References musicPtr, and PlayNote().

Referenced by DoTflags(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PlayTone()

void PlayTone ( uint16_t  tone,
uint8_t  duration 
)

Plays a single tone.

Parameters
toneThe value of the timer period register (OCR3A)
durationLength in multiple of 10ms

The frequency of the tone is 3.6864MHz/(tone+1) A tone value 0 plays silence for the given duration

References sndToneCnt, SndToneOff(), and SndToneOn().

Referenced by PlayNote().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SndToneOff()

void SndToneOff ( void  )
inline

Stops playing a tone.

Referenced by PlayTone(), and SndTimerCallback().

Here is the caller graph for this function:

◆ SndToneOn()

void SndToneOn ( uint16_t  tone)
inline

Starts playing a tone.

Parameters
toneThe value of the timer period register (OCR3A)

The frequency of the tone is 3.6864MHz/(tone+1)

Referenced by PlayTone().

Here is the caller graph for this function:

Variable Documentation

◆ midiOffset

const uint8_t midiOffset =57
static

The first note in notes[] is midi-code 57.

Referenced by PlayNote().

◆ musicPtr

uint8_t* musicPtr

Is used in the timer callback to play sequences.

Referenced by InitSound(), PlaySequence(), and SndTimerCallback().

◆ PROGMEM

const uint16_t notes [] PROGMEM
static
Initial value:
={
8378, 7908, 7464, 7045, 6650, 6277, 5924, 5592, 5278, 4982, 4702, 4438,
4189, 3954, 3732, 3523, 3325, 3138, 2962, 2796, 2639, 2491, 2351, 2219,
2095, 1977, 1866, 1761, 1662, 1569, 1481, 1398, 1319, 1245, 1176, 1110,
1047, 988, 933, 881, 831, 785, 741, 699, 660, 623, 588, 555,
524, 494, 467, 440, 416, 392, 370, 349, 330, 311, 294, 277,
262, 247, 233, 220, 208, 196, 185, 175, 165, 156, 147, 139
}

◆ sndBigBenSeq

uint8_t sndBigBenSeq[]
Initial value:
=
{
0,0
}
#define quarter
Definition: sound.c:116
#define half
Definition: sound.c:117

Big Ben Tone sequence.

Referenced by DoTflags().

◆ sndErrorSeq

uint8_t sndErrorSeq[] ={57,20,0,0}

Tone sequence for error messages.

◆ sndSeqPlaying

uint8_t sndSeqPlaying

Is !=0 while a sequence is playing.

Referenced by InitSound().

◆ sndSig1

uint8_t sndSig1[]
Initial value:
=
{
}
#define sixteenth
Definition: sound.c:114
#define half
Definition: sound.c:117

Sequence for alert output 1.

Referenced by DoTflags().

◆ sndSig2

uint8_t sndSig2[]
Initial value:
=
{
81,sixteenth,76,sixteenth,0,0
}
#define sixteenth
Definition: sound.c:114

Sequence for alert output 2.

Referenced by DoTflags().

◆ sndSuccessSeq

uint8_t sndSuccessSeq[] ={80,5,0,10,92,5,0,0}

Tone sequence for success.

Referenced by main().

◆ sndToneCnt

uint8_t sndToneCnt

Down-counter for tone duration. Can be tested to 0 to wait for end of tone.

Referenced by InitSound(), PlayTone(), and SndTimerCallback().