Skip to content

Commit 9ba7860

Browse files
committed
Adjust wave forms to Pico-8
Wave forms in Pi are slightly different from Pico-8.
1 parent 14f09c7 commit 9ba7860

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

audio/internal/oscillator.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ func (o *Oscillator) NextSample() (v float64) {
1818
return
1919
}
2020

21-
const volume = 0.7
22-
2321
func Triangle(pos float64) float64 {
2422
phase := math.Mod(pos, 1)
2523
value := math.Abs(phase*2-1)*2 - 1
2624

27-
return value * volume
25+
return value * 0.45
2826
}
2927

3028
func TiltedSaw(pos float64) float64 {
@@ -35,12 +33,12 @@ func TiltedSaw(pos float64) float64 {
3533
} else {
3634
v = (1 - phase) * 16
3735
}
38-
return (v - 1) * volume
36+
return (v - 1) * 0.45
3937
}
4038

4139
func Saw(pos float64) float64 {
4240
phase := math.Mod(pos, 1)
43-
return (phase - 0.5) * 0.9
41+
return (phase - 0.5) * 0.65
4442
}
4543

4644
func Square(pos float64) float64 {
@@ -49,7 +47,7 @@ func Square(pos float64) float64 {
4947
if phase < 0.5 {
5048
v = 1.0
5149
}
52-
return v / 3.0
50+
return v / 4.0
5351
}
5452

5553
func Pulse(pos float64) float64 {
@@ -58,13 +56,15 @@ func Pulse(pos float64) float64 {
5856
if phase < 0.3125 {
5957
v = 1.0
6058
}
61-
return v / 3.0
59+
return v / 4.0
6260
}
6361

6462
// Organ is triangle / 2
6563
func Organ(pos float64) float64 {
6664
pos = pos * 4
6765

68-
return (math.Abs(math.Mod(pos, 2)-1) - 0.5 +
69-
(math.Abs((math.Mod(pos*0.5, 2))-1)-0.5)/2 - 0.1) * volume
66+
v := math.Abs(math.Mod(pos, 2)-1) - 0.5 +
67+
(math.Abs((math.Mod(pos*0.5, 2))-1)-0.5)/2 - 0.1
68+
69+
return v * 0.55
7070
}

examples/audio/audio.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ func main() {
1010
sfx := audio.SoundEffect{
1111
Notes: [32]audio.Note{
1212
{
13-
Pitch: audio.PitchC2,
14-
Instrument: audio.InstrumentTriangle,
15-
Volume: 4,
13+
Pitch: audio.PitchG3,
14+
Instrument: audio.InstrumentOrgan,
15+
Volume: 7,
1616
},
1717
},
1818
Speed: 255,

0 commit comments

Comments
 (0)