Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CNFA.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void RegCNFADriver( int priority, const char * name, CNFAInitFn * fn );
#if CNFA_WINDOWS
#include "CNFA_winmm.c"
#include <ntverp.h> // This probably won't work on pre-NT systems
#if VER_PRODUCTBUILD >= 7601
#if (VER_PRODUCTBUILD >= 7601 || defined(TCC)) // TCC can't seem to figure out NT versions?
#include "CNFA_wasapi.c"
#endif
#elif CNFA_ANDROID
Expand Down
469 changes: 294 additions & 175 deletions CNFA_wasapi.c

Large diffs are not rendered by default.

207 changes: 207 additions & 0 deletions CNFA_wasapi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,19 @@ typedef struct IMMNotificationClient IMMNotificationClient;
typedef struct IPropertyStore IPropertyStore;
typedef struct IAudioClient IAudioClient;
typedef struct IAudioCaptureClient IAudioCaptureClient;
typedef struct IAudioRenderClient IAudioRenderClient;
typedef struct IAudioSessionControl IAudioSessionControl;
typedef struct IAudioSessionEvents IAudioSessionEvents;

// So the linker doesn't complain
extern const IID CLSID_MMDeviceEnumerator;
extern const IID IID_IMMDeviceEnumerator;
extern const IID IID_IAudioClient;
extern const IID CNFA_GUID;
extern const IID IID_IAudioCaptureClient;
extern const IID IID_IAudioRenderClient;
extern const IID IID_IAudioSessionControl;
extern const IID IID_IAudioSessionEvents;

typedef enum __MIDL___MIDL_itf_mmdeviceapi_0000_0000_0001
{
Expand Down Expand Up @@ -596,6 +602,47 @@ interface IAudioCaptureClient
CONST_VTBL struct IAudioCaptureClientVtbl *lpVtbl;
};

typedef struct IAudioRenderClientVtbl
{
BEGIN_INTERFACE


HRESULT(STDMETHODCALLTYPE* QueryInterface)(
IAudioRenderClient* This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void** ppvObject);


ULONG(STDMETHODCALLTYPE* AddRef)(
IAudioRenderClient* This);

ULONG(STDMETHODCALLTYPE* Release)(
IAudioRenderClient* This);

HRESULT(STDMETHODCALLTYPE* GetBuffer)(
IAudioRenderClient* This,
/* [annotation][in] */
_In_ UINT32 NumFramesRequested,
/* [annotation][out] */
_Outptr_result_buffer_(_Inexpressible_("NumFramesRequested * pFormat->nBlockAlign")) BYTE** ppData);

HRESULT(STDMETHODCALLTYPE* ReleaseBuffer)(
IAudioRenderClient* This,
/* [annotation][in] */
_In_ UINT32 NumFramesWritten,
/* [annotation][in] */
_In_ DWORD dwFlags);

END_INTERFACE
} IAudioRenderClientVtbl;

interface IAudioRenderClient
{
CONST_VTBL struct IAudioRenderClientVtbl* lpVtbl;
};


typedef interface IMMEndpoint IMMEndpoint;

typedef struct IMMEndpointVtbl
Expand Down Expand Up @@ -627,6 +674,166 @@ typedef interface IMMEndpoint IMMEndpoint;
CONST_VTBL struct IMMEndpointVtbl *lpVtbl;
};

typedef enum _AudioSessionState
{
AudioSessionStateInactive = 0,
AudioSessionStateActive = 1,
AudioSessionStateExpired = 2
} AudioSessionState;

typedef enum AudioSessionDisconnectReason
{
DisconnectReasonDeviceRemoval = 0,
DisconnectReasonServerShutdown = (DisconnectReasonDeviceRemoval + 1),
DisconnectReasonFormatChanged = (DisconnectReasonServerShutdown + 1),
DisconnectReasonSessionLogoff = (DisconnectReasonFormatChanged + 1),
DisconnectReasonSessionDisconnected = (DisconnectReasonSessionLogoff + 1),
DisconnectReasonExclusiveModeOverride = (DisconnectReasonSessionDisconnected + 1)
} AudioSessionDisconnectReason;

