mirror of
https://github.com/genemecija/learn-morse-code.git
synced 2025-12-06 07:02:00 +01:00
Progress on tone timing synchronization between telegraph keys
This commit is contained in:
parent
b3436d963b
commit
d681c3d237
|
|
@ -2,7 +2,7 @@
|
|||
"timingUnit": 1,
|
||||
"ditMaxTime": 60,
|
||||
"mainVolume": 0.2,
|
||||
"frequency": 700.0,
|
||||
"frequency": 550.0,
|
||||
"practiceSpeed": {
|
||||
"slow": 40,
|
||||
"normal": 24,
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@ function useElectronicKey() {
|
|||
|
||||
const timingUnit = config.timingUnit
|
||||
|
||||
let ratio = 0.2
|
||||
const ditMaxTime = 80 // ditMaxTime * 0.365 to get ms, e.g. 85 * 0.365 ~= 31ms
|
||||
let ratio = .2
|
||||
const ditMaxTime = 85 // ditMaxTime * 0.365 to get ms, e.g. 85 * 0.365 ~= 31ms
|
||||
|
||||
const letterGapMinTime = ditMaxTime*ratio*3 //config.practiceSpeed.normal*3
|
||||
const wordGapMaxTime = ditMaxTime*ratio*7 // config.practiceSpeed.normal*7
|
||||
const morseHistorySize = config.historySize
|
||||
|
|
@ -57,6 +58,12 @@ function useElectronicKey() {
|
|||
let frequency = config.frequency
|
||||
|
||||
|
||||
let toneTimer = 0
|
||||
let toneTime = 0
|
||||
let start = 0
|
||||
let end = 0
|
||||
|
||||
|
||||
// Promisify playing Dits and Dahs
|
||||
function play(ditDah) {
|
||||
let playDuration = ((ditDah === '.') ? ditMaxTime : ditMaxTime*3)
|
||||
|
|
@ -82,19 +89,23 @@ function useElectronicKey() {
|
|||
g.connect(context.destination)
|
||||
|
||||
o.start(startTime)
|
||||
|
||||
// // for troubleshooting ditDah length in milliseconds
|
||||
// toneTimer = setInterval(() => {
|
||||
// toneTime += 1
|
||||
// }, 1);
|
||||
// start = toneTime
|
||||
// // </>
|
||||
|
||||
g.gain.setTargetAtTime(0.0001, startTime + playDuration/1000, 0.001)
|
||||
o.stop(startTime + playDuration/1000 + 0.05)
|
||||
|
||||
setTimeout(() => {
|
||||
g.gain.setTargetAtTime(0.0001, context.currentTime, 0.001)
|
||||
o.stop(context.currentTime + 0.05)
|
||||
}, playDuration)
|
||||
// g.gain.setTargetAtTime(0.0001, startTime + playDuration/1000, 0.001)
|
||||
// o.stop(startTime + playDuration/1000 + 0.05)
|
||||
})
|
||||
}
|
||||
|
||||
function stopToneTimer() {
|
||||
clearInterval(toneTimer)
|
||||
end = toneTime
|
||||
console.log('toneTime:', start, end);
|
||||
toneTime = 0
|
||||
}
|
||||
|
||||
function playWithSpaces(ditDah) {
|
||||
let delay = (ditDah === '.') ? ditMaxTime + ditMaxTime : ditMaxTime*3 + ditMaxTime
|
||||
|
||||
|
|
@ -105,14 +116,19 @@ function useElectronicKey() {
|
|||
checkGapBetweenInputs()
|
||||
setMorseCharBuffer(prev => prev + ditDah)
|
||||
|
||||
// for troubleshooting ditDah length in milliseconds
|
||||
toneTimer = setInterval(() => {
|
||||
toneTime += 1
|
||||
}, 1);
|
||||
start = toneTime
|
||||
|
||||
|
||||
play(ditDah)
|
||||
.then(setTimeout(() => {
|
||||
|
||||
// START GAP TIMER
|
||||
// gapTimerRunning = true
|
||||
gapTimer = setInterval(() => {
|
||||
gapTime += 1
|
||||
|
||||
|
||||
if (gapTime >= wordGapMaxTime) {
|
||||
setMorseCharBuffer(prev => prev + '/')
|
||||
clearInterval(gapTimer)
|
||||
|
|
@ -122,7 +138,8 @@ function useElectronicKey() {
|
|||
}, timingUnit)
|
||||
|
||||
resolve();
|
||||
}, delay))
|
||||
}, delay)
|
||||
)
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
|
|
@ -264,6 +281,10 @@ function useElectronicKey() {
|
|||
depressSyncTime = 0
|
||||
}
|
||||
function checkGapBetweenInputs() {
|
||||
console.log('ditMaxTime', ditMaxTime)
|
||||
console.log('gapTime', gapTime);
|
||||
console.log('letterGapMinTime', letterGapMinTime);
|
||||
console.log('wordGapMaxTime', wordGapMaxTime);
|
||||
// Check Gap between letters
|
||||
if (gapTime >= letterGapMinTime && gapTime < wordGapMaxTime) {
|
||||
setMorseCharBuffer(prev => prev + ' ')
|
||||
|
|
|
|||
|
|
@ -41,8 +41,12 @@ function useMorsePlayer() {
|
|||
g.connect(context.destination)
|
||||
o.start(startTime)
|
||||
|
||||
g.gain.setTargetAtTime(0.0001, startTime + length/1000, 0.001)
|
||||
o.stop(startTime + length/1000 + 0.05)
|
||||
// g.gain.setTargetAtTime(0.0001, startTime + length/1000, 0.001)
|
||||
// o.stop(startTime + length/1000 + 0.05)
|
||||
setTimeout(() => {
|
||||
g.gain.setTargetAtTime(0.0001, context.currentTime, 0.009)
|
||||
o.stop(context.currentTime + 0.05)
|
||||
}, length)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ function useStraightKey() {
|
|||
|
||||
if (o.context.state === 'running') {
|
||||
g.gain.setTargetAtTime(0.0001, context.currentTime, 0.001)
|
||||
o.stop(context.currentTime + 0.01)
|
||||
o.stop(context.currentTime + 0.05)
|
||||
}
|
||||
} else { return }
|
||||
}
|
||||
|
|
@ -142,7 +142,10 @@ function useStraightKey() {
|
|||
|
||||
function checkGapBetweenInputs() {
|
||||
// Check Gap between letters
|
||||
|
||||
console.log('ditMaxTime', ditMaxTime)
|
||||
console.log('gapTime', gapTime);
|
||||
console.log('letterGapMinTime', letterGapMinTime);
|
||||
console.log('wordGapMaxTime', wordGapMaxTime);
|
||||
if (gapTime >= letterGapMinTime && gapTime < wordGapMaxTime) {
|
||||
// if (mode === 'practice') {
|
||||
setMorseCharBuffer(prev => prev + ' ')
|
||||
|
|
|
|||
Loading…
Reference in a new issue