Skip to content

Commit 70ee85b

Browse files
committed
Fixed sub-millisecond duration truncation when using stim.getData()
1 parent 71df496 commit 70ee85b

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
11
classdef DirectCurrentGenerator < symphonyui.core.StimulusGenerator
22
% Generates a constant, zero-frequency, direct current stimulus.
3-
3+
44
properties
55
time % Duration (s)
66
offset % Mean value (units)
77
sampleRate % Sample rate of generated stimulus (Hz)
88
units % Units of generated stimulus
99
end
10-
10+
1111
methods
12-
12+
1313
function obj = DirectCurrentGenerator(map)
1414
if nargin < 1
1515
map = containers.Map();
1616
end
1717
1818
end
19-
19+
2020
end
21-
21+
2222
methods (Access = protected)
23-
23+
2424
function s = generateStimulus(obj)
2525
import Symphony.Core.*;
26-
26+
2727
timeToPts = @(t)(round(t * obj.sampleRate));
28-
28+
2929
pts = timeToPts(obj.time);
30-
30+
3131
% Allows the RenderedStimulus to determine the BaseUnits of the output when the duration is zero. The
3232
% duration (span) is being explicitly declared below so a zero duration stimulus will truely be of duration
3333
% zero even though it has one data point.
3434
pts = max(pts, 1);
35-
35+
3636
data = ones(1, pts) * obj.offset;
37-
37+
3838
parameters = obj.dictionaryFromMap(obj.propertyMap);
3939
measurements = Measurement.FromArray(data, obj.units);
4040
rate = Measurement(obj.sampleRate, 'Hz');
4141
output = OutputData(measurements, rate);
42-
span = TimeSpanOption(System.TimeSpan.FromSeconds(obj.time));
43-
42+
span = TimeSpanOption(System.TimeSpan.FromTicks(obj.time * 1e7));
43+
4444
cobj = RenderedStimulus(class(obj), parameters, output, span);
4545
s = symphonyui.core.Stimulus(cobj);
4646
end
47-
47+
4848
end
49-
50-
end
5149

50+
end

src/main/matlab/+symphonyui/+core/CoreObject.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function tryCore(obj, call) %#ok<INUSL>
150150
end
151151

152152
function t = timeSpanFromDuration(obj, d) %#ok<INUSL>
153-
t = System.TimeSpan.FromSeconds(seconds(d));
153+
t = System.TimeSpan.FromTicks(milliseconds(d) * 10000);
154154
end
155155

156156
function v = propertyValueFromValue(obj, v) %#ok<INUSL>

src/test/matlab/+symphonyui/+builtin/+stimuli/RepeatingPulseGeneratorTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
function methodSetup(obj)
1010
gen = symphonyui.builtin.stimuli.RepeatingPulseGenerator();
1111
gen.preTime = 50;
12-
gen.stimTime = 430.2;
12+
gen.stimTime = 430;
1313
gen.tailTime = 70;
1414
gen.amplitude = 100;
1515
gen.mean = -60;

0 commit comments

Comments
 (0)