audio: use muldiv64 where it makes sense
authormalc <av1474@comtv.ru>
Fri, 18 Sep 2009 04:16:03 +0000 (08:16 +0400)
committermalc <av1474@comtv.ru>
Fri, 18 Sep 2009 10:04:36 +0000 (14:04 +0400)
Signed-off-by: malc <av1474@comtv.ru>
audio/audio.c
audio/audio_template.h
audio/noaudio.c
audio/wavaudio.c
hw/gus.c
hw/sb16.c

index d8e54961fe3b37114505b66d83a0b3975f292be7..a3e23b212b6cbc8795276d463ccb4b16d81b77f0 100644 (file)
@@ -1878,7 +1878,8 @@ static void audio_init (void)
         }
         conf.period.ticks = 1;
     } else {
-        conf.period.ticks = get_ticks_per_sec() / conf.period.hertz;
+        conf.period.ticks =
+            muldiv64 (1, get_ticks_per_sec (), conf.period.hertz);
     }
 
     e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
index e65d834ac91566ecff49040ab585bd823553eaf7..70c4a8818b03a7030e0b203dd0375815b2c978e3 100644 (file)
@@ -556,7 +556,7 @@ uint64_t glue (AUD_get_elapsed_usec_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts)
         return 0;
     }
 
-    return (delta * sw->hw->info.freq) / 1000000;
+    return muldiv64 (delta, sw->hw->info.freq, 1000000);
 }
 
 #undef TYPE
index 2f25f176e21b5e6ed12f01ef00575320a25121c3..82272b7199595c4d9a8191f81cd085dfcd6c9174 100644 (file)
@@ -53,7 +53,7 @@ static int no_run_out (HWVoiceOut *hw)
 
     now = qemu_get_clock (vm_clock);
     ticks = now - no->old_ticks;
-    bytes = (ticks * hw->info.bytes_per_second) / get_ticks_per_sec();
+    bytes = muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
     bytes = audio_MIN (bytes, INT_MAX);
     samples = bytes >> hw->info.shift;
 
@@ -109,7 +109,8 @@ static int no_run_in (HWVoiceIn *hw)
     if (dead) {
         int64_t now = qemu_get_clock (vm_clock);
         int64_t ticks = now - no->old_ticks;
-        int64_t bytes = (ticks * hw->info.bytes_per_second) / get_ticks_per_sec();
+        int64_t bytes =
+            muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
 
         no->old_ticks = now;
         bytes = audio_MIN (bytes, INT_MAX);
index 78eb758bd635831135d773cc831928acab8834de..e659aa541ca8a15f7309578e0266d98ca6394b95 100644 (file)
@@ -54,7 +54,8 @@ static int wav_run_out (HWVoiceOut *hw)
     struct st_sample *src;
     int64_t now = qemu_get_clock (vm_clock);
     int64_t ticks = now - wav->old_ticks;
-    int64_t bytes = (ticks * hw->info.bytes_per_second) / get_ticks_per_sec();
+    int64_t bytes =
+        muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
 
     if (bytes > INT_MAX) {
         samples = INT_MAX >> hw->info.shift;
index 543b4ea68c4b46b42ce3debe9423e53ecd78cf72..c6b98b3ce4ebbf06f029a4ee60af03fce650f01b 100644 (file)
--- a/hw/gus.c
+++ b/hw/gus.c
@@ -156,8 +156,8 @@ static void GUS_callback (void *opaque, int free)
     }
     s->left = samples;
 
-reset:
-    gus_irqgen (&s->emu, (double) (net * 1000000) / s->freq);
+ reset:
+    gus_irqgen (&s->emu, muldiv64 (net, 1000000, s->freq));
 }
 
 int GUS_irqrequest (GUSEmuState *emu, int hwirq, int n)
index a222e21eefacf11d66ebaa97584c0e4b4d6cc478..8654b7d47e752e3cb2023c7c7b03143779e3b826 100644 (file)
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -758,8 +758,8 @@ static void complete (SB16State *s)
                 freq = s->freq > 0 ? s->freq : 11025;
                 samples = dsp_get_lohi (s) + 1;
                 bytes = samples << s->fmt_stereo << (s->fmt_bits == 16);
-                ticks = (bytes * get_ticks_per_sec()) / freq;
-                if (ticks < get_ticks_per_sec() / 1024) {
+                ticks = muldiv64 (bytes, get_ticks_per_sec (), freq);
+                if (ticks < get_ticks_per_sec () / 1024) {
                     qemu_irq_raise (s->pic);
                 }
                 else {