3 #include "qemu/osdep.h"
5 #define AUDIO_CAP "win-int"
11 #include "audio_int.h"
12 #include "audio_win_int.h"
14 int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
15 struct audsettings *as)
17 memset (wfx, 0, sizeof (*wfx));
19 wfx->nChannels = as->nchannels;
20 wfx->nSamplesPerSec = as->freq;
21 wfx->nAvgBytesPerSec = as->freq << (as->nchannels == 2);
22 wfx->nBlockAlign = 1 << (as->nchannels == 2);
28 wfx->wFormatTag = WAVE_FORMAT_PCM;
29 wfx->wBitsPerSample = 8;
32 case AUDIO_FORMAT_S16:
33 case AUDIO_FORMAT_U16:
34 wfx->wFormatTag = WAVE_FORMAT_PCM;
35 wfx->wBitsPerSample = 16;
36 wfx->nAvgBytesPerSec <<= 1;
37 wfx->nBlockAlign <<= 1;
40 case AUDIO_FORMAT_S32:
41 case AUDIO_FORMAT_U32:
42 wfx->wFormatTag = WAVE_FORMAT_PCM;
43 wfx->wBitsPerSample = 32;
44 wfx->nAvgBytesPerSec <<= 2;
45 wfx->nBlockAlign <<= 2;
48 case AUDIO_FORMAT_F32:
49 wfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
50 wfx->wBitsPerSample = 32;
51 wfx->nAvgBytesPerSec <<= 2;
52 wfx->nBlockAlign <<= 2;
56 dolog("Internal logic error: Bad audio format %d\n", as->fmt);
63 int waveformat_to_audio_settings (WAVEFORMATEX *wfx,
64 struct audsettings *as)
66 if (!wfx->nSamplesPerSec) {
67 dolog ("Invalid wave format, frequency is zero\n");
70 as->freq = wfx->nSamplesPerSec;
72 switch (wfx->nChannels) {
83 "Invalid wave format, number of channels is not 1 or 2, but %d\n",
89 if (wfx->wFormatTag == WAVE_FORMAT_PCM) {
90 switch (wfx->wBitsPerSample) {
92 as->fmt = AUDIO_FORMAT_U8;
96 as->fmt = AUDIO_FORMAT_S16;
100 as->fmt = AUDIO_FORMAT_S32;
104 dolog("Invalid PCM wave format, bits per sample is not "
105 "8, 16 or 32, but %d\n",
106 wfx->wBitsPerSample);
109 } else if (wfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) {
110 switch (wfx->wBitsPerSample) {
112 as->fmt = AUDIO_FORMAT_F32;
116 dolog("Invalid IEEE_FLOAT wave format, bits per sample is not "
118 wfx->wBitsPerSample);
122 dolog("Invalid wave format, tag is not PCM and not IEEE_FLOAT, "