Skip to content

Commit

Permalink
Fixed the BPM to be more precise!
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnesky committed Nov 29, 2020
1 parent 8e90191 commit 46a2f1a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion editor/EditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {DictionaryArray, BeepBoxOption, InstrumentType, toNameMap} from "../synt
}

export class EditorConfig {
public static readonly version: string = "3.0.11";
public static readonly version: string = "3.0.12";

public static readonly versionDisplayName: string = "BeepBox " + EditorConfig.version;
public static readonly presetCategories: DictionaryArray<PresetCategory> = toNameMap([
Expand Down
2 changes: 1 addition & 1 deletion editor/ExportPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ import {MidiChunkType, MidiFileFormat, MidiControlEventMessage, MidiEventType, M
synth.nextBar();
}
}
const sampleFrames: number = synth.getSamplesPerBar() * synth.getTotalBars(this._enableIntro.checked, this._enableOutro.checked);
const sampleFrames: number = Math.ceil(synth.getSamplesPerBar() * synth.getTotalBars(this._enableIntro.checked, this._enableOutro.checked));
const recordedSamplesL: Float32Array = new Float32Array(sampleFrames);
const recordedSamplesR: Float32Array = new Float32Array(sampleFrames);
//const timer: number = performance.now();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BeepBox",
"version": "3.0.11",
"version": "3.0.12",
"description": "BeepBox is an online tool for sketching and sharing instrumental melodies.",
"author": "John Nesky",
"license": "MIT",
Expand Down
19 changes: 8 additions & 11 deletions synth/synth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ declare global {
this.tick = Math.floor(remainder);
const samplesPerTick: number = this.getSamplesPerTick();
remainder = samplesPerTick * (remainder - this.tick);
this.tickSampleCountdown = Math.floor(samplesPerTick - remainder);
this.tickSampleCountdown = samplesPerTick - remainder;
}
}

Expand Down Expand Up @@ -2634,9 +2634,8 @@ declare global {
let ended: boolean = false;

// Check the bounds of the playhead:
if (this.tickSampleCountdown == 0 || this.tickSampleCountdown > samplesPerTick) {
this.tickSampleCountdown = samplesPerTick;
}
while (this.tickSampleCountdown <= 0) this.tickSampleCountdown += samplesPerTick;
if (this.tickSampleCountdown > samplesPerTick) this.tickSampleCountdown = samplesPerTick;
if (playSong) {
if (this.beat >= this.song.beatsPerBar) {
this.bar++;
Expand Down Expand Up @@ -2710,9 +2709,7 @@ declare global {
while (bufferIndex < outputBufferLength && !ended) {

const samplesLeftInBuffer: number = outputBufferLength - bufferIndex;
const runLength: number = (this.tickSampleCountdown <= samplesLeftInBuffer)
? this.tickSampleCountdown
: samplesLeftInBuffer;
const runLength: number = Math.min(Math.ceil(this.tickSampleCountdown), samplesLeftInBuffer);
for (let channel: number = 0; channel < this.song.getChannelCount(); channel++) {

if (channel == this.liveInputChannel) {
Expand Down Expand Up @@ -2880,7 +2877,7 @@ declare global {
}

this.tick++;
this.tickSampleCountdown = samplesPerTick;
this.tickSampleCountdown += samplesPerTick;
if (this.tick == Config.ticksPerPart) {
this.tick = 0;
this.part++;
Expand Down Expand Up @@ -4328,9 +4325,9 @@ declare global {
if (this.song == null) return 0;
const beatsPerMinute: number = this.song.getBeatsPerMinute();
const beatsPerSecond: number = beatsPerMinute / 60.0;
const partsPerSecond: number = beatsPerSecond * Config.partsPerBeat;
const tickPerSecond: number = partsPerSecond * Config.ticksPerPart;
return Math.floor(this.samplesPerSecond / tickPerSecond);
const partsPerSecond: number = Config.partsPerBeat * beatsPerSecond;
const tickPerSecond: number = Config.ticksPerPart * partsPerSecond;
return this.samplesPerSecond / tickPerSecond;
}
}

Expand Down
4 changes: 3 additions & 1 deletion tasks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,6 @@
√ Allow playing piano while song is paused, added preference to preview added notes while paused.
√ Added preference to control whether to display song data in url.
√ Added song recovery feature to file menu.
√ Added .mp3 file export.
√ Added .mp3 file export.
√ Added tinyurl shortcut to file menu.
√ BPM is now precise.

0 comments on commit 46a2f1a

Please sign in to comment.