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