typedef struct IAudioSessionEventsVtbl
{
BEGIN_INTERFACE

HRESULT(STDMETHODCALLTYPE* QueryInterface)(
IAudioSessionEvents* This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void** ppvObject);

ULONG(STDMETHODCALLTYPE* AddRef)(
IAudioSessionEvents* This);

ULONG(STDMETHODCALLTYPE* Release)(
IAudioSessionEvents* This);

HRESULT(STDMETHODCALLTYPE* OnDisplayNameChanged)(
IAudioSessionEvents* This,
/* [annotation][string][in] */
_In_ LPCWSTR NewDisplayName,
/* [in] */ LPCGUID EventContext);

HRESULT(STDMETHODCALLTYPE* OnIconPathChanged)(
IAudioSessionEvents* This,
/* [annotation][string][in] */
_In_ LPCWSTR NewIconPath,
/* [in] */ LPCGUID EventContext);

HRESULT(STDMETHODCALLTYPE* OnSimpleVolumeChanged)(
IAudioSessionEvents* This,
/* [annotation][in] */
_In_ float NewVolume,
/* [annotation][in] */
_In_ BOOL NewMute,
/* [in] */ LPCGUID EventContext);

HRESULT(STDMETHODCALLTYPE* OnChannelVolumeChanged)(
IAudioSessionEvents* This,
/* [annotation][in] */
_In_ DWORD ChannelCount,
/* [annotation][size_is][in] */
float NewChannelVolumeArray[],
/* [annotation][in] */
_In_ DWORD ChangedChannel,
/* [in] */ LPCGUID EventContext);

HRESULT(STDMETHODCALLTYPE* OnGroupingParamChanged)(
IAudioSessionEvents* This,
/* [annotation][in] */
_In_ LPCGUID NewGroupingParam,
/* [in] */ LPCGUID EventContext);

HRESULT(STDMETHODCALLTYPE* OnStateChanged)(
IAudioSessionEvents* This,
/* [annotation][in] */
_In_ AudioSessionState NewState);

HRESULT(STDMETHODCALLTYPE* OnSessionDisconnected)(
IAudioSessionEvents* This,
/* [annotation][in] */
_In_ AudioSessionDisconnectReason DisconnectReason);

END_INTERFACE
} IAudioSessionEventsVtbl;

interface IAudioSessionEvents
{
CONST_VTBL struct IAudioSessionEventsVtbl* lpVtbl;
};

typedef struct IAudioSessionControlVtbl
{
BEGIN_INTERFACE

HRESULT(STDMETHODCALLTYPE* QueryInterface)(
IAudioSessionControl* This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void** ppvObject);

ULONG(STDMETHODCALLTYPE* AddRef)(
IAudioSessionControl* This);

ULONG(STDMETHODCALLTYPE* Release)(
IAudioSessionControl* This);

HRESULT(STDMETHODCALLTYPE* GetState)(
IAudioSessionControl* This,
/* [annotation][out] */
_Out_ AudioSessionState* pRetVal);

HRESULT(STDMETHODCALLTYPE* GetDisplayName)(
IAudioSessionControl* This,
/* [annotation][string][out] */
_Out_ LPWSTR* pRetVal);

HRESULT(STDMETHODCALLTYPE* SetDisplayName)(
IAudioSessionControl* This,
/* [annotation][string][in] */
_In_ LPCWSTR Value,
/* [unique][in] */ LPCGUID EventContext);

HRESULT(STDMETHODCALLTYPE* GetIconPath)(
IAudioSessionControl* This,
/* [annotation][string][out] */
_Out_ LPWSTR* pRetVal);

HRESULT(STDMETHODCALLTYPE* SetIconPath)(
IAudioSessionControl* This,
/* [annotation][string][in] */
_In_ LPCWSTR Value,
/* [unique][in] */ LPCGUID EventContext);

HRESULT(STDMETHODCALLTYPE* GetGroupingParam)(
IAudioSessionControl* This,
/* [annotation][out] */
_Out_ GUID* pRetVal);

HRESULT(STDMETHODCALLTYPE* SetGroupingParam)(
IAudioSessionControl* This,
/* [annotation][in] */
_In_ LPCGUID Override,
/* [unique][in] */ LPCGUID EventContext);

HRESULT(STDMETHODCALLTYPE* RegisterAudioSessionNotification)(
IAudioSessionControl* This,
/* [annotation][in] */
_In_ IAudioSessionEvents* NewNotifications);

HRESULT(STDMETHODCALLTYPE* UnregisterAudioSessionNotification)(
IAudioSessionControl* This,
/* [annotation][in] */
_In_ IAudioSessionEvents* NewNotifications);

END_INTERFACE
} IAudioSessionControlVtbl;

interface IAudioSessionControl
{
CONST_VTBL struct IAudioSessionControlVtbl* lpVtbl;
};


#define DEVICE_STATE_ACTIVE 0x00000001
#define DEVICE_STATE_DISABLED 0x00000002
#define DEVICE_STATE_NOTPRESENT 0x00000004
Expand Down
14 changes: 7 additions & 7 deletions example.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include <stdio.h>
#include <math.h>

#ifdef CNFA_WINDOWS
#include <windows.h>
#define sleep(time_s) Sleep((time_s) * 1000)
#else
#include <unistd.h>
#endif

// If using the shared library, don't define CNFA_IMPLEMENTATION
// (it's already in the library).
#ifndef USE_SHARED
#define CNFA_IMPLEMENTATION
#endif
#include "CNFA.h"

#ifdef CNFA_WINDOWS
#include <windows.h>
#define sleep(time_s) Sleep((time_s) * 1000)
#else
#include <unistd.h>
#endif

#define RUNTIME 5

double omega = 0;
Expand Down
2 changes: 1 addition & 1 deletion wave_player/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
C_SRCS = wav_player.c
OUT := wav_player

CFLAGS = -O2 -g -DUSE_SHARED
CFLAGS = -O2 -I../. -g -DUSE_SHARED
LDFLAGS = -L../. -Wl,-rpath,. -lCNFA -lm
CC ?= gcc -std=c99

Expand Down
6 changes: 3 additions & 3 deletions wave_player/wavDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <stdint.h>

//#define ABSOLUTE 1
#ifdef ABSOLUTE
//#define WAV_ABSOLUTE_OFFSETS 1
#ifdef WAV_ABSOLUTE_OFFSETS

//absolute offsets PCM audacity files only
// name offset description
Expand Down Expand Up @@ -60,7 +60,7 @@
//1 - 8 bit mono, 2 - 8 bit stereo/16 bit mono, 4 - 16 bit stereo
#define BITS_PER_SAMPLE 22 //bits per channel 8 or 16 (unsigned char)

#endif //ABSOLUTE
#endif //WAV_ABSOLUTE_OFFSETS

#define MAX_TAG_SIZE 100 //defines the maximum number of characters to be allocated for any info string

Expand Down
6 changes: 3 additions & 3 deletions wave_player/wav_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include "os_generic.h"

#include "wavDefs.h"

Expand Down Expand Up @@ -90,7 +90,7 @@ int main (int nargs, char** args) {
filename = args[1];
}
else {
printf("\nError, no input file\nUseage %s <wave file>\n", args[0]);
printf("\nError, no input file\nUsage %s <wave file>\n", args[0]);
return 1;
}
wav_file = fopen(filename, "r");
Expand Down Expand Up @@ -123,7 +123,7 @@ int main (int nargs, char** args) {
const char* glyph = spin_glyph;
int i = 0;
while (!is_done){
sleep(1);
OGUSleep(1000000);
++runtime;
printf("\r %c ", *glyph++);
fflush(stdout);
Expand Down