Compare commits
2 Commits
46e4fda581
...
5d41cf4c53
Author | SHA1 | Date |
---|---|---|
Christopher Arndt | 5d41cf4c53 | |
Christopher Arndt | 2f00720d2b |
|
@ -4,62 +4,62 @@ import nymph
|
||||||
const PluginUri = "urn:nymph:examples:amp"
|
const PluginUri = "urn:nymph:examples:amp"
|
||||||
|
|
||||||
type
|
type
|
||||||
CSample = cfloat
|
CSample = cfloat
|
||||||
CSamples = UncheckedArray[CSample]
|
CSamples = UncheckedArray[CSample]
|
||||||
|
|
||||||
PortIndex = enum
|
PortIndex = enum
|
||||||
INPUT = 0,
|
INPUT = 0,
|
||||||
OUTPUT = 1,
|
OUTPUT = 1,
|
||||||
GAIN = 2
|
GAIN = 2
|
||||||
|
|
||||||
Amp = object
|
Amp = object
|
||||||
input: ptr CSamples
|
input: ptr CSamples
|
||||||
output: ptr CSamples
|
output: ptr CSamples
|
||||||
gain: ptr cfloat
|
gain: ptr cfloat
|
||||||
|
|
||||||
|
|
||||||
template db2coeff(db: cfloat): cfloat =
|
template db2coeff(db: cfloat): cfloat =
|
||||||
pow(10.0, db / 20.0)
|
pow(10.0, db / 20.0)
|
||||||
|
|
||||||
|
|
||||||
proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
||||||
bundlePath: cstring; features: ptr ptr Lv2Feature):
|
bundlePath: cstring; features: ptr ptr Lv2Feature):
|
||||||
Lv2Handle {.cdecl.} =
|
Lv2Handle {.cdecl.} =
|
||||||
return createShared(Amp)
|
return createShared(Amp)
|
||||||
|
|
||||||
|
|
||||||
proc connectPort(instance: Lv2Handle; port: cuint;
|
proc connectPort(instance: Lv2Handle; port: cuint;
|
||||||
dataLocation: pointer) {.cdecl.} =
|
dataLocation: pointer) {.cdecl.} =
|
||||||
let amp = cast[ptr Amp](instance)
|
let amp = cast[ptr Amp](instance)
|
||||||
case cast[PortIndex](port)
|
case cast[PortIndex](port)
|
||||||
of INPUT:
|
of INPUT:
|
||||||
amp.input = cast[ptr CSamples](dataLocation)
|
amp.input = cast[ptr CSamples](dataLocation)
|
||||||
of OUTPUT:
|
of OUTPUT:
|
||||||
amp.output = cast[ptr CSamples](dataLocation)
|
amp.output = cast[ptr CSamples](dataLocation)
|
||||||
of GAIN:
|
of GAIN:
|
||||||
amp.gain = cast[ptr cfloat](dataLocation)
|
amp.gain = cast[ptr cfloat](dataLocation)
|
||||||
|
|
||||||
|
|
||||||
proc activate(instance: Lv2Handle) {.cdecl.} =
|
proc activate(instance: Lv2Handle) {.cdecl.} =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
||||||
proc run(instance: Lv2Handle; nSamples: cuint) {.cdecl.} =
|
proc run(instance: Lv2Handle; nSamples: cuint) {.cdecl.} =
|
||||||
let amp = cast[ptr Amp](instance)
|
let gain = cast[ptr Amp](instance)
|
||||||
for pos in 0 ..< nSamples:
|
for pos in 0 ..< nSamples:
|
||||||
amp.output[pos] = amp.input[pos] * db2coeff(amp.gain[])
|
gain.output[pos] = gain.input[pos] * db2coeff(gain.gain[])
|
||||||
|
|
||||||
|
|
||||||
proc deactivate(instance: Lv2Handle) {.cdecl.} =
|
proc deactivate(instance: Lv2Handle) {.cdecl.} =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
||||||
proc cleanup(instance: Lv2Handle) {.cdecl.} =
|
proc cleanup(instance: Lv2Handle) {.cdecl.} =
|
||||||
freeShared(cast[ptr Amp](instance))
|
freeShared(cast[ptr Amp](instance))
|
||||||
|
|
||||||
|
|
||||||
proc extensionData(uri: cstring): pointer {.cdecl.} =
|
proc extensionData(uri: cstring): pointer {.cdecl.} =
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
|
||||||
proc NimMain() {.cdecl, importc.}
|
proc NimMain() {.cdecl, importc.}
|
||||||
|
@ -67,16 +67,16 @@ proc NimMain() {.cdecl, importc.}
|
||||||
|
|
||||||
proc lv2Descriptor(index: cuint): ptr Lv2Descriptor {.
|
proc lv2Descriptor(index: cuint): ptr Lv2Descriptor {.
|
||||||
cdecl, exportc, dynlib, extern: "lv2_descriptor".} =
|
cdecl, exportc, dynlib, extern: "lv2_descriptor".} =
|
||||||
NimMain()
|
NimMain()
|
||||||
|
|
||||||
if index == 0:
|
if index == 0:
|
||||||
result = createShared(Lv2Descriptor)
|
result = createShared(Lv2Descriptor)
|
||||||
result.uri = cstring(PluginUri)
|
result.uri = cstring(PluginUri)
|
||||||
result.instantiate = instantiate
|
result.instantiate = instantiate
|
||||||
result.connectPort = connectPort
|
result.connectPort = connectPort
|
||||||
result.activate = activate
|
result.activate = activate
|
||||||
result.run = run
|
result.run = run
|
||||||
result.deactivate = deactivate
|
result.deactivate = deactivate
|
||||||
result.cleanup = cleanup
|
result.cleanup = cleanup
|
||||||
result.extensionData = extensionData
|
result.extensionData = extensionData
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue