dsoundaudio: enable f32 audio sample format
Enable the f32 audio sample format for the DirectSound backend. Signed-off-by: Volker Rümelin <vr_qemu@t-online.de> Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de Message-Id: <20210110100239.27588-22-vr_qemu@t-online.de> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
3c18e43179
commit
1157506161
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#define AUDIO_CAP "win-int"
|
#define AUDIO_CAP "win-int"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <mmreg.h>
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
|
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
@ -16,7 +17,6 @@ int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
|
|||||||
{
|
{
|
||||||
memset (wfx, 0, sizeof (*wfx));
|
memset (wfx, 0, sizeof (*wfx));
|
||||||
|
|
||||||
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
|
||||||
wfx->nChannels = as->nchannels;
|
wfx->nChannels = as->nchannels;
|
||||||
wfx->nSamplesPerSec = as->freq;
|
wfx->nSamplesPerSec = as->freq;
|
||||||
wfx->nAvgBytesPerSec = as->freq << (as->nchannels == 2);
|
wfx->nAvgBytesPerSec = as->freq << (as->nchannels == 2);
|
||||||
@ -26,11 +26,13 @@ int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
|
|||||||
switch (as->fmt) {
|
switch (as->fmt) {
|
||||||
case AUDIO_FORMAT_S8:
|
case AUDIO_FORMAT_S8:
|
||||||
case AUDIO_FORMAT_U8:
|
case AUDIO_FORMAT_U8:
|
||||||
|
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
||||||
wfx->wBitsPerSample = 8;
|
wfx->wBitsPerSample = 8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUDIO_FORMAT_S16:
|
case AUDIO_FORMAT_S16:
|
||||||
case AUDIO_FORMAT_U16:
|
case AUDIO_FORMAT_U16:
|
||||||
|
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
||||||
wfx->wBitsPerSample = 16;
|
wfx->wBitsPerSample = 16;
|
||||||
wfx->nAvgBytesPerSec <<= 1;
|
wfx->nAvgBytesPerSec <<= 1;
|
||||||
wfx->nBlockAlign <<= 1;
|
wfx->nBlockAlign <<= 1;
|
||||||
@ -38,6 +40,14 @@ int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
|
|||||||
|
|
||||||
case AUDIO_FORMAT_S32:
|
case AUDIO_FORMAT_S32:
|
||||||
case AUDIO_FORMAT_U32:
|
case AUDIO_FORMAT_U32:
|
||||||
|
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
||||||
|
wfx->wBitsPerSample = 32;
|
||||||
|
wfx->nAvgBytesPerSec <<= 2;
|
||||||
|
wfx->nBlockAlign <<= 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_FORMAT_F32:
|
||||||
|
wfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
|
||||||
wfx->wBitsPerSample = 32;
|
wfx->wBitsPerSample = 32;
|
||||||
wfx->nAvgBytesPerSec <<= 2;
|
wfx->nAvgBytesPerSec <<= 2;
|
||||||
wfx->nBlockAlign <<= 2;
|
wfx->nBlockAlign <<= 2;
|
||||||
@ -54,12 +64,6 @@ int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
|
|||||||
int waveformat_to_audio_settings (WAVEFORMATEX *wfx,
|
int waveformat_to_audio_settings (WAVEFORMATEX *wfx,
|
||||||
struct audsettings *as)
|
struct audsettings *as)
|
||||||
{
|
{
|
||||||
if (wfx->wFormatTag != WAVE_FORMAT_PCM) {
|
|
||||||
dolog ("Invalid wave format, tag is not PCM, but %d\n",
|
|
||||||
wfx->wFormatTag);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wfx->nSamplesPerSec) {
|
if (!wfx->nSamplesPerSec) {
|
||||||
dolog ("Invalid wave format, frequency is zero\n");
|
dolog ("Invalid wave format, frequency is zero\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -83,23 +87,42 @@ int waveformat_to_audio_settings (WAVEFORMATEX *wfx,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (wfx->wBitsPerSample) {
|
if (wfx->wFormatTag == WAVE_FORMAT_PCM) {
|
||||||
case 8:
|
switch (wfx->wBitsPerSample) {
|
||||||
as->fmt = AUDIO_FORMAT_U8;
|
case 8:
|
||||||
break;
|
as->fmt = AUDIO_FORMAT_U8;
|
||||||
|
break;
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
as->fmt = AUDIO_FORMAT_S16;
|
as->fmt = AUDIO_FORMAT_S16;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 32:
|
case 32:
|
||||||
as->fmt = AUDIO_FORMAT_S32;
|
as->fmt = AUDIO_FORMAT_S32;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dolog ("Invalid wave format, bits per sample is not "
|
dolog("Invalid PCM wave format, bits per sample is not "
|
||||||
"8, 16 or 32, but %d\n",
|
"8, 16 or 32, but %d\n",
|
||||||
wfx->wBitsPerSample);
|
wfx->wBitsPerSample);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (wfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) {
|
||||||
|
switch (wfx->wBitsPerSample) {
|
||||||
|
case 32:
|
||||||
|
as->fmt = AUDIO_FORMAT_F32;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
dolog("Invalid IEEE_FLOAT wave format, bits per sample is not "
|
||||||
|
"32, but %d\n",
|
||||||
|
wfx->wBitsPerSample);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dolog("Invalid wave format, tag is not PCM and not IEEE_FLOAT, "
|
||||||
|
"but %d\n",
|
||||||
|
wfx->wFormatTag);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user