iotests: Only create BB if necessary
[qemu.git] / audio / audio_win_int.c
blobe1324056a47949e5442e2300b597b8a560d3b9e2
1 /* public domain */
3 #include "qemu-common.h"
5 #define AUDIO_CAP "win-int"
6 #include <windows.h>
7 #include <mmsystem.h>
9 #include "audio.h"
10 #include "audio_int.h"
11 #include "audio_win_int.h"
13 int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
14 struct audsettings *as)
16 memset (wfx, 0, sizeof (*wfx));
18 wfx->wFormatTag = WAVE_FORMAT_PCM;
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);
23 wfx->cbSize = 0;
25 switch (as->fmt) {
26 case AUD_FMT_S8:
27 case AUD_FMT_U8:
28 wfx->wBitsPerSample = 8;
29 break;
31 case AUD_FMT_S16:
32 case AUD_FMT_U16:
33 wfx->wBitsPerSample = 16;
34 wfx->nAvgBytesPerSec <<= 1;
35 wfx->nBlockAlign <<= 1;
36 break;
38 case AUD_FMT_S32:
39 case AUD_FMT_U32:
40 wfx->wBitsPerSample = 32;
41 wfx->nAvgBytesPerSec <<= 2;
42 wfx->nBlockAlign <<= 2;
43 break;
45 default:
46 dolog ("Internal logic error: Bad audio format %d\n", as->freq);
47 return -1;
50 return 0;
53 int waveformat_to_audio_settings (WAVEFORMATEX *wfx,
54 struct audsettings *as)
56 if (wfx->wFormatTag != WAVE_FORMAT_PCM) {
57 dolog ("Invalid wave format, tag is not PCM, but %d\n",
58 wfx->wFormatTag);
59 return -1;
62 if (!wfx->nSamplesPerSec) {
63 dolog ("Invalid wave format, frequency is zero\n");
64 return -1;
66 as->freq = wfx->nSamplesPerSec;
68 switch (wfx->nChannels) {
69 case 1:
70 as->nchannels = 1;
71 break;
73 case 2:
74 as->nchannels = 2;
75 break;
77 default:
78 dolog (
79 "Invalid wave format, number of channels is not 1 or 2, but %d\n",
80 wfx->nChannels
82 return -1;
85 switch (wfx->wBitsPerSample) {
86 case 8:
87 as->fmt = AUD_FMT_U8;
88 break;
90 case 16:
91 as->fmt = AUD_FMT_S16;
92 break;
94 case 32:
95 as->fmt = AUD_FMT_S32;
96 break;
98 default:
99 dolog ("Invalid wave format, bits per sample is not "
100 "8, 16 or 32, but %d\n",
101 wfx->wBitsPerSample);
102 return -1;
105 return 0;