Skip to content

Commit

Permalink
Fixes to timing of jp_makebeats and added Cfg.max to jp_maketone
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeelle committed Nov 25, 2015
1 parent 3bb6847 commit ad34ed5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
7 changes: 4 additions & 3 deletions jp_makebeats.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
end

pauseBetweenTones = zeros(round(Cfg.pauseBetweenTonesSec*Cfg.fs),1);
toneDurationSec = Cfg.beatLengthSec - Cfg.pauseBetweenTonesSec;
%toneDurationSec = Cfg.beatLengthSec - Cfg.pauseBetweenTonesSec;
fs = Cfg.fs;

% Initialize vector for holding things. It would be more efficient to not
Expand All @@ -68,15 +68,16 @@

toneCfg = [];
toneCfg.fs = fs;
toneCfg.max = 0.9; % tones should max at 0.9

for note=pattern
tone = jp_maketone(Cfg.toneFreq, toneDurationSec * note, toneCfg);
tone = jp_maketone(Cfg.toneFreq, (Cfg.beatLengthSec * note) - Cfg.pauseBetweenTonesSec, toneCfg);
y = [y; tone; pauseBetweenTones];
end

% If requested, add one more beat at end
if Cfg.endWithDownbeat
tone = jp_maketone(Cfg.toneFreq, toneDurationSec, toneCfg);
tone = jp_maketone(Cfg.toneFreq, Cfg.beatLengthSec, toneCfg);
y = [y; tone];
end

Expand Down
28 changes: 23 additions & 5 deletions jp_maketone.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@
Cfg.fs = 20050;
end

if ~isfield(Cfg, 'db') || isempty(Cfg.db)
Cfg.db = -25; % dB FS

if ~isfield(Cfg, 'max')
Cfg.max = [];
end


if ~isfield(Cfg, 'db') % can by empty, in which case, no db scaling
Cfg.db = []; % dB FS
end


if ~isempty(Cfg.max) && ~isempty(Cfg.db)
error('Can specify Cfg.max or Cfg.db, but not both.')
end


Expand All @@ -52,9 +63,16 @@
y = sin(freq*2*pi*t);

% Adjust the dB NB for steady state (done before ramping)
targetRMS = 10^(Cfg.db/20);
scaleFactor = targetRMS/jp_rms(y);
y = y * scaleFactor;
if ~isempty(Cfg.db)
targetRMS = 10^(Cfg.db/20);
scaleFactor = targetRMS/jp_rms(y);
y = y * scaleFactor;
else ~isempty(Cfg.max)
scaleFactor = Cfg.max/max(y);
y = y * scaleFactor;
end



% Ramp
if rampUpSamples > 0
Expand Down

0 comments on commit ad34ed5

Please sign in to comment.