changeset 16309:aa7829aa8428

reordered bps calculation
author henry
date Thu, 25 Aug 2005 21:46:32 +0000
parents 41278ab73e9b
children fb95057e370e
files libao2/ao_alsa.c
diffstat 1 files changed, 33 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/ao_alsa.c	Thu Aug 25 19:57:32 2005 +0000
+++ b/libao2/ao_alsa.c	Thu Aug 25 21:46:32 2005 +0000
@@ -284,7 +284,6 @@
     }
 
     ao_data.samplerate = rate_hz;
-    ao_data.bps = channels * rate_hz;
     ao_data.format = format;
     ao_data.channels = channels;
     ao_data.outburst = OUTBURST;
@@ -330,34 +329,6 @@
 	break;
       }
     
-    //setting bw according to the input-format. resolution seems to be always s16_le or
-    //u16_le so 32bit is probably obsolet. 
-    switch(alsa_format)
-      {
-      case SND_PCM_FORMAT_S8:
-      case SND_PCM_FORMAT_U8:
-	ao_data.bps *= 1;
-	break;
-      case SND_PCM_FORMAT_S16_LE:
-      case SND_PCM_FORMAT_U16_LE:
-      case SND_PCM_FORMAT_S16_BE:
-      case SND_PCM_FORMAT_U16_BE:
-	ao_data.bps *= 2;
-	break;
-      case SND_PCM_FORMAT_S32_LE:
-      case SND_PCM_FORMAT_S32_BE:
-      case SND_PCM_FORMAT_FLOAT_LE:
-	ao_data.bps *= 4;
-	break;
-      case -1:
-	mp_msg(MSGT_AO,MSGL_ERR,"alsa-init: invalid format (%s) requested - output disabled\n",af_fmt2str_short(format));
-	return(0);
-	break;
-      default:
-	ao_data.bps *= 2;
-	mp_msg(MSGT_AO,MSGL_WARN,"alsa-init: couldn't convert to right format. setting bps to: %d", ao_data.bps);
-      }
-
     //subdevice parsing
     // set defaults
     ao_mmap = 0;
@@ -537,12 +508,8 @@
 		"alsa-init: format %s are not supported by hardware, trying default\n", af_fmt2str_short(format));
          alsa_format = SND_PCM_FORMAT_S16_LE;
          ao_data.format = AF_FORMAT_S16_LE;
-         ao_data.bps = channels * rate_hz * 2;
       }
 
-      bytes_per_sample = ao_data.bps / ao_data.samplerate; //it should be here
-
-    
       if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams,
 					      alsa_format)) < 0)
 	{
@@ -567,6 +534,38 @@
 	  return(0);
         }
 
+    ao_data.bps = ao_data.channels * ao_data.samplerate;
+
+    //setting bw according to the input-format. resolution seems to be always s16_le or
+    //u16_le so 32bit is probably obsolet. 
+    switch(alsa_format)
+      {
+      case SND_PCM_FORMAT_S8:
+      case SND_PCM_FORMAT_U8:
+	ao_data.bps *= 1;
+	break;
+      case SND_PCM_FORMAT_S16_LE:
+      case SND_PCM_FORMAT_U16_LE:
+      case SND_PCM_FORMAT_S16_BE:
+      case SND_PCM_FORMAT_U16_BE:
+	ao_data.bps *= 2;
+	break;
+      case SND_PCM_FORMAT_S32_LE:
+      case SND_PCM_FORMAT_S32_BE:
+      case SND_PCM_FORMAT_FLOAT_LE:
+	ao_data.bps *= 4;
+	break;
+      case -1:
+	mp_msg(MSGT_AO,MSGL_ERR,"alsa-init: invalid format (%s) requested - output disabled\n",af_fmt2str_short(format));
+	return(0);
+	break;
+      default:
+	ao_data.bps *= 2;
+	mp_msg(MSGT_AO,MSGL_WARN,"alsa-init: couldn't convert to right format. setting bps to: %d", ao_data.bps);
+      }
+
+    bytes_per_sample = ao_data.bps / ao_data.samplerate;
+
 #ifdef BUFFERTIME
       {
 	int alsa_buffer_time = 500000; /* original 60 */
@@ -661,7 +660,7 @@
 	    }
 
 	  bits_per_sample = snd_pcm_format_physical_width(alsa_format);
-	  bits_per_frame = bits_per_sample * channels;
+	  bits_per_frame = bits_per_sample * ao_data.channels;
 	  chunk_bytes = chunk_size * bits_per_frame / 8;
 
 	    mp_msg(MSGT_AO,MSGL_V,"alsa-init: bits per sample (bps)=%i, bits per frame (bpf)=%i, chunk_bytes=%i\n",bits_per_sample,bits_per_frame,chunk_bytes);}