1. Are you ready for the Galaxy S20? Here is everything we know so far!

Cannot use Kotlin object pinnig to pass a buffer to a C function

Discussion in 'Android Development' started by DridriLaBastos, Oct 11, 2021.

  1. DridriLaBastos

    Thread Starter

    I am working on an app, and I need to pass a buffer of audio data from kotlin to a C function. The prototype of the C function is :
    Code (Text):
    1. DECL(void, fftBuildAudioData, const jshort* const recordedAudio)
    (DECL is a macro to declare the good prototype and name function to match JNI specifictions)

    I saw in the Kotlin web page that kotlin is abble to pass pointer to C code with object pinning So I tried to write this code on my kotlin file :

    Code (Text):
    1.  
    2. private var recordedAudioData = ShortArray(4096)
    3.  
    4. //Reading data from an audio record instance
    5.  
    6. recordedAudioData.usePinned { pinned -> {
    7.  
    8. Native.fftBuildAudioData(pinned.addressOf(0))
    9.  
    10. }
    11. }
    But when I compile I have this error :
    Code (Text):
    1.  Unresolved reference: usePinned
    I know I can use the env function GetShortArrayElements but the function may involve a copy of the initial array and I don't want that so I cannot use it.

    My question is: how can I pass a Kotlin ShortArray as a pointer to a native c function if the way provided by the language doesn't work (I use Android Studio v2020.3.1 Patch 2)?
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Cannot Kotlin object
  1. CiDefaid
    Replies:
    3
    Views:
    350
  2. Bob65
    Replies:
    1
    Views:
    800
  3. Janeire
    Replies:
    2
    Views:
    290
  4. Paolo Giovanelli
    Replies:
    0
    Views:
    503
  5. mikewax
    Replies:
    0
    Views:
    444
  6. unet
    Replies:
    0
    Views:
    574
  7. kgash
    Replies:
    6
    Views:
    672
  8. ixoni
    Replies:
    8
    Views:
    828
  9. Anand Suthar
    Replies:
    1
    Views:
    1,598
  10. Kevil
    Replies:
    1
    Views:
    1,782

Share This Page

Loading...