pulse oscillator
This commit is contained in:
parent
9dbf5000a7
commit
016d7e5db5
15 changed files with 252 additions and 30 deletions
BIN
proj/block/pulse_oscillator_front.ase
Normal file
BIN
proj/block/pulse_oscillator_front.ase
Normal file
Binary file not shown.
BIN
proj/block/pulse_oscillator_side.ase
Normal file
BIN
proj/block/pulse_oscillator_side.ase
Normal file
Binary file not shown.
|
|
@ -1,4 +1,4 @@
|
|||
// 1.19.2 2023-05-01T17:37:15.245979043 Models
|
||||
// 1.19.2 2023-05-01T19:04:28.317254994 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
|
||||
|
|
@ -17,6 +17,7 @@ a4e8bc89d39021eb8d56ad7735216cb851d67287 assets/dawd3/models/item/light_blue_pat
|
|||
aa1a1807d2c46f1f25e3d0c507952fefb5b3cd9f assets/dawd3/models/item/knob.json
|
||||
d65fd7b21da2adf55a0b076103103da7e7bb453a assets/dawd3/models/block/speaker.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
|
||||
aab1bce7ec4e7c7dccd3d33d4242de12b63a981d assets/dawd3/models/item/white_patch_cable.json
|
||||
6cdda36e539e23acf3db70d761338e88932a6ebb assets/dawd3/models/item/purple_patch_cable.json
|
||||
|
|
@ -24,9 +25,11 @@ 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
|
||||
292685c025f28911bca9252da3e4ac72998b3c7a assets/dawd3/blockstates/pulse_oscillator.json
|
||||
956d8f117df95cf62c8cac375cff853df96840d6 assets/dawd3/models/item/pink_patch_cable.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
|
||||
50023b9cff64844a4001e3e78d3f0ac828f2724a assets/dawd3/models/block/sine_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/pulse_oscillator",
|
||||
"y": 90
|
||||
},
|
||||
"facing=north": {
|
||||
"model": "dawd3:block/pulse_oscillator"
|
||||
},
|
||||
"facing=south": {
|
||||
"model": "dawd3:block/pulse_oscillator",
|
||||
"y": 180
|
||||
},
|
||||
"facing=west": {
|
||||
"model": "dawd3:block/pulse_oscillator",
|
||||
"y": 270
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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": [
|
||||
4.0,
|
||||
0.0,
|
||||
8.0,
|
||||
4.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
3.0,
|
||||
3.0,
|
||||
-0.01
|
||||
],
|
||||
"to": [
|
||||
7.0,
|
||||
7.0,
|
||||
0.01
|
||||
]
|
||||
},
|
||||
{
|
||||
"faces": {
|
||||
"north": {
|
||||
"cullface": "north",
|
||||
"texture": "#port",
|
||||
"uv": [
|
||||
0.0,
|
||||
0.0,
|
||||
4.0,
|
||||
4.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"from": [
|
||||
9.0,
|
||||
3.0,
|
||||
-0.01
|
||||
],
|
||||
"to": [
|
||||
13.0,
|
||||
7.0,
|
||||
0.01
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures": {
|
||||
"back": "dawd3:block/pulse_oscillator_side",
|
||||
"bottom": "dawd3:block/pulse_oscillator_side",
|
||||
"front": "dawd3:block/pulse_oscillator_front",
|
||||
"left": "dawd3:block/pulse_oscillator_side",
|
||||
"particle": "dawd3:block/pulse_oscillator_side",
|
||||
"port": "dawd3:device/port",
|
||||
"right": "dawd3:block/pulse_oscillator_side",
|
||||
"top": "dawd3:block/pulse_oscillator_side"
|
||||
}
|
||||
}
|
||||
|
|
@ -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,3 @@
|
|||
{
|
||||
"parent": "dawd3:block/pulse_oscillator"
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package net.liquidev.dawd3.audio.devices.oscillator
|
||||
|
||||
import net.liquidev.dawd3.Mod
|
||||
import net.liquidev.dawd3.audio.device.*
|
||||
import net.minecraft.util.Identifier
|
||||
|
||||
class PulseOscillatorDevice : Device<NoControls> {
|
||||
companion object : DeviceDescriptor {
|
||||
override val id = Identifier(Mod.id, "pulse_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 = true
|
||||
const val oversampling = 4
|
||||
|
||||
// Especially this should be a knob+CV controlled thing.
|
||||
const val dutyCycle = 0.5f
|
||||
}
|
||||
|
||||
private val phase = InputPort()
|
||||
private val output = OutputPort(bufferCount = 1)
|
||||
|
||||
private val phaseDerivative = PhaseDerivative()
|
||||
|
||||
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, ::pulse)
|
||||
}
|
||||
}
|
||||
|
||||
private fun pulse(t: Float, dt: Float): Float {
|
||||
val naivePulse = if (t > 1f - dutyCycle) 1f else -1f
|
||||
return if (usePolyBLEP) {
|
||||
naivePulse + polyBLEP((t + dutyCycle) % 1f, dt) - polyBLEP(t, dt)
|
||||
} else {
|
||||
naivePulse
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitInputPorts(visit: (InputPortName, InputPort) -> Unit) {
|
||||
visit(phasePort, phase)
|
||||
}
|
||||
|
||||
override fun visitOutputPorts(visit: (OutputPortName, OutputPort) -> Unit) {
|
||||
visit(outputPort, output)
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,12 @@ import net.liquidev.dawd3.block.device.AnyDeviceBlockDescriptor
|
|||
import net.liquidev.dawd3.block.device.DeviceBlock
|
||||
import net.liquidev.dawd3.block.device.DeviceBlockEntity
|
||||
import net.liquidev.dawd3.block.device.DeviceBlockEntityRenderer
|
||||
import net.liquidev.dawd3.block.devices.*
|
||||
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.item.Items
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.Material
|
||||
|
|
@ -64,6 +69,7 @@ object Blocks {
|
|||
val phase = registerDeviceBlock(PhaseBlockDescriptor)
|
||||
val sineOscillator = registerDeviceBlock(SineOscillatorBlockDescriptor)
|
||||
val sawOscillator = registerDeviceBlock(SawOscillatorBlockDescriptor)
|
||||
val pulseOscillator = registerDeviceBlock(PulseOscillatorBlockDescriptor)
|
||||
|
||||
fun initialize() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package net.liquidev.dawd3.block.devices
|
||||
package net.liquidev.dawd3.block.devices.oscillator
|
||||
|
||||
import net.liquidev.dawd3.Mod
|
||||
import net.liquidev.dawd3.audio.device.DeviceInstance
|
||||
|
|
@ -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.PulseOscillatorDevice
|
||||
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 PulseOscillatorBlockDescriptor : DeviceBlockDescriptor<PulseOscillatorBlockDescriptor.ClientState, NoControls> {
|
||||
override val id = Identifier(Mod.id, "pulse_oscillator")
|
||||
|
||||
override val portLayout = PhysicalPort.layout {
|
||||
port(
|
||||
PulseOscillatorDevice.phasePort,
|
||||
position = Vec2f(0.25f, 0.75f),
|
||||
side = PhysicalPort.Side.Front,
|
||||
)
|
||||
port(
|
||||
PulseOscillatorDevice.outputPort,
|
||||
position = Vec2f(0.75f, 0.75f),
|
||||
side = PhysicalPort.Side.Front
|
||||
)
|
||||
}
|
||||
|
||||
class ClientState(controls: NoControls) : DeviceBlockDescriptor.ClientState {
|
||||
override val logicalDevice = DeviceInstance.create(PulseOscillatorDevice(), controls)
|
||||
}
|
||||
|
||||
override fun initControls() = NoControls
|
||||
|
||||
override fun onClientLoad(controls: NoControls, world: ClientWorld) = ClientState(controls)
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.liquidev.dawd3.block.devices
|
||||
package net.liquidev.dawd3.block.devices.oscillator
|
||||
|
||||
import net.liquidev.dawd3.Mod
|
||||
import net.liquidev.dawd3.audio.device.DeviceInstance
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.liquidev.dawd3.block.devices
|
||||
package net.liquidev.dawd3.block.devices.oscillator
|
||||
|
||||
import net.liquidev.dawd3.Mod
|
||||
import net.liquidev.dawd3.audio.device.DeviceInstance
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 342 B |
Binary file not shown.
|
After Width: | Height: | Size: 200 B |
Reference in a new issue