| 35 |
} WAVVoiceOut; |
} WAVVoiceOut; |
| 36 |
|
|
| 37 |
static struct { |
static struct { |
| 38 |
|
audsettings_t settings; |
| 39 |
const char *wav_path; |
const char *wav_path; |
| 40 |
} conf = { |
} conf = { |
| 41 |
.wav_path = "qemu.wav" |
{ |
| 42 |
|
44100, |
| 43 |
|
2, |
| 44 |
|
AUD_FMT_S16 |
| 45 |
|
}, |
| 46 |
|
"qemu.wav" |
| 47 |
}; |
}; |
| 48 |
|
|
| 49 |
static int wav_run_out (HWVoiceOut *hw) |
static int wav_run_out (HWVoiceOut *hw) |
| 107 |
} |
} |
| 108 |
} |
} |
| 109 |
|
|
| 110 |
static int wav_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
static int wav_init_out (HWVoiceOut *hw, audsettings_t *as) |
| 111 |
{ |
{ |
| 112 |
WAVVoiceOut *wav = (WAVVoiceOut *) hw; |
WAVVoiceOut *wav = (WAVVoiceOut *) hw; |
| 113 |
int bits16; |
int bits16 = 0, stereo = 0; |
| 114 |
uint8_t hdr[] = { |
uint8_t hdr[] = { |
| 115 |
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, |
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, |
| 116 |
0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, |
0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 117 |
0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, |
0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, |
| 118 |
0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00 |
0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00 |
| 119 |
}; |
}; |
| 120 |
|
audsettings_t wav_as = conf.settings; |
| 121 |
|
|
| 122 |
freq = audio_state.fixed_freq_out; |
(void) as; |
|
fmt = audio_state.fixed_fmt_out; |
|
|
nchannels = audio_state.fixed_channels_out; |
|
| 123 |
|
|
| 124 |
switch (fmt) { |
stereo = wav_as.nchannels == 2; |
| 125 |
|
switch (wav_as.fmt) { |
| 126 |
case AUD_FMT_S8: |
case AUD_FMT_S8: |
| 127 |
case AUD_FMT_U8: |
case AUD_FMT_U8: |
| 128 |
bits16 = 0; |
bits16 = 0; |
| 132 |
case AUD_FMT_U16: |
case AUD_FMT_U16: |
| 133 |
bits16 = 1; |
bits16 = 1; |
| 134 |
break; |
break; |
|
|
|
|
default: |
|
|
dolog ("Internal logic error bad format %d\n", fmt); |
|
|
return -1; |
|
| 135 |
} |
} |
| 136 |
|
|
| 137 |
hdr[34] = bits16 ? 0x10 : 0x08; |
hdr[34] = bits16 ? 0x10 : 0x08; |
| 138 |
audio_pcm_init_info ( |
|
| 139 |
&hw->info, |
audio_pcm_init_info (&hw->info, &wav_as, audio_need_to_swap_endian (0)); |
| 140 |
freq, |
|
| 141 |
nchannels, |
hw->samples = 1024; |
| 142 |
bits16 ? AUD_FMT_S16 : AUD_FMT_U8, |
wav->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); |
|
audio_need_to_swap_endian (0) |
|
|
); |
|
|
hw->bufsize = 4096; |
|
|
wav->pcm_buf = qemu_mallocz (hw->bufsize); |
|
| 143 |
if (!wav->pcm_buf) { |
if (!wav->pcm_buf) { |
| 144 |
dolog ("Can not initialize WAV buffer of %d bytes\n", |
dolog ("Could not allocate buffer (%d bytes)\n", |
| 145 |
hw->bufsize); |
hw->samples << hw->info.shift); |
| 146 |
return -1; |
return -1; |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
le_store (hdr + 22, hw->info.nchannels, 2); |
le_store (hdr + 22, hw->info.nchannels, 2); |
| 150 |
le_store (hdr + 24, hw->info.freq, 4); |
le_store (hdr + 24, hw->info.freq, 4); |
| 151 |
le_store (hdr + 28, hw->info.freq << (bits16 + (nchannels == 2)), 4); |
le_store (hdr + 28, hw->info.freq << (bits16 + stereo), 4); |
| 152 |
le_store (hdr + 32, 1 << (bits16 + (nchannels == 2)), 2); |
le_store (hdr + 32, 1 << (bits16 + stereo), 2); |
| 153 |
|
|
| 154 |
wav->f = fopen (conf.wav_path, "wb"); |
wav->f = fopen (conf.wav_path, "wb"); |
| 155 |
if (!wav->f) { |
if (!wav->f) { |
| 173 |
uint32_t rifflen = (wav->total_samples << stereo) + 36; |
uint32_t rifflen = (wav->total_samples << stereo) + 36; |
| 174 |
uint32_t datalen = wav->total_samples << stereo; |
uint32_t datalen = wav->total_samples << stereo; |
| 175 |
|
|
| 176 |
if (!wav->f || !hw->active) { |
if (!wav->f) { |
| 177 |
return; |
return; |
| 178 |
} |
} |
| 179 |
|
|
| 212 |
} |
} |
| 213 |
|
|
| 214 |
struct audio_option wav_options[] = { |
struct audio_option wav_options[] = { |
| 215 |
|
{"FREQUENCY", AUD_OPT_INT, &conf.settings.freq, |
| 216 |
|
"Frequency", NULL, 0}, |
| 217 |
|
|
| 218 |
|
{"FORMAT", AUD_OPT_FMT, &conf.settings.fmt, |
| 219 |
|
"Format", NULL, 0}, |
| 220 |
|
|
| 221 |
|
{"DAC_FIXED_CHANNELS", AUD_OPT_INT, &conf.settings.nchannels, |
| 222 |
|
"Number of channels (1 - mono, 2 - stereo)", NULL, 0}, |
| 223 |
|
|
| 224 |
{"PATH", AUD_OPT_STR, &conf.wav_path, |
{"PATH", AUD_OPT_STR, &conf.wav_path, |
| 225 |
"Path to wave file", NULL, 0}, |
"Path to wave file", NULL, 0}, |
| 226 |
{NULL, 0, NULL, NULL, NULL, 0} |
{NULL, 0, NULL, NULL, NULL, 0} |