Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
plugin-GUI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
yehaojie
plugin-GUI
Commits
611cca0a
Commit
611cca0a
authored
7 years ago
by
kmichaelfox
Browse files
Options
Downloads
Patches
Plain Diff
add a cached file reading buffer to decrease number of file accesses
parent
db64af02
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Source/Processors/FileReader/FileReader.cpp
+12
-7
12 additions, 7 deletions
Source/Processors/FileReader/FileReader.cpp
Source/Processors/FileReader/FileReader.h
+2
-0
2 additions, 0 deletions
Source/Processors/FileReader/FileReader.h
with
14 additions
and
7 deletions
Source/Processors/FileReader/FileReader.cpp
+
12
−
7
View file @
611cca0a
...
...
@@ -195,6 +195,7 @@ void FileReader::setActiveRecording (int index)
currentSample
=
0
;
startSample
=
0
;
stopSample
=
currentNumSamples
;
bufferCacheWindow
=
0
;
for
(
int
i
=
0
;
i
<
currentNumChannels
;
++
i
)
{
...
...
@@ -203,7 +204,7 @@ void FileReader::setActiveRecording (int index)
static_cast
<
FileReaderEditor
*>
(
getEditor
())
->
setTotalTime
(
samplesToMilliseconds
(
currentNumSamples
));
readBuffer
.
malloc
(
currentNumChannels
*
BUFFER_SIZE
);
readBuffer
.
malloc
(
currentNumChannels
*
BUFFER_SIZE
*
BUFFER_WINDOW_CACHE_SIZE
);
}
...
...
@@ -232,16 +233,18 @@ void FileReader::process (AudioSampleBuffer& buffer)
{
const
int
samplesNeeded
=
int
(
float
(
buffer
.
getNumSamples
())
*
(
getDefaultSampleRate
()
/
44100.0
f
));
const
int
samplesNeededPerBuffer
=
int
(
float
(
buffer
.
getNumSamples
())
*
(
getDefaultSampleRate
()
/
44100.0
f
));
// const int samplesNeeded = int (float (buffer.getNumSamples()) * (getDefaultSampleRate() / 44100.0f));
const
int
samplesNeeded
=
samplesNeededPerBuffer
*
BUFFER_WINDOW_CACHE_SIZE
;
// FIXME: needs to account for the fact that the ratio might not be an exact
// integer value
int
samplesRead
=
0
;
while
(
samplesRead
<
samplesNeeded
)
while
(
bufferCacheWindow
==
0
&&
samplesRead
<
samplesNeeded
)
// only read every 5th window
{
int
samplesToRead
=
samplesNeeded
-
samplesRead
;
if
(
(
currentSample
+
samplesToRead
)
>
stopSample
)
if
(
(
currentSample
+
samplesToRead
)
>
stopSample
)
// if there are enough samples for full buffer
{
samplesToRead
=
stopSample
-
currentSample
;
if
(
samplesToRead
>
0
)
...
...
@@ -250,7 +253,7 @@ void FileReader::process (AudioSampleBuffer& buffer)
input
->
seekTo
(
startSample
);
currentSample
=
startSample
;
}
else
else
// if there aren't enough samples for full buffer
{
input
->
readData
(
readBuffer
+
samplesRead
*
currentNumChannels
,
samplesToRead
);
...
...
@@ -262,12 +265,14 @@ void FileReader::process (AudioSampleBuffer& buffer)
for
(
int
i
=
0
;
i
<
currentNumChannels
;
++
i
)
{
input
->
processChannelData
(
readBuffer
,
buffer
.
getWritePointer
(
i
,
0
),
i
,
samplesNeeded
);
input
->
processChannelData
(
readBuffer
+
samplesRead
*
currentNumChannels
*
bufferCacheWindow
,
buffer
.
getWritePointer
(
i
,
0
),
i
,
samplesNeeded
PerBuffer
);
}
timestamp
+=
samplesNeeded
;
setTimestampAndSamples
(
timestamp
,
samplesNeeded
);
setTimestampAndSamples
(
timestamp
,
samplesNeeded
PerBuffer
);
bufferCacheWindow
+=
1
;
bufferCacheWindow
%=
BUFFER_WINDOW_CACHE_SIZE
;
}
...
...
This diff is collapsed.
Click to expand it.
Source/Processors/FileReader/FileReader.h
+
2
−
0
View file @
611cca0a
...
...
@@ -32,6 +32,7 @@
#include
"FileSource.h"
#define BUFFER_SIZE 1024
#define BUFFER_WINDOW_CACHE_SIZE 5
/**
...
...
@@ -83,6 +84,7 @@ private:
int64
currentNumSamples
;
int64
startSample
;
int64
stopSample
;
int64
bufferCacheWindow
;
Array
<
RecordedChannelInfo
>
channelInfo
;
// for testing purposes only
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment