forked from bitdog-io/restraining_bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioPlayer.cpp
More file actions
75 lines (51 loc) · 1.21 KB
/
Copy pathAudioPlayer.cpp
File metadata and controls
75 lines (51 loc) · 1.21 KB
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
//
//
//
#include "AudioPlayer.h"
AudioPlayer::AudioPlayer()
{
_patchCord = new AudioConnection( _playSdWav1, 0, _mixer1, 0 );
_patchCord2 = new AudioConnection( _playSdWav1, 1, _mixer1, 3 );
_patchCord3 = new AudioConnection( _mixer1, 0, _mqs1, 0 );
_patchCord4 = new AudioConnection( _mixer1, 0, _mqs1, 1 );
}
AudioPlayer::~AudioPlayer()
{
delete _patchCord;
delete _patchCord2;
delete _patchCord3;
delete _patchCord4;
}
void AudioPlayer::play( const char* filepath )
{
int position = _playQueue.size();
if ( position < FILE_QUEUE_SIZE )
{
Log.trace( "scheduling sound file for playback: %s", filepath );
_playQueue.enqueue( filepath );
}
}
void AudioPlayer::tick()
{
if ( (!_playSdWav1.isPlaying()) && _playQueue.size() > 0 )
{
const char* filepath = _playQueue.dequeue();
if ( filepath != nullptr )
{
//
if ( !_playSdWav1.play( filepath ) )
{
Log.trace( "Could not play sound file: %s", filepath );
}
else
{
delay( 1000 );
while ( _playSdWav1.isPlaying() )
{
// stop processing to allow the sound to play. Unfortunately haven't found a way to allow the audio interrupts to work without it.
delay( 1000 );
}
}
}
}
}