]> Git Repo - qemu.git/blobdiff - audio/ossaudio.c
audio endianness API changes (malc)
[qemu.git] / audio / ossaudio.c
index 5072742491364dd322ea4538fbb06bdac229629f..125e4c8ff79395e2eb875d9bfb135dba5664045c 100644 (file)
@@ -55,12 +55,14 @@ static struct {
     int fragsize;
     const char *devpath_out;
     const char *devpath_in;
+    int debug;
 } conf = {
     .try_mmap = 0,
     .nfrags = 4,
     .fragsize = 4096,
     .devpath_out = "/dev/dsp",
-    .devpath_in = "/dev/dsp"
+    .devpath_in = "/dev/dsp",
+    .debug = 0
 };
 
 struct oss_params {
@@ -75,11 +77,11 @@ static void GCC_FMT_ATTR (2, 3) oss_logerr (int err, const char *fmt, ...)
 {
     va_list ap;
 
+    va_start (ap, fmt);
     AUD_vlog (AUDIO_CAP, fmt, ap);
+    va_end (ap);
 
-    va_start (ap, fmt);
     AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
-    va_end (ap);
 }
 
 static void GCC_FMT_ATTR (3, 4) oss_logerr2 (
@@ -324,9 +326,20 @@ static int oss_run_out (HWVoiceOut *hw)
             return 0;
         }
 
-        if (abinfo.bytes < 0 || abinfo.bytes > bufsize) {
-            ldebug ("warning: Invalid available size, size=%d bufsize=%d\n",
-                    abinfo.bytes, bufsize);
+        if (abinfo.bytes > bufsize) {
+            if (conf.debug) {
+                dolog ("warning: Invalid available size, size=%d bufsize=%d\n"
+                       "please report your OS/audio hw to [email protected]\n",
+                       abinfo.bytes, bufsize);
+            }
+            abinfo.bytes = bufsize;
+        }
+
+        if (abinfo.bytes < 0) {
+            if (conf.debug) {
+                dolog ("warning: Invalid available size, size=%d bufsize=%d\n",
+                       abinfo.bytes, bufsize);
+            }
             return 0;
         }
 
@@ -369,15 +382,12 @@ static int oss_run_out (HWVoiceOut *hw)
                            "alignment %d\n",
                            wbytes, written, hw->info.align + 1);
                 }
-                mixeng_clear (src, wsamples);
                 decr -= wsamples;
                 rpos = (rpos + wsamples) % hw->samples;
                 break;
             }
         }
 
-        mixeng_clear (src, convert_samples);
-
         rpos = (rpos + convert_samples) % hw->samples;
         samples -= convert_samples;
     }
@@ -422,6 +432,8 @@ static int oss_init_out (HWVoiceOut *hw, audsettings_t *as)
     audfmt_e effective_fmt;
     audsettings_t obt_as;
 
+    oss->fd = -1;
+
     req.fmt = aud_to_ossfmt (as->fmt);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
@@ -441,12 +453,9 @@ static int oss_init_out (HWVoiceOut *hw, audsettings_t *as)
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
     obt_as.fmt = effective_fmt;
+    obt_as.endianness = endianness;
 
-    audio_pcm_init_info (
-        &hw->info,
-        &obt_as,
-        audio_need_to_swap_endian (endianness)
-        );
+    audio_pcm_init_info (&hw->info, &obt_as);
     oss->nfrags = obt.nfrags;
     oss->fragsize = obt.fragsize;
 
@@ -506,8 +515,11 @@ static int oss_init_out (HWVoiceOut *hw, audsettings_t *as)
             1 << hw->info.shift
             );
         if (!oss->pcm_buf) {
-            dolog ("Could not allocate DAC buffer (%d bytes)\n",
-                   hw->samples << hw->info.shift);
+            dolog (
+                "Could not allocate DAC buffer (%d samples, each %d bytes)\n",
+                hw->samples,
+                1 << hw->info.shift
+                );
             oss_anal_close (&fd);
             return -1;
         }
@@ -562,6 +574,8 @@ static int oss_init_in (HWVoiceIn *hw, audsettings_t *as)
     audfmt_e effective_fmt;
     audsettings_t obt_as;
 
+    oss->fd = -1;
+
     req.fmt = aud_to_ossfmt (as->fmt);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
@@ -580,12 +594,9 @@ static int oss_init_in (HWVoiceIn *hw, audsettings_t *as)
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
     obt_as.fmt = effective_fmt;
+    obt_as.endianness = endianness;
 
-    audio_pcm_init_info (
-        &hw->info,
-        &obt_as,
-        audio_need_to_swap_endian (endianness)
-        );
+    audio_pcm_init_info (&hw->info, &obt_as);
     oss->nfrags = obt.nfrags;
     oss->fragsize = obt.fragsize;
 
@@ -597,8 +608,8 @@ static int oss_init_in (HWVoiceIn *hw, audsettings_t *as)
     hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
     oss->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
     if (!oss->pcm_buf) {
-        dolog ("Could not allocate ADC buffer (%d bytes)\n",
-               hw->samples << hw->info.shift);
+        dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
+               hw->samples, 1 << hw->info.shift);
         oss_anal_close (&fd);
         return -1;
     }
@@ -657,7 +668,7 @@ static int oss_run_in (HWVoiceIn *hw)
 
             if (nread > 0) {
                 if (nread & hw->info.align) {
-                    dolog ("warning: Misaligned read %d (requested %d), "
+                    dolog ("warning: Misaligned read %zd (requested %d), "
                            "alignment %d\n", nread, bufs[i].add << hwshift,
                            hw->info.align + 1);
                 }
@@ -723,6 +734,8 @@ static struct audio_option oss_options[] = {
      "Path to DAC device", NULL, 0},
     {"ADC_DEV", AUD_OPT_STR, &conf.devpath_in,
      "Path to ADC device", NULL, 0},
+    {"DEBUG", AUD_OPT_BOOL, &conf.debug,
+     "Turn on some debugging messages", NULL, 0},
     {NULL, 0, NULL, NULL, NULL, 0}
 };
 
This page took 0.029146 seconds and 4 git commands to generate.