Skip to content

Commit

Permalink
Simplify sounds, lower volume
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Jan 25, 2024
1 parent 9aaff7c commit 94c3ade
Showing 1 changed file with 31 additions and 70 deletions.
101 changes: 31 additions & 70 deletions src/ui/sounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,24 @@
import * as Tone from 'tone'

// Create synths and connect it to the main output (your speakers).
const polySynth = new Tone.PolySynth(Tone.AMSynth, {volume: -36}).toDestination()
const amSynth = new Tone.AMSynth({volume: -14}).toDestination()
const polySynth = new Tone.PolySynth(Tone.AMSynth, {volume: -20}).toDestination()
const amSynth = new Tone.AMSynth({volume: -10}).toDestination()

export async function init() {
await Tone.start()
console.log('audio is ready')
console.log('Sound initialized')
}

function startGame() {
polySynth.triggerAttackRelease(['D4', 'F4', 'A4', 'C5', 'E5'], 0.7)
}

const brownNoise = new Tone.Noise({
type: 'brown',
fadeOut: 0.07,
volume: -33,
})

const autoFilter = new Tone.AutoFilter({
frequency: '5n',
baseFrequency: 3000,
octaves: 2,
}).toDestination()

const selectCard = () => {
brownNoise.start()
// make an autofilter to shape the noise
autoFilter.start().stop('+0.1')
brownNoise.connect(autoFilter)
// start the autofilter LFO
brownNoise.stop('+0.04')
}

const pinkNoise = new Tone.Noise({
type: 'pink',
fadeOut: 0.2,
volume: -28,
})

function endTurn() {
pinkNoise.start()

const autoFilter = new Tone.AutoFilter({
frequency: '2n',
baseFrequency: 200,
octaves: 2,
})
.toDestination()
.start()
.stop('+0.4')

pinkNoise.connect(autoFilter).stop('+0.2')
polySynth.triggerAttackRelease(['D4', 'F4', 'A4', 'C5', 'E5'], '4n')
}

function startTurn() {
/* synth.triggerAttackRelease('C4', '8n') */

// initialize the noise and start
const noise = new Tone.Noise({
type: 'pink',
fadeOut: 0.4,
volume: -33,
volume: -20,
}).start()

// make an autofilter to shape the noise
Expand All @@ -82,12 +38,32 @@ function startTurn() {
noise.stop('+0.3')
}

function endTurn() {
const pinkNoise = new Tone.Noise({
type: 'pink',
fadeOut: 0.2,
volume: -28,
})

pinkNoise.start()
const autoFilter = new Tone.AutoFilter({
frequency: '2n',
// baseFrequency: 200,
octaves: 4,
volume: -10,
})
.toDestination()
.start()
.stop('+0.4')
pinkNoise.connect(autoFilter).stop('+0.3')
}

function cardToHand() {
// initialize the noise and start
const noise = new Tone.Noise({
type: 'pink',
fadeOut: 0.1,
volume: -35,
volume: -20,
}).start()

// make an autofilter to shape the noise
Expand All @@ -107,31 +83,16 @@ function cardToHand() {
.stop('+0.1')
}

function playCard(card) {
// const cardType = card.damage ? 'attack' : 'defense'
// if (cardType === 'attack') {
// playAttackCard()
// }
// if (cardType === 'defense') {
// playDefenseCard()
// }
playGenericCard()
}

const playGenericCard = () => {
amSynth.triggerAttackRelease('G#3', 0.1)
}

const playAttackCard = () => {
amSynth.triggerAttackRelease('G#3', 0.2)
const selectCard = () => {
amSynth.triggerAttackRelease('C4', '8n')
}

const playDefenseCard = () => {
amSynth.triggerAttackRelease('G#2', 0.02)
function playCard(card) {
amSynth.triggerAttackRelease('G#3', '16n')
}

export const toggleMute = (shouldMute) => {
Tone.Master.mute = shouldMute
Tone.Destination.mute = shouldMute
}

export default {
Expand Down

0 comments on commit 94c3ade

Please sign in to comment.