FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nRF52Audio/ChainedSDWavFile.cpp at master · JakeS0ft/nRF52Audio · GitHub
JakeS0ft
/
nRF52Audio
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
11
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nRF52Audio
/
ChainedSDWavFile.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
177 lines (148 loc) · 3.76 KB
Breadcrumbs
nRF52Audio
/
ChainedSDWavFile.cpp
Copy path
File metadata and controls
177 lines (148 loc) · 3.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
*****************************************************************************
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************
*/
/*
* ChainedSDWavFile.cpp
*
* Created on: Oct 31, 2019
* Author: JakeSoft
*/
#
include
"
ChainedSDWavFile.h
"
ChainedSDWavFile::ChainedSDWavFile
(
const
char
* aFilePath,
const
char
* aNextFilePath)
{
mFileIndex
=
0
;
mpFiles[
0
] =
new
SDWavFile
(aFilePath);
mpFiles[
1
] =
new
SDWavFile
(aNextFilePath);
}
ChainedSDWavFile::~ChainedSDWavFile
()
{
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
delete
mpFiles[lIdx];
}
}
File&
ChainedSDWavFile::GetFileHandle
()
{
return
mpFiles[
mFileIndex
]->
GetFileHandle
();
}
const
tWavFileHeader&
ChainedSDWavFile::GetHeader
()
{
return
mpFiles[
mFileIndex
]->
GetHeader
();
}
const
tWavDataHeader&
ChainedSDWavFile::GetDataHeader
()
{
return
mpFiles[
mFileIndex
]->
GetDataHeader
();
}
void
ChainedSDWavFile::Close
()
{
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
mpFiles[lIdx]->
Close
();
}
}
bool
ChainedSDWavFile::SeekStartOfData
()
{
bool
lSuccess =
true
;
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
lSuccess &= mpFiles[lIdx]->
SeekStartOfData
();
}
return
lSuccess;
}
int
ChainedSDWavFile::Available
()
{
int
lAvail =
0
;
//
Return the greatest available bytes from either file
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
if
(mpFiles[lIdx]->
Available
() > lAvail)
{
lAvail = mpFiles[lIdx]->
Available
();
}
}
return
lAvail;
}
int
ChainedSDWavFile::Fetch16BitSamples
(
int16_t
* apBuffer,
int
aNumSamples)
{
int
lSamplesFetched =
0
;
static
int
lWrap =
0
;
if
(
false
== mpFiles[
0
]->
IsEnded
())
{
lSamplesFetched = mpFiles[
0
]->
Fetch16BitSamples
(apBuffer, aNumSamples);
}
if
(lSamplesFetched < aNumSamples)
{
int
lNumSamplesToFetch = aNumSamples-lSamplesFetched;
int
lBufPos =
0
;
if
(lSamplesFetched >
0
)
{
lBufPos = lSamplesFetched-
1
;
}
lSamplesFetched += mpFiles[
1
]->
Fetch16BitSamples
(&(apBuffer[lBufPos]), lNumSamplesToFetch);
}
return
lSamplesFetched;
}
void
ChainedSDWavFile::SetVolume
(
float
aVolume)
{
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
mpFiles[lIdx]->
SetVolume
(aVolume);
}
}
void
ChainedSDWavFile::SetLooping
(
bool
aLoopingEnable)
{
mpFiles[
0
]->
SetLooping
(
0
);
mpFiles[
1
]->
SetLooping
(aLoopingEnable);
}
void
ChainedSDWavFile::Pause
()
{
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
mpFiles[lIdx]->
Pause
();
}
}
bool
ChainedSDWavFile::IsPaused
()
{
return
mpFiles[
0
]->
IsPaused
();
}
void
ChainedSDWavFile::UnPause
()
{
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
mpFiles[lIdx]->
UnPause
();
}
}
bool
ChainedSDWavFile::IsEnded
()
{
bool
lEnded =
true
;
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
if
(
false
== mpFiles[lIdx]->
IsEnded
())
{
lEnded =
false
;
}
}
return
lEnded;
}
void
ChainedSDWavFile::SetDePop
(
bool
aStart,
bool
aEnd)
{
for
(
int
lIdx =
0
; lIdx <
NUM_CHAINED_FILES
; lIdx++)
{
mpFiles[lIdx]->
SetDePop
(aStart, aEnd);
}
}
void
ChainedSDWavFile::Skip16BitSamples
(
int
aNumSamples)
{
mpFiles[
mFileIndex
]->
Skip16BitSamples
(aNumSamples);
}
Back
|
FazBrowse Home
|
New Git URL