miniaudio.h
miniaudio.h
Hi, i am trying to import miniaudio.h using the C backend and inline C. Inside the header file are lots of includes to other header files. Is there a way to tell GCC where to look for these files? I get errors complaining about not finding the include files.
https://miniaud.io/
https://miniaud.io/
Re: miniaudio.h
You need to add the include path on the GCC commandline. On a side note, I plan to migrate the sound lib to miniaudio, as it seems very powerful and crossplateform.
Re: miniaudio.h
Hi Fred, will you include all of its functionality?
I have never done this before, can you explain?You need to add the include path on the GCC commandline
Re: miniaudio.h
Fred, I can't get it working by including it
PB test
Code: Select all
!//gccflags -IC:\llvm-mingw-20211002-msvcrt-x86_64\lib\clang\13.0.0\include;
!//#include "d:\miniaudio\miniaudio.c";
!//useclang;
but I can get it working as a dll but it's tricky without an import.error: typedef redefinition with different types ('void' vs 'char')
typedef void TCHAR;
^
C:\llvm-mingw-20211002-msvcrt-x86_64\include\winnt.h:373:16: note: previous definition is here
typedef char TCHAR, *PTCHAR;
^
Code: Select all
//miniaudio.c
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
>clang -c miniaudio.c -ldl -lpthread -lm
>clang -shared miniaudio.o -o miniaudiox64.dll -Wl,--out-implib,miniaudiox64.lib
PB test
Code: Select all
!//gccflags -IC:\llvm-mingw-20211002-msvcrt-x86_64\lib\clang\13.0.0\include;
!//#include "E:\andrews\pbstuff\miniaudio\miniaudio.h";
!//useclang;
ImportC "miniaudiox64.lib" : EndImport
ProcedureC data_callback(*Device,*Output,*Input,frameCount)
Protected amount
If frameCount
!ma_device* pDevice;
!pDevice = p_device;
!v_amount = v_framecount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels);
If amount <> 0
CopyMemory(*input,*Output,amount)
EndIf
EndIf
EndProcedure
OpenConsole()
data_callback(0,0,0,0)
!ma_result result;
!ma_device_config deviceConfig;
!ma_device device;
!deviceConfig = ma_device_config_init(ma_device_type_duplex);
!deviceConfig.capture.pDeviceID = NULL;
!deviceConfig.capture.format = ma_format_s16;
!deviceConfig.capture.channels = 2;
!deviceConfig.capture.shareMode = ma_share_mode_shared;
!deviceConfig.playback.pDeviceID = NULL;
!deviceConfig.playback.format = ma_format_s16;
!deviceConfig.playback.channels = 2;
!deviceConfig.dataCallback = f_data_callback;
!result = ma_device_init(NULL, &deviceConfig, &device);
!if (result != MA_SUCCESS) {
MessageRequester("error","failed to config")
End
!}
!ma_device_start(&device);
PrintN("press enter to end")
Input();
!ma_device_uninit(&device);
Re: miniaudio.h
Thanks idle, works fine although i had to rename the dll to miniaudio.dll
Re: miniaudio.h
exclusive mode does not seem to work. no sound, no errors and callback is passing buffers as normal.
Re: miniaudio.h
It works with other audio devices so its an issue with my usb audio driver. Strange as the usb audio device works in exclusive mode with portaudio.
Here is how i enumerate the playback devices.
Here is how i enumerate the playback devices.
Code: Select all
!//gccflags -IC:\llvm-mingw-20211002-msvcrt-x86_64\lib\clang\13.0.0\include;
!//#include "D:\Purebasic\miniaudio\miniaudio\miniaudio.h";
!//useclang;
ImportC "miniaudio.lib" : EndImport
ProcedureC data_callback(*Device,*Output,*Input,frameCount)
Protected amount
If frameCount
;Debug frameCount
!ma_device* pDevice;
!pDevice = p_device;
!v_amount = v_framecount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels);
If amount <> 0
CopyMemory(*input,*Output,amount)
EndIf
EndIf
EndProcedure
OpenConsole()
data_callback(0,0,0,0)
!ma_context context;
!if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
PrintN("Context ERROR")
!}
!ma_device_info* pPlaybackInfos;
!ma_uint32 playbackCount;
!ma_device_info* pCaptureInfos;
!ma_uint32 captureCount ;
!if (ma_context_get_devices(&context, &pPlaybackInfos, &playbackCount, &pCaptureInfos, &captureCount) != MA_SUCCESS) {
PrintN("Get Devices ERROR")
!}
playback_count.l
!v_playback_count = playbackCount;
PrintN("Playback Devices" + #CRLF$);
For k = 0 To playback_count
names.l = 0
!v_names = pPlaybackInfos[v_k].name;
PrintN(Str(k) + " " + PeekS(names, -1, #PB_Ascii))
Next
!ma_result result;
!ma_device_config deviceConfig;
!ma_device device;
!deviceConfig = ma_device_config_init(ma_device_type_playback);
!deviceConfig.playback.pDeviceID = &pPlaybackInfos[1].id;
!deviceConfig.playback.format = ma_format_f32;
!deviceConfig.playback.channels = 2;
!deviceConfig.playback.shareMode = ma_share_mode_exclusive;
!deviceConfig.dataCallback = f_data_callback;
!deviceConfig.sampleRate = 48000;
!deviceConfig.periodSizeInFrames = 480;
!deviceConfig.periods = 3;
!deviceConfig.wasapi.noAutoConvertSRC = MA_TRUE;
!result = ma_device_init(NULL, &deviceConfig, &device);
!if (result != MA_SUCCESS) {
MessageRequester("error","failed to config")
End
!}
!result = ma_device_start(&device);
!if (result != MA_SUCCESS) {
MessageRequester("error","failed to start")
End
!}
PrintN("press enter to end")
Input();
!ma_device_uninit(&device);
Re: miniaudio.h
Turns out it was a missing audio format in the header for my device. I haxed it. All working, not a PB problem. Could still do with including the header without needing to compile a dll.
Re: miniaudio.h
It's conflicting type defs causing the issue and there's also the issue of mixed tool chains and crt to consider.
Re: miniaudio.h
also in the case where a function isn't referenced by PB use a prototype instead of using a dummy call to reference it
Code: Select all
!//gccflags -IC:\llvm-mingw-20211002-msvcrt-x86_64\lib\clang\13.0.0\include;
!//#include "E:\andrews\pbstuff\miniaudio\miniaudio.h";
!//useclang;
ImportC "miniaudio.lib" : EndImport
ProcedureC data_callback(*Device,*Output,*Input,frameCount)
Protected amount
If frameCount
!ma_device* pDevice;
!pDevice = p_device;
!v_amount = v_framecount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels);
If amount <> 0
CopyMemory(*input,*Output,amount)
EndIf
EndIf
EndProcedure
PrototypeC pcbcallback(*device,*output,*input,framecount)
Global pcb.pcbcallback
pcb = @data_callback() ;use a prototype set a refertence to the data_callbackotherwise pb won't include it
OpenConsole()
!ma_result result;
!ma_device_config deviceConfig;
!ma_device device;
!deviceConfig = ma_device_config_init(ma_device_type_duplex);
!deviceConfig.capture.pDeviceID = NULL;
!deviceConfig.capture.format = ma_format_s16;
!deviceConfig.capture.channels = 2;
!deviceConfig.capture.shareMode = ma_share_mode_shared;
!deviceConfig.playback.pDeviceID = NULL;
!deviceConfig.playback.format = ma_format_s16;
!deviceConfig.playback.channels = 2;
!deviceConfig.dataCallback = v_pcb;;
!result = ma_device_init(NULL, &deviceConfig, &device);
!if (result != MA_SUCCESS) {
MessageRequester("error","failed to config")
End
!}
!ma_device_start(&device);
PrintN("press enter to end")
Input();
!ma_device_uninit(&device);
Re: miniaudio.h
So its a nightmareIt's conflicting type defs causing the issue and there's also the issue of mixed tool chains and crt to consider.
Re: miniaudio.h
Currently static linking is problematic on window, Purebasic uses and old CRT that predates the UCRT and I'm not sure if mingw supports that crt version of not.
Re: miniaudio.h
You could try the CRT from WDK 7.1.0. It's the last CRT (dated 2010) that works with PB out of the box. PB's msvcrt.lib is from 2004.
Et cetera is my worst enemy