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
5303930f
Commit
5303930f
authored
11 years ago
by
jsiegle
Browse files
Options
Downloads
Patches
Plain Diff
Add source code for FileReader
parent
273a617b
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.cpp
+201
-0
201 additions, 0 deletions
Source/Processors/FileReader.cpp
Source/Processors/FileReader.h
+98
-0
98 additions, 0 deletions
Source/Processors/FileReader.h
with
299 additions
and
0 deletions
Source/Processors/FileReader.cpp
0 → 100644
+
201
−
0
View file @
5303930f
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2013 Open Ephys
------------------------------------------------------------------
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/>.
*/
#include
"FileReader.h"
#include
"Editors/FileReaderEditor.h"
#include
<stdio.h>
FileReader
::
FileReader
()
:
GenericProcessor
(
"File Reader"
)
{
input
=
0
;
timestamp
=
0
;
enabledState
(
false
);
}
FileReader
::~
FileReader
()
{
if
(
input
)
fclose
(
input
);
}
AudioProcessorEditor
*
FileReader
::
createEditor
()
{
editor
=
new
FileReaderEditor
(
this
,
true
);
return
editor
;
}
float
FileReader
::
getDefaultSampleRate
()
{
return
40000.0
f
;
}
int
FileReader
::
getDefaultNumOutputs
()
{
return
16
;
}
float
FileReader
::
getDefaultBitVolts
()
{
return
0.0305
f
;
}
void
FileReader
::
enabledState
(
bool
t
)
{
isEnabled
=
t
;
}
void
FileReader
::
setFile
(
String
fullpath
)
{
filePath
=
fullpath
;
const
char
*
path
=
filePath
.
getCharPointer
();
if
(
input
)
fclose
(
input
);
input
=
fopen
(
path
,
"r"
);
// Avoid a segfault if file isn't found
if
(
!
input
)
{
std
::
cout
<<
"Can't find data file "
<<
'"'
<<
path
<<
"
\"
"
<<
std
::
endl
;
return
;
}
fseek
(
input
,
0
,
SEEK_END
);
lengthOfInputFile
=
ftell
(
input
);
rewind
(
input
);
}
String
FileReader
::
getFile
()
{
return
filePath
;
}
void
FileReader
::
updateSettings
()
{
}
void
FileReader
::
process
(
AudioSampleBuffer
&
buffer
,
MidiBuffer
&
events
,
int
&
nSamples
)
{
uint8
data
[
8
];
memcpy
(
data
,
&
timestamp
,
8
);
// generate timestamp
addEvent
(
events
,
// MidiBuffer
TIMESTAMP
,
// eventType
0
,
// sampleNum
nodeId
,
// eventID
0
,
// eventChannel
8
,
// numBytes
data
// data
);
// FIXME: needs to account for the fact that the ratio might not be an exact
// integer value
int
samplesNeeded
=
(
int
)
float
(
buffer
.
getNumSamples
())
*
(
getDefaultSampleRate
()
/
44100.0
f
);
if
(
ftell
(
input
)
>=
lengthOfInputFile
-
samplesNeeded
)
{
rewind
(
input
);
}
size_t
numRead
=
fread
(
readBuffer
,
2
,
samplesNeeded
*
buffer
.
getNumChannels
(),
input
);
int
chan
=
0
;
int
samp
=
0
;
for
(
size_t
n
=
0
;
n
<
numRead
;
n
++
)
{
if
(
chan
==
buffer
.
getNumChannels
())
{
samp
++
;
timestamp
++
;
chan
=
0
;
}
*
buffer
.
getSampleData
(
chan
++
,
samp
)
=
float
(
-
readBuffer
[
n
])
*
getDefaultBitVolts
();
// previously 0.035
}
nSamples
=
samplesNeeded
;
}
void
FileReader
::
setParameter
(
int
parameterIndex
,
float
newValue
)
{
}
void
FileReader
::
saveCustomParametersToXml
(
XmlElement
*
parentElement
)
{
XmlElement
*
childNode
=
parentElement
->
createNewChildElement
(
"FILENAME"
);
childNode
->
setAttribute
(
"path"
,
getFile
());
}
void
FileReader
::
loadCustomParametersFromXml
()
{
if
(
parametersAsXml
!=
nullptr
)
{
// use parametersAsXml to restore state
forEachXmlChildElement
(
*
parametersAsXml
,
xmlNode
)
{
if
(
xmlNode
->
hasTagName
(
"FILENAME"
))
{
String
filepath
=
xmlNode
->
getStringAttribute
(
"path"
);
FileReaderEditor
*
fre
=
(
FileReaderEditor
*
)
getEditor
();
fre
->
setFile
(
filepath
);
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Source/Processors/FileReader.h
0 → 100644
+
98
−
0
View file @
5303930f
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2013 Open Ephys
------------------------------------------------------------------
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/>.
*/
#ifndef __FILEREADER_H_B327D3D2__
#define __FILEREADER_H_B327D3D2__
#include
"../../JuceLibraryCode/JuceHeader.h"
#include
"GenericProcessor.h"
#define BUFFER_SIZE 102400
/**
Reads data from a file.
@see GenericProcessor
*/
class
FileReader
:
public
GenericProcessor
{
public:
FileReader
();
~
FileReader
();
void
process
(
AudioSampleBuffer
&
buffer
,
MidiBuffer
&
midiMessages
,
int
&
nSamples
);
void
setParameter
(
int
parameterIndex
,
float
newValue
);
AudioProcessorEditor
*
createEditor
();
bool
hasEditor
()
const
{
return
true
;
}
void
updateSettings
();
bool
isSource
()
{
return
true
;
}
void
enabledState
(
bool
t
);
float
getDefaultSampleRate
();
int
getDefaultNumOutputs
();
float
getDefaultBitVolts
();
void
setFile
(
String
fullpath
);
String
getFile
();
void
saveCustomParametersToXml
(
XmlElement
*
parentElement
);
void
loadCustomParametersFromXml
();
private
:
uint64
timestamp
;
int
lengthOfInputFile
;
FILE
*
input
;
int16
readBuffer
[
BUFFER_SIZE
];
int
bufferSize
;
String
filePath
;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR
(
FileReader
);
};
#endif // __FILEREADER_H_B327D3D2__
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