miniaudio.h

Just starting out? Need help? Post your questions and find answers here.
AndyMK
Enthusiast
Enthusiast
Posts: 540
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

miniaudio.h

Post by AndyMK »

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/
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: miniaudio.h

Post by Fred »

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.
AndyMK
Enthusiast
Enthusiast
Posts: 540
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: miniaudio.h

Post by AndyMK »

Hi Fred, will you include all of its functionality?
You need to add the include path on the GCC commandline
I have never done this before, can you explain?
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: miniaudio.h

Post by idle »

Fred, I can't get it working by including it

Code: Select all

!//gccflags -IC:\llvm-mingw-20211002-msvcrt-x86_64\lib\clang\13.0.0\include; 
!//#include "d:\miniaudio\miniaudio.c"; 
!//useclang;
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;
^
but I can get it working as a dll but it's tricky without an import.

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);

AndyMK
Enthusiast
Enthusiast
Posts: 540
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: miniaudio.h

Post by AndyMK »

Thanks idle, works fine although i had to rename the dll to miniaudio.dll
AndyMK
Enthusiast
Enthusiast
Posts: 540
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: miniaudio.h

Post by AndyMK »

exclusive mode does not seem to work. no sound, no errors and callback is passing buffers as normal.
AndyMK
Enthusiast
Enthusiast
Posts: 540
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: miniaudio.h

Post by AndyMK »

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.

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);
AndyMK
Enthusiast
Enthusiast
Posts: 540
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: miniaudio.h

Post by AndyMK »

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.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: miniaudio.h

Post by idle »

It's conflicting type defs causing the issue and there's also the issue of mixed tool chains and crt to consider.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: miniaudio.h

Post by idle »

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);


AndyMK
Enthusiast
Enthusiast
Posts: 540
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: miniaudio.h

Post by AndyMK »

It's conflicting type defs causing the issue and there's also the issue of mixed tool chains and crt to consider.
So its a nightmare :?
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: miniaudio.h

Post by idle »

AndyMK wrote: Thu Jul 07, 2022 1:56 pm
It's conflicting type defs causing the issue and there's also the issue of mixed tool chains and crt to consider.
So its a nightmare :?
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.
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: miniaudio.h

Post by chi »

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
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: miniaudio.h

Post by idle »

chi wrote: Fri Jul 08, 2022 5:32 am 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.
thanks will give it a go. I
Post Reply