#include "qemu/osdep.h"
#include "hw/hw.h"
+#include "qemu/log.h"
#include "qemu/audio.h"
#include "lm4549.h"
#include "migration/vmstate.h"
break;
case LM4549_PCM_Front_DAC_Rate:
- regfile[LM4549_PCM_Front_DAC_Rate] = value;
DPRINTF("DAC rate change = %i\n", value);
+ /*
+ * Valid sample rates are 4kHz to 48kHz.
+ * The datasheet doesn't say what happens if you try to
+ * set the frequency to zero. AUD_open_out() will print
+ * a bug message if we pass it a zero frequency, so just
+ * ignore attempts to set the DAC frequency to zero.
+ */
+ if (value < 4000 || value > 48000) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: DAC sample rate %d Hz is invalid, ignoring it\n",
+ __func__, value);
+ break;
+ }
+ regfile[LM4549_PCM_Front_DAC_Rate] = value;
+
/* Re-open a voice with the new sample rate */
struct audsettings as;
as.freq = value;