• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

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

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:
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:
private var recordedAudioData = ShortArray(4096)

//Reading data from an audio record instance

recordedAudioData.usePinned { pinned -> {

Native.fftBuildAudioData(pinned.addressOf(0))

}
}

But when I compile I have this error :
Code:
 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)?
 
Back
Top Bottom