[Mplayer-cvslog] CVS: main/libao2 ao_dxr3.c,1.7,1.8

David Holm mswitch at mplayer.dev.hu
Fri Nov 30 23:18:53 CET 2001


Update of /cvsroot/mplayer/main/libao2
In directory mplayer:/var/tmp.root/cvs-serv20216/libao2

Modified Files:
	ao_dxr3.c 
Log Message:
Added support for upsampling since dxr3/h+ only supports 44100Hz and 48000Hz, currently it only works on 44100/(2*ratio)
Reverted get_delay to return a properly calculated value instead of 0.0


Index: ao_dxr3.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_dxr3.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ao_dxr3.c	30 Nov 2001 16:11:36 -0000	1.7
+++ ao_dxr3.c	30 Nov 2001 22:18:51 -0000	1.8
@@ -86,12 +86,26 @@
         if( ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_data.channels) < 0 )
 	    printf( "AO: [dxr3] Unable to set number of channels\n" );
   
-	// set rate
 	ao_data.bps = (channels+1)*rate;
 	ao_data.samplerate=rate;
 	if( ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_data.samplerate) < 0 )
+	{
 	    printf( "AO: [dxr3] Unable to set samplerate\n" );
-	printf("AO: [dxr3] Using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate);
+	    return 0;
+	}
+	if( rate < ao_data.samplerate )
+	{
+	    ao_data.samplerate = 44100;
+	    ioctl(fd_audio, SNDCTL_DSP_SPEED, &ao_data.samplerate);
+    	    if( ao_data.samplerate != 44100 )
+	    {
+	        printf( "AO: [dxr3] Unable to set samplerate\n" );
+	        return 0;
+	    }
+	    printf("AO: [dxr3] Using %d Hz samplerate (requested: %d) (Upsampling)\n",ao_data.samplerate,rate);
+	    ao_data.samplerate = rate;
+	}
+	else printf("AO: [dxr3] Using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate);
   }
   else ao_data.bps *= 2;
 
@@ -190,23 +204,68 @@
     return space;
 }
 
+// playes 'len' bytes of 'data'
+// upsamples if samplerate < 44100
+// return: number of bytes played
 static int play(void* data,int len,int flags)
 {
     if( ioctl( fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &ao_data.pts ) < 0 )
 	printf( "AO: [dxr3] Unable to set PTS\n" );
+    if( ao_data.samplerate < 44100 )
+    {
+	int i,j,ratio,len2;
+	unsigned char *data2,*s,*d;
+	
+	ratio = 44100/ao_data.samplerate;ratio/=2;ratio*=2;
+	len2 = len * ratio;
+	data2 = malloc(len2);
+	
+	s = data;
+	d = data2;
+	
+	//Upsampler
+	if( ao_data.format == AFMT_U8 )
+	{
+	    for(i=0;i<ratio/2;i++)
+		for(j=0;j<len;j++)
+		{
+		    *d = *s;
+		    d++;
+		    *d = *s;
+		    d++;s++;
+		}
+	}
+	else
+	{
+	    for(i=0;i<ratio/2;i++)
+		for(j=0;j<len/2;j++)
+		{
+		    *d = *s;
+		    d++;s++;
+		    *d = *s;
+		    d++;s--;
+		    *d = *s;
+		    d++;s++;
+		    *d = *s;
+		    d++;s++;
+		}
+	}
+	if( len2 < 0 ) return 0;
+	write(fd_audio,data2,len2);
+	return len;
+    }
     return write(fd_audio,data,len);
 }
 
-// return: how many unplayed bytes are in the buffer
+// return: delay in seconds between first and last sample in buffer
 static float get_delay()
 {
-/*    int r=0;
+    int r=0;
     if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r) < 0 )
     {
         printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" );
 	return ((float)ao_data.buffersize)/(float)ao_data.bps;
     }
-    return (((float)r)/(float)ao_data.bps);*/
-    return 0.0;
+    return (((float)r)/(float)ao_data.bps);
 }
 




More information about the MPlayer-cvslog mailing list