zacharycarter / soloud-nim

Nim bindings to the soloud audio engine (https://github.com/jarikomppa/soloud/)
MIT License
8 stars 1 forks source link

Did this work? #1

Open konsumer opened 1 year ago

konsumer commented 1 year ago

I know it's been a while, but I am also trying to wrap soloud in nim, and got similar output with c2nim. I keep getting Illegal storage access. (Attempt to read from nil?) when I try to Soloud_play().

import unittest
import ../src/null0/soloud

suite "Soloud":
  test "text":
    var sl = Soloud_create()
    discard Soloud_initEx(sl, ord(SOLOUD_CLIP_ROUNDOFF), ord(SOLOUD_NULLDRIVER), 44100, ord(SOLOUD_AUTO), 2)
    Soloud_setGlobalVolume(sl, 1)

    var speech = Speech_create()
    discard Speech_setText(speech, "1 2 3       A B C        Doooooo    Reeeeee    Miiiiii    Faaaaaa    Soooooo    Laaaaaa    Tiiiiii    Doooooo!")
    discard Soloud_play(speech, sl)

    Soloud_deinit(sl)
    Soloud_destroy(sl)

I get similar with your example, using your wrap of soloud. Did you ever get this working? Am I missing some steps?

My full wrapper is here. Main difference is that I inline soloud with {.compile} instead of using a dll, but I think it all works the same, and it seems to fail the same both ways.

konsumer commented 1 year ago

I don't see how this wrapper would have ever worked, but I got mine starting to work. all the types that are ptr Name should be Name for example:

proc Soloud_init*(aSoloud: ptr Soloud): cint

should be

proc Soloud_init*(aSoloud: Soloud): cint

because Soloud is already a pointer (so ptr Soloud would be a pointer to a pointer):

type
  Soloud* = pointer

Here is a working example:

import unittest
import soloud
import os

test "setup":
  var sl = Soloud_create()
  discard Soloud_init(sl)
  Soloud_setGlobalVolume(sl, 3.0)
  var speech = Speech_create()
  discard Speech_setText(speech, "Hello")
  discard Soloud_play(sl, speech)
  while Soloud_getVoiceCount(sl) > 0:
    sleep(100)

I definitely need to test a lot more, but it seems to be the start of things working.