shitty triangle oscillator
This commit is contained in:
parent
016d7e5db5
commit
bc5b72bd5f
13 changed files with 273 additions and 56 deletions
BIN
proj/block/triangle_oscillator_front.ase
Normal file
BIN
proj/block/triangle_oscillator_front.ase
Normal file
Binary file not shown.
BIN
proj/block/triangle_oscillator_side.ase
Normal file
BIN
proj/block/triangle_oscillator_side.ase
Normal file
Binary file not shown.
|
|
@ -1,4 +1,4 @@
|
|||
// 1.19.2 2023-05-01T19:04:28.317254994 Models
|
||||
// 1.19.2 2023-05-01T19:34:50.889753306 Models
|
||||
0812a674d14cfc6fbb7c0e2ac1b473bf2afe1965 assets/dawd3/models/item/brown_patch_cable.json
|
||||
6e01a1aa07f3a36d7950a1b00d1bc6e9045b9995 assets/dawd3/blockstates/knob.json
|
||||
bf0e322e33123cb6873c2da4e8c6ab85688deb4e assets/dawd3/models/item/gray_patch_cable.json
|
||||
|
|
@ -6,6 +6,7 @@ bf0e322e33123cb6873c2da4e8c6ab85688deb4e assets/dawd3/models/item/gray_patch_cab
|
|||
6a9fb209d82556f5941422a8d047a0ae2af1dc8f assets/dawd3/models/item/sine_oscillator.json
|
||||
8ba890b28c5ac57c59f19ccc8c72825caac10677 assets/dawd3/models/item/magenta_patch_cable.json
|
||||
e34001d3c974aecfa347d435beb6bc0b9d325897 assets/dawd3/models/item/cyan_patch_cable.json
|
||||
c3ea3e310d8fe7796b5b055d34db712cb8c7ac5a assets/dawd3/blockstates/triangle_oscillator.json
|
||||
f7b47538f17992177e97e06842c0039ae5096b2b assets/dawd3/blockstates/speaker.json
|
||||
9cf2cff42345ec60a944d7399b5047323aa8e88c assets/dawd3/models/item/red_patch_cable.json
|
||||
0fb5cd695c2a82a2353809529dc8b5086ee2c87d assets/dawd3/blockstates/phase.json
|
||||
|
|
@ -16,6 +17,7 @@ a4e8bc89d39021eb8d56ad7735216cb851d67287 assets/dawd3/models/item/light_blue_pat
|
|||
8c4b8147bfea2bdb8c1d348bc332a60d2cd82d68 assets/dawd3/models/item/phase.json
|
||||
aa1a1807d2c46f1f25e3d0c507952fefb5b3cd9f assets/dawd3/models/item/knob.json
|
||||
d65fd7b21da2adf55a0b076103103da7e7bb453a assets/dawd3/models/block/speaker.json
|
||||
fe4987cffd1253462cc8440c90ff2341ac3026a4 assets/dawd3/models/block/triangle_oscillator.json
|
||||
8aa966337109315240614d5257eb72f959eba5d8 assets/dawd3/models/item/orange_patch_cable.json
|
||||
4748361fec856c3fe328ac0036ee642a5865fa99 assets/dawd3/models/block/pulse_oscillator.json
|
||||
12c4bfd825b2476955afcd3bb23c1f736ce68caa assets/dawd3/models/item/yellow_patch_cable.json
|
||||
|
|
@ -24,12 +26,13 @@ aab1bce7ec4e7c7dccd3d33d4242de12b63a981d assets/dawd3/models/item/white_patch_ca
|
|||
e3c6aacd49a6395f37047d3df31f91a18a411267 assets/dawd3/models/item/speaker.json
|
||||
f69a4acfdf715c64f64830ce0a79aa452ad4760a assets/dawd3/models/item/saw_oscillator.json
|
||||
32bb0e6e3bf75b9005602e8fb1042ad5d41286ad assets/dawd3/models/item/lime_patch_cable.json
|
||||
1358574aaed0a49a6a4fdaba4ceb330463dcc421 assets/dawd3/models/block/phase.json
|
||||
c5998d4ae85e7a16010e66b4b165ddd6b7f0f3ac assets/dawd3/models/block/phase.json
|
||||
292685c025f28911bca9252da3e4ac72998b3c7a assets/dawd3/blockstates/pulse_oscillator.json
|
||||
956d8f117df95cf62c8cac375cff853df96840d6 assets/dawd3/models/item/pink_patch_cable.json
|
||||
2adb4f854a9f13090dffaf8ab9dfe0553cc59a80 assets/dawd3/models/item/triangle_oscillator.json
|
||||
3b1811bab3ba394ba03b67ac2efc72cb35316dc8 assets/dawd3/blockstates/sine_oscillator.json
|
||||
9c18a8292a0c9990cd23bebf5c6191c2114ccc6d assets/dawd3/models/item/black_patch_cable.json
|
||||
8688de3eadb6579cac89522683c394f18733e614 assets/dawd3/models/block/knob.json
|
||||
0afd7ba8d87444961a33cb87bba122fca5ebef8e assets/dawd3/models/block/saw_oscillator.json
|
||||
96135c420e211d0cfee4aff9e1ae98484b4603c4 assets/dawd3/models/block/saw_oscillator.json
|
||||
9690e1f7ff13a8ea72a1edb87c8afd6d0a228925 assets/dawd3/models/item/pulse_oscillator.json
|
||||
64c9ff6a94721f17a823c9d253559e5b9e73662a assets/dawd3/models/block/sine_oscillator.json
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"variants": {
|
||||
"facing=east": {
|
||||
"model": "dawd3:block/triangle_oscillator",
|
||||
"y": 90
|
||||
},
|
||||
"facing=north": {
|
||||
"model": "dawd3:block/triangle_oscillator"
|
||||
},
|
||||
"facing=south": {
|
||||
"model": "dawd3:block/triangle_oscillator",
|
||||
"y": 180
|
||||
},
|
||||
"facing=west": {
|
||||
"model": "dawd3:block/triangle_oscillator",
|
||||
"y": 270
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,30 +40,6 @@
|
|||
16.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
"cullface": "north",
|
||||
"texture": "#port",
|
||||
"uv": [
|
||||
4.0,
|
||||
0.0,
|
||||
8.0,
|
||||
4.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
3.0,
|
||||
6.0,
|
||||
-0.01
|
||||
],
|
||||
"to": [
|
||||
7.0,
|
||||
10.0,
|
||||
0.01
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
|
|
@ -87,6 +63,30 @@
|
|||
10.0,
|
||||
0.01
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
"cullface": "north",
|
||||
"texture": "#port",
|
||||
"uv": [
|
||||
4.0,
|
||||
0.0,
|
||||
8.0,
|
||||
4.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
3.0,
|
||||
6.0,
|
||||
-0.01
|
||||
],
|
||||
"to": [
|
||||
7.0,
|
||||
10.0,
|
||||
0.01
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures": {
|
||||
|
|
|
|||
|
|
@ -40,30 +40,6 @@
|
|||
16.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
"cullface": "north",
|
||||
"texture": "#port",
|
||||
"uv": [
|
||||
0.0,
|
||||
0.0,
|
||||
4.0,
|
||||
4.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
9.0,
|
||||
6.0,
|
||||
-0.01
|
||||
],
|
||||
"to": [
|
||||
13.0,
|
||||
10.0,
|
||||
0.01
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
|
|
@ -87,6 +63,30 @@
|
|||
10.0,
|
||||
0.01
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
"cullface": "north",
|
||||
"texture": "#port",
|
||||
"uv": [
|
||||
0.0,
|
||||
0.0,
|
||||
4.0,
|
||||
4.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
9.0,
|
||||
6.0,
|
||||
-0.01
|
||||
],
|
||||
"to": [
|
||||
13.0,
|
||||
10.0,
|
||||
0.01
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures": {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
{
|
||||
"parent": "block/block",
|
||||
"elements": [
|
||||
{
|
||||
"faces": {
|
||||
"down": {
|
||||
"cullface": "down",
|
||||
"texture": "#bottom"
|
||||
},
|
||||
"east": {
|
||||
"cullface": "east",
|
||||
"texture": "#right"
|
||||
},
|
||||
"north": {
|
||||
"cullface": "north",
|
||||
"texture": "#front"
|
||||
},
|
||||
"south": {
|
||||
"cullface": "south",
|
||||
"texture": "#back"
|
||||
},
|
||||
"up": {
|
||||
"cullface": "up",
|
||||
"rotation": 180,
|
||||
"texture": "#top"
|
||||
},
|
||||
"west": {
|
||||
"cullface": "west",
|
||||
"texture": "#left"
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"to": [
|
||||
16.0,
|
||||
16.0,
|
||||
16.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
"cullface": "north",
|
||||
"texture": "#port",
|
||||
"uv": [
|
||||
0.0,
|
||||
0.0,
|
||||
4.0,
|
||||
4.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
9.0,
|
||||
6.0,
|
||||
-0.01
|
||||
],
|
||||
"to": [
|
||||
13.0,
|
||||
10.0,
|
||||
0.01
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
"cullface": "north",
|
||||
"texture": "#port",
|
||||
"uv": [
|
||||
4.0,
|
||||
0.0,
|
||||
8.0,
|
||||
4.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
3.0,
|
||||
6.0,
|
||||
-0.01
|
||||
],
|
||||
"to": [
|
||||
7.0,
|
||||
10.0,
|
||||
0.01
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures": {
|
||||
"back": "dawd3:block/triangle_oscillator_side",
|
||||
"bottom": "dawd3:block/triangle_oscillator_side",
|
||||
"front": "dawd3:block/triangle_oscillator_front",
|
||||
"left": "dawd3:block/triangle_oscillator_side",
|
||||
"particle": "dawd3:block/triangle_oscillator_side",
|
||||
"port": "dawd3:device/port",
|
||||
"right": "dawd3:block/triangle_oscillator_side",
|
||||
"top": "dawd3:block/triangle_oscillator_side"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"parent": "dawd3:block/triangle_oscillator"
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package net.liquidev.dawd3.audio.devices.oscillator
|
||||
|
||||
import net.liquidev.dawd3.Mod
|
||||
import net.liquidev.dawd3.audio.device.*
|
||||
import net.minecraft.util.Identifier
|
||||
import kotlin.math.abs
|
||||
|
||||
class TriangleOscillatorDevice : Device<NoControls> {
|
||||
companion object : DeviceDescriptor {
|
||||
override val id = Identifier(Mod.id, "triangle_oscillator")
|
||||
val phasePort = InputPortName(id, "phase")
|
||||
val outputPort = OutputPortName(id, "output")
|
||||
|
||||
// TODO: Make this into a couple controls and put it into a nice UI
|
||||
const val usePolyBLEP = false
|
||||
const val oversampling = 1
|
||||
}
|
||||
|
||||
private val phase = InputPort()
|
||||
private val output = OutputPort(bufferCount = 1)
|
||||
|
||||
private val phaseDerivative = PhaseDerivative()
|
||||
private var previous = 0f
|
||||
|
||||
override fun process(sampleCount: Int, controls: NoControls) {
|
||||
val phaseBuffer = phase.getConnectedOutputBuffer(0, sampleCount)
|
||||
|
||||
val outputBuffer = output.buffers[0].getOrReallocate(sampleCount)
|
||||
for (i in 0 until sampleCount) {
|
||||
val phase = phaseBuffer[i]
|
||||
val deltaPhase = phaseDerivative.stepNextDerivative(phase)
|
||||
outputBuffer[i] = oversample(phase, deltaPhase, oversampling, ::triangle)
|
||||
}
|
||||
}
|
||||
|
||||
private fun triangle(t: Float, dt: Float): Float {
|
||||
return if (usePolyBLEP) {
|
||||
val naivePulse = if (t > 0.5f) 1f else -1f
|
||||
val pulse = naivePulse + polyBLEP((t + 0.5f) % 1f, dt) - polyBLEP(t, dt)
|
||||
val triangle = dt * pulse + (1f - dt) * previous
|
||||
previous = triangle * 0.99f
|
||||
triangle * 4f
|
||||
} else {
|
||||
val saw = t * 2f - 1f
|
||||
2f * abs(saw) - 1f
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitInputPorts(visit: (InputPortName, InputPort) -> Unit) {
|
||||
visit(phasePort, phase)
|
||||
}
|
||||
|
||||
override fun visitOutputPorts(visit: (OutputPortName, OutputPort) -> Unit) {
|
||||
visit(outputPort, output)
|
||||
}
|
||||
}
|
||||
|
|
@ -12,10 +12,7 @@ import net.liquidev.dawd3.block.device.DeviceBlockEntity
|
|||
import net.liquidev.dawd3.block.device.DeviceBlockEntityRenderer
|
||||
import net.liquidev.dawd3.block.devices.KnobBlockDescriptor
|
||||
import net.liquidev.dawd3.block.devices.SpeakerBlockDescriptor
|
||||
import net.liquidev.dawd3.block.devices.oscillator.PhaseBlockDescriptor
|
||||
import net.liquidev.dawd3.block.devices.oscillator.PulseOscillatorBlockDescriptor
|
||||
import net.liquidev.dawd3.block.devices.oscillator.SawOscillatorBlockDescriptor
|
||||
import net.liquidev.dawd3.block.devices.oscillator.SineOscillatorBlockDescriptor
|
||||
import net.liquidev.dawd3.block.devices.oscillator.*
|
||||
import net.liquidev.dawd3.item.Items
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.Material
|
||||
|
|
@ -68,8 +65,9 @@ object Blocks {
|
|||
|
||||
val phase = registerDeviceBlock(PhaseBlockDescriptor)
|
||||
val sineOscillator = registerDeviceBlock(SineOscillatorBlockDescriptor)
|
||||
val sawOscillator = registerDeviceBlock(SawOscillatorBlockDescriptor)
|
||||
val pulseOscillator = registerDeviceBlock(PulseOscillatorBlockDescriptor)
|
||||
val sawOscillator = registerDeviceBlock(SawOscillatorBlockDescriptor)
|
||||
val triangleOscillator = registerDeviceBlock(TriangleOscillatorBlockDescriptor)
|
||||
|
||||
fun initialize() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package net.liquidev.dawd3.block.devices.oscillator
|
||||
|
||||
import net.liquidev.dawd3.Mod
|
||||
import net.liquidev.dawd3.audio.device.DeviceInstance
|
||||
import net.liquidev.dawd3.audio.device.NoControls
|
||||
import net.liquidev.dawd3.audio.devices.oscillator.TriangleOscillatorDevice
|
||||
import net.liquidev.dawd3.block.device.DeviceBlockDescriptor
|
||||
import net.liquidev.dawd3.block.device.PhysicalPort
|
||||
import net.minecraft.client.world.ClientWorld
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.Vec2f
|
||||
|
||||
object TriangleOscillatorBlockDescriptor : DeviceBlockDescriptor<TriangleOscillatorBlockDescriptor.ClientState, NoControls> {
|
||||
override val id = Identifier(Mod.id, "triangle_oscillator")
|
||||
|
||||
override val portLayout = PhysicalPort.layout {
|
||||
port(
|
||||
TriangleOscillatorDevice.phasePort,
|
||||
position = Vec2f(0.25f, 0.5f),
|
||||
side = PhysicalPort.Side.Front,
|
||||
)
|
||||
port(
|
||||
TriangleOscillatorDevice.outputPort,
|
||||
position = Vec2f(0.75f, 0.5f),
|
||||
side = PhysicalPort.Side.Front
|
||||
)
|
||||
}
|
||||
|
||||
class ClientState(controls: NoControls) : DeviceBlockDescriptor.ClientState {
|
||||
override val logicalDevice = DeviceInstance.create(TriangleOscillatorDevice(), controls)
|
||||
}
|
||||
|
||||
override fun initControls() = NoControls
|
||||
|
||||
override fun onClientLoad(controls: NoControls, world: ClientWorld) = ClientState(controls)
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 298 B |
Binary file not shown.
|
After Width: | Height: | Size: 199 B |
Reference in a new issue