- pbminiaudio
- libpbminiaudio
- libpbminiaudio.a
- -lminiaudio
- libminiaudio
- libminiaudio.a
- libminiaudio.lib
- miniaudio.lib
The linker did not like any of these.

I found an easier way. I just extracted miniaudio.o from libpbminiaudio.a with the ar tool:idle wrote: Thu Oct 10, 2024 10:06 am Try this and save is as .so
viewtopic.php?p=628837#p628837
Search github for miniaudio and then try to compile it as shared object.
Code: Select all
nicolas@Rocky:~/programme/PureBasic_6.12_LTS/purelibraries/linux/libraries$ ar t libpbminiaudio.a
miniaudio.o
nicolas@Rocky:~/programme/PureBasic_6.12_LTS/purelibraries/linux/libraries$ ar x libpbminiaudio.a
nicolas@Rocky:~/programme/PureBasic_6.12_LTS/purelibraries/linux/libraries$ file miniaudio.o
miniaudio.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
Code: Select all
ImportC "/home/nicolas/programme/PureBasic_6.12_LTS/purelibraries/linux/libraries/miniaudio.o"
PWÖ
Code: Select all
ma_pcm_rb_init(format.ma_format, channels.ma_uint32, bufferSizeInFrames.ma_uint32, *pOptionalPreallocatedBuffer, *pAllocationCallbacks, *pRB.ma_pcm_rb)
ma_pcm_rb_acquire_read(*pRB.ma_pcm_rb, *pSizeInFrames, *ppBufferOut)
ma_pcm_rb_commit_read(*pRB.ma_pcm_rb, sizeInFrames.ma_uint32, *pBufferOut)
ma_pcm_rb_acquire_write(*pRB.ma_pcm_rb, *pSizeInFrames, *ppBufferOut)
ma_pcm_rb_commit_write(*pRB.ma_pcm_rb, sizeInFrames.ma_uint32, *pBufferOut)
ma_pcm_rb_available_read(*pRB.ma_pcm_rb)
ma_pcm_rb_available_write(*pRB.ma_pcm_rb)
Global rb.ma_pcm_rb
If ma_pcm_rb_init(#ma_format_f32, 2, 256, #Null, #Null, @rb) <> #MA_SUCCESS
Debug "Failed to initialize ring buffer"
End
EndIf
Debug ma_pcm_rb_available_write(@rb) ; Works fine here but not in the callback.
Need replace #PB_Ascii to #PB_UTF8 because the device name is not displayed correctly.idle wrote: Tue Feb 27, 2024 2:09 amCode: Select all
;-test device enumeration Global context.ma_context; Global *pPlaybackDeviceInfos.ma_device_info_Array; Global playbackDeviceCount.ma_uint32; Global *pCaptureDeviceInfos.ma_device_info_Array; Global captureDeviceCount.ma_uint32; Global iDevice.ma_uint32; If ma_context_init(#Null, 0, #Null, @context) <> #MA_SUCCESS PrintN("Failed to initialize context"); End -2 ; EndIf result = ma_context_get_devices(@context, @*pPlaybackDeviceInfos, @playbackDeviceCount, @*pCaptureDeviceInfos, @captureDeviceCount); If result <> #MA_SUCCESS PrintN("Failed to retrieve device information"); End -3 ; EndIf PrintN("Playback Devices"); For iDevice = 0 To playbackDeviceCount-1 PrintN("device " + Str(iDevice) + " " + PeekS(@*pPlaybackDeviceInfos\e[iDevice]\name,-1,#PB_Ascii)) Next PrintN("") PrintN("Capture Devices"); For iDevice = 0 To captureDeviceCount-1 PrintN("device " + Str(iDevice) + " " + PeekS(@*pCaptureDeviceInfos\e[iDevice]\name,-1,#PB_Ascii)) Next ma_context_uninit(@context) Input(); CompilerEndIf
Makes sense.User_Russian wrote: Sun Sep 07, 2025 5:00 pmNeed replace #PB_Ascii to #PB_UTF8 because the device name is not displayed correctly.idle wrote: Tue Feb 27, 2024 2:09 amCode: Select all
;-test device enumeration Global context.ma_context; Global *pPlaybackDeviceInfos.ma_device_info_Array; Global playbackDeviceCount.ma_uint32; Global *pCaptureDeviceInfos.ma_device_info_Array; Global captureDeviceCount.ma_uint32; Global iDevice.ma_uint32; If ma_context_init(#Null, 0, #Null, @context) <> #MA_SUCCESS PrintN("Failed to initialize context"); End -2 ; EndIf result = ma_context_get_devices(@context, @*pPlaybackDeviceInfos, @playbackDeviceCount, @*pCaptureDeviceInfos, @captureDeviceCount); If result <> #MA_SUCCESS PrintN("Failed to retrieve device information"); End -3 ; EndIf PrintN("Playback Devices"); For iDevice = 0 To playbackDeviceCount-1 PrintN("device " + Str(iDevice) + " " + PeekS(@*pPlaybackDeviceInfos\e[iDevice]\name,-1,#PB_Ascii)) Next PrintN("") PrintN("Capture Devices"); For iDevice = 0 To captureDeviceCount-1 PrintN("device " + Str(iDevice) + " " + PeekS(@*pCaptureDeviceInfos\e[iDevice]\name,-1,#PB_Ascii)) Next ma_context_uninit(@context) Input(); CompilerEndIf
Code: Select all
;-Imports
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
ImportC "miniaudio.lib"
CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
ImportC #PB_Compiler_Home+"/purelibraries/linux/libraries/libpbminiaudio.a"
CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
ImportC #PB_Compiler_Home+"/purelibraries/macos/libraries/libpbminiaudio.a"
CompilerElse
CompilerError ""
CompilerEndIf
;ma_device_config_init(deviceType)
ma_device_init(*pContext,*config,*Device)
ma_device_start(*Device);
ma_device_uninit(*Device);
ma_get_bytes_per_sample(format.ma_format)
ma_context_init(*ma_backend,backendCount.ma_uint32,*config,*context.ma_context)
ma_context_get_devices(*context, *pPlaybackDeviceInfos, *playbackDeviceCount, *pCaptureDeviceInfos, *captureDeviceCount)
ma_context_uninit(*context);
EndImport
Code: Select all
amount = framecount * (ma_get_bytes_per_sample(*Device\capture\format) * *Device\capture\channels)
The native PB lib is cutdown for whatever reason, if you wait for 6.30 b2 you wiill be able to call it directly with inline cUser_Russian wrote: Sun Sep 07, 2025 10:38 pm Tested the code on Linux and MacOS.
To do this, I changed the import code.On Linux, the program exits with the message "invalid memory access" at this line in procedure data_callback().Code: Select all
;-Imports CompilerIf #PB_Compiler_OS = #PB_OS_Windows ImportC "miniaudio.lib" CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux ImportC #PB_Compiler_Home+"/purelibraries/linux/libraries/libpbminiaudio.a" CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS ImportC #PB_Compiler_Home+"/purelibraries/macos/libraries/libpbminiaudio.a" CompilerElse CompilerError "" CompilerEndIf ;ma_device_config_init(deviceType) ma_device_init(*pContext,*config,*Device) ma_device_start(*Device); ma_device_uninit(*Device); ma_get_bytes_per_sample(format.ma_format) ma_context_init(*ma_backend,backendCount.ma_uint32,*config,*context.ma_context) ma_context_get_devices(*context, *pPlaybackDeviceInfos, *playbackDeviceCount, *pCaptureDeviceInfos, *captureDeviceCount) ma_context_uninit(*context); EndImport
In MacOS x64 the application fails to build due to a linker error.Code: Select all
amount = framecount * (ma_get_bytes_per_sample(*Device\capture\format) * *Device\capture\channels)
In MacOS miniaudio library does not contain all functions or what is the reason for the error?
I have nothing to contribute about MiniAudio, but I'm having this exact same issue interfacing with SDL3... For GUID functions, they pass and return the entire GUID (16-byte struct) and I haven't figured out how to handle it in PB! It's frustrating because everything else in the SDL API seems to use byref pointer-to-a-structure instead. I assumed I needed some fancy push-pop stack Assembly code, but perhaps now I can write C wrapper functions inside a HeaderSection...? To be explored...idle wrote: Mon Sep 08, 2025 12:01 amThe main issue with Miniaudio is that it returns structures and some functions use structures as parameters, which means you either need to wrap those functions in c so you can import then into PB or use miniaudio directly with inline c in the header section. you will still need a compatible c install though for system headers and there will likely be a couple of type conflicts between PB's c typedefs though they can perhaps be fixed with pragmas.
you could do it like this perhapskenmo wrote: Tue Sep 09, 2025 4:19 amI have nothing to contribute about MiniAudio, but I'm having this exact same issue interfacing with SDL3... For GUID functions, they pass and return the entire GUID (16-byte struct) and I haven't figured out how to handle it in PB! It's frustrating because everything else in the SDL API seems to use byref pointer-to-a-structure instead. I assumed I needed some fancy push-pop stack Assembly code, but perhaps now I can write C wrapper functions inside a HeaderSection...? To be explored...idle wrote: Mon Sep 08, 2025 12:01 amThe main issue with Miniaudio is that it returns structures and some functions use structures as parameters, which means you either need to wrap those functions in c so you can import then into PB or use miniaudio directly with inline c in the header section. you will still need a compatible c install though for system headers and there will likely be a couple of type conflicts between PB's c typedefs though they can perhaps be fixed with pragmas.
Code: Select all
HeaderSection
!integer sdl_getguid(){
!
! SDL_GUID guid = SDL_FunctionThatReturnsGUID();
! char *pzguid = PB_AllocateMemory(33);
! SDL_GUIDToString(guid,*pzguid,33);
! return *pzguid;
!};
EndHeaderSection
PrototypeC SDL_GetGUID()
Global SDL_GetGUID.SDL_GetGUID
!g_sdl_getguid = &sdl_getguid;
Debug PeekS(SDL_GetGUID(),16,#PB_Ascii)