Skip to content

Commit

Permalink
Added 32 bits floating poing samples support to Waveforminput plugin.…
Browse files Browse the repository at this point in the history
… Added support for multiple channels audio. Fixed a bug in Wasapi to open AudioClient for Channels > 2
  • Loading branch information
MarcoBellini committed Oct 21, 2023
1 parent add563a commit 3c474bd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
14 changes: 7 additions & 7 deletions WinAudio/WA_GEN_Playback_Engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,24 @@ bool WA_Playback_Engine_OpenFile(const wchar_t* lpwPath)

if (!PathFileExists(lpwPath))
{
MessageBox(Globals2.hMainWindow, L"File not Found", L"WinAudio Error", MB_OK | MB_ICONEXCLAMATION);
TaskDialog(Globals2.hMainWindow, Globals2.hMainWindowInstance, L"WinAudio Error", L"Unable to open input file", L"The file format is not found, try another file path", TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL);
return false;
}

pIn = WA_Playback_Engine_Find_Decoder(lpwPath);

if (!pIn)
{
MessageBox(Globals2.hMainWindow, L"File not Supported", L"WinAudio Error", MB_OK | MB_ICONEXCLAMATION);
{
TaskDialog(Globals2.hMainWindow, Globals2.hMainWindowInstance, L"WinAudio Error", L"Unable to open input file", L"The file format is not supported, try to add a proper plugin to support it", TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL);
return false;
}


uResult = pIn->WA_Input_Open(pIn, lpwPath);

if (uResult != WA_OK)
{
MessageBox(Globals2.hMainWindow, L"Input Plugin cannot open this file", L"WinAudio Error", MB_OK | MB_ICONEXCLAMATION);
{
TaskDialog(Globals2.hMainWindow, Globals2.hMainWindowInstance, L"WinAudio Error", L"Unable to open input file", L"The file format is not supported, or the input is not able to decode it", TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL);
return false;
}

Expand Down Expand Up @@ -174,8 +174,8 @@ bool WA_Playback_Engine_OpenFile(const wchar_t* lpwPath)

if (uResult != WA_OK)
{
WA_Playback_Engine_CloseFile();
MessageBox(Globals2.hMainWindow, L"Cannot open Output", L"WinAudio Error", MB_OK | MB_ICONEXCLAMATION);
pIn->WA_Input_Close(pIn);
TaskDialog(Globals2.hMainWindow, Globals2.hMainWindowInstance, L"WinAudio Error", L"Unable to open output", L"The file format is not supported, or the output is not active", TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL);
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions WinAudio_ParamEQ/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static HMODULE GetCurrentModuleHandle() {
return hModule;
}

static void WA_ParamEQ_Bytes_To_Float(WA_Effect* This, const int8_t* pByte, uint32_t uByteLen, double* pFloat, uint32_t uFloatLen)
static void WA_ParamEQ_Bytes_To_Double(WA_Effect* This, const int8_t* pByte, uint32_t uByteLen, double* pFloat, uint32_t uFloatLen)
{
WA_ParamEQ_Intance* pInstance = (WA_ParamEQ_Intance*)This->hPluginData;
uint32_t uSampleSize, uTotalSamples, uFloatSample;
Expand Down Expand Up @@ -350,7 +350,7 @@ uint32_t WA_ParamEQ_Process(WA_Effect* This, int8_t* pBuffer, uint32_t uBufferLe
if (!pDouble)
return WA_ERROR_MALLOCERROR;

WA_ParamEQ_Bytes_To_Float(This, pBuffer, uBufferLen, pDouble, uDoubleLen);
WA_ParamEQ_Bytes_To_Double(This, pBuffer, uBufferLen, pDouble, uDoubleLen);

if (pInstance->bEnableBoost)
{
Expand Down
4 changes: 2 additions & 2 deletions WinAudio_Wasapi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ uint32_t WA_Wasapi_Open(WA_Output* This, uint32_t* puBufferLatency)


// Create Input Stream WaveFormat and Store Locally
pWfx->Format.cbSize = 0;
pWfx->Format.wFormatTag = WAVE_FORMAT_PCM;
pWfx->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
pWfx->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
pWfx->SubFormat = WASAPI_KSDATAFORMAT_SUBTYPE_PCM;
pWfx->Format.nSamplesPerSec = (DWORD)WAFormat.uSamplerate;

Expand Down
53 changes: 52 additions & 1 deletion WinAudio_Waveform/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,56 @@ static uint32_t WA_Sndlib_ReadFormat(SF_INFO* Info, WA_AudioFormat* pFormat)
pFormat->uBitsPerSample = 32;
pFormat->uSampleType = WA_SIGNED_SAMPLE;
break;
case SF_FORMAT_FLOAT:
pFormat->uBitsPerSample = 32;
pFormat->uSampleType = WA_SIGNED_SAMPLE;
break;
default:
return WA_ERROR_FILENOTSUPPORTED;
}

pFormat->uBlockAlign = (pFormat->uBitsPerSample / 8) * pFormat->uChannels;
pFormat->uAvgBytesPerSec = pFormat->uSamplerate * pFormat->uBlockAlign;



/*
Prepare Channel Mask on (Channels > 2)
see https://learn.microsoft.com/en-us/previous-versions/windows/hardware/design/dn653308(v=vs.85)?redirectedfrom=MSDN
Channel Order:
Front Left - FL
Front Right - FR
Front Center - FC
Low Frequency - LF
Back Left - BL
Back Right - BR
Front Left of Center - FLC
Front Right of Center - FRC
Back Center - BC
Side Left - SL
Side Right - SR
Top Center - TC
Top Front Left - TFL
Top Front Center - TFC
Top Front Right - TFR
Top Back Left - TBL
Top Back Center - TBC
Top Back Right - TBR
*/

pFormat->dwChannelMask = 0;

if ((pFormat->uChannels > 2) && (pFormat->uChannels <= 18))
{

for (uint32_t i = 0U; i < pFormat->uChannels; i++)
{
pFormat->dwChannelMask |= (uint64_t) 1 << i;
}
}

return WA_OK;
}

Expand Down Expand Up @@ -222,7 +265,15 @@ uint32_t WA_Sndlib_Open(WA_Input* This, const wchar_t* lpwFilePath)
pInstance->bCastToSigned = ((Info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_PCM_U8) ? true : false;
pInstance->bStreamIsSeekable = (Info.seekable > 0) ? true : false;
pInstance->uPosition = 0U;
pInstance->uDuration = (Info.frames / Info.samplerate) * 1000;
pInstance->uDuration = (Info.frames / Info.samplerate) * 1000;

// Scale data when libsndfile convert from floating-point to int data
// using sf_readf_int function
if (((Info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_FLOAT))
{
//SFC_SET_SCALE_FLOAT_INT_READ
sf_command(pInstance->pSndFile, SFC_SET_SCALE_FLOAT_INT_READ, NULL, TRUE);
}

nPathLen = wcslen(lpwFilePath) + 1; // Inlcude Null-Terminating char
pInstance->pCurrentPath = NULL;
Expand Down

0 comments on commit 3c474bd

Please sign in to comment.