aboutsummaryrefslogtreecommitdiff
path: root/stm32/inc/sfx.h
blob: 97450186425e1aa9fcfd084bd77ba518c779fb01 (plain)
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
#ifndef _SFX_H
#define _SFX_H
/*!
 * Sound effect player library.
 *
 * This implements a state machine for playing back various monophonic
 * sound effects such as morse code symbols, clicks and alert tones.
 *
 * Author Stuart Longland <[email protected]>
 * Copyright (C) 2015 FreeDV project.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 2.1,
 * as published by the Free Software Foundation.  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 Lesser General Public
 * License along with this program; if not, see
 * <http://www.gnu.org/licenses/>.
 */

#include "tone.h"

/*!
 * A sound effect "note"
 */
struct sfx_note_t {
	/*! Note frequency.  0 == pause */
	uint16_t	freq;
	/*! Note duration in msec.   0 == end of effect */
	uint16_t	duration;
};

/*!
 * Sound effect player state machine
 */
struct sfx_player_t {
	/*!
	 * Pointer to the current "note".  When this is NULL,
	 * playback is complete.
	 */
	const struct sfx_note_t*	note;
	/*! Tone generator state machine */
	struct tone_gen_t		tone_gen;
};

/*!
 * Start playing a particular effect.
 * @param	sfx_player	Effect player state machine
 * @param	effect		Pointer to sound effect (NULL == stop)
 */
void sfx_play(struct sfx_player_t* const sfx_player,
		const struct sfx_note_t* effect);

/*!
 * Retrieve the next sample to be played.
 */
int16_t sfx_next(struct sfx_player_t* const sfx_player);

#endif