Changeset 356
- Timestamp:
- May 17, 2008, 9:49:53 AM (17 years ago)
- Location:
- GPL/branches/uniaud32-2.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/branches/uniaud32-2.0/lib32/sound.c
r353 r356 1 /* $Id: sound.c,v 1.2 2003/08/08 15:09:03 vladest Exp $ */2 1 /* 3 2 * MMPM/2 to OSS interface translation layer … … 43 42 #define samples_to_bytes(a) ((a*pHandle->doublesamplesize)/2) 44 43 #define bytes_to_samples(a) (pHandle->doublesamplesize ? ((a*2)/pHandle->doublesamplesize) : a) 45 46 44 int GetMaxChannels(ULONG deviceid, int type); 47 45 … … 771 769 soundhandle *pHandle = (soundhandle *)streamid; 772 770 struct snd_pcm_hw_params params; 773 struct snd_pcm_status status;774 771 struct snd_pcm_sw_params swparams; 775 int ret, ret1, nrperiods, minnrperiods, maxnrperiods, samplesize, i; 772 773 int ret, nrperiods, minnrperiods, maxnrperiods, samplesize; 776 774 ULONG bufsize, periodsize, minperiodsize, maxperiodsize; 777 775 ULONG periodbytes, minperiodbytes, maxperiodbytes; 778 776 BOOL fTryAgain = FALSE; 779 ULONG ulMinRate, ulMaxRate; 780 781 #ifdef DEBUG 782 dprintf(("OSS32_WaveSetHwParams")); 783 #endif 777 784 778 if(pHandle == NULL || pHandle->magic != MAGIC_WAVE_ALSA32) { 785 printk("OSS32_WaveSetHwParams error. Invalid handle: %x\n", pHandle); 786 DebugInt3(); 787 return OSSERR_INVALID_STREAMID; 779 DebugInt3(); 780 return OSSERR_INVALID_STREAMID; 788 781 } 789 782 if(pHwParams == NULL) { 790 printk("OSS32_WaveSetHwParams error. params = NULL\n"); 791 DebugInt3(); 792 return OSSERR_INVALID_PARAMETER; 783 DebugInt3(); 784 return OSSERR_INVALID_PARAMETER; 793 785 } 794 786 if(pHwParams->ulDataType >= OSS32_PCM_MAX_FORMATS) { 795 printk("OSS32_WaveSetHwParams error. Too high PCM format\n"); 796 DebugInt3(); 797 return OSSERR_INVALID_PARAMETER; 798 } 799 if ((int)pHwParams->ulNumChannels <= 0) { 800 printk("OSS32_WaveSetHwParams error. Invalid number of channels: %i\n", pHwParams->ulNumChannels); 801 DebugInt3(); 802 return OSSERR_INVALID_PARAMETER; 803 } 804 tryagain: 787 DebugInt3(); 788 return OSSERR_INVALID_PARAMETER; 789 } 790 805 791 //set operation to non-blocking 806 792 pHandle->file.f_flags = O_NONBLOCK; 793 807 794 //size of two samples (adpcm sample can be as small as 4 bits (mono), so take two) 808 795 samplesize = snd_pcm_format_size(OSSToALSADataType[pHwParams->ulDataType], 1); … … 811 798 periodbytes = pHwParams->ulPeriodSize; 812 799 periodsize = bytes_to_samples(periodbytes); 813 // checking number of channels814 815 printk("channels: %i, period bytes: %i\n",pHwParams->ulNumChannels, periodbytes);816 _snd_pcm_hw_params_any(¶ms);817 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_REFINE, (ULONG)__Stack32ToFlat(¶ms));818 ulMinRate = hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE)->min;819 ulMaxRate = hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE)->max;820 821 _snd_pcm_hw_params_any(¶ms);822 do {823 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_ACCESS,824 SNDRV_PCM_ACCESS_RW_INTERLEAVED, 0);825 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS,826 pHwParams->ulNumChannels, 0);827 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_REFINE, (ULONG)__Stack32ToFlat(¶ms));828 if (ret == 0) break;829 pHwParams->ulNumChannels--;830 } while(ret < 0 && pHwParams->ulNumChannels > 1);831 832 printk("channels selected: %i\n",pHwParams->ulNumChannels);833 800 834 801 //get all hardware parameters … … 836 803 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_ACCESS, 837 804 SNDRV_PCM_ACCESS_RW_INTERLEAVED, 0); 838 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_FORMAT,839 OSSToALSADataType[pHwParams->ulDataType], 0);840 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_REFINE, (ULONG)__Stack32ToFlat(¶ms));841 if(ret != 0) {842 printk("invalid format %i\n", OSSToALSADataType[pHwParams->ulDataType]);843 return UNIXToOSSError(ret);844 }845 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_SAMPLE_BITS,846 pHwParams->ulBitsPerSample, 0);847 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_REFINE, (ULONG)__Stack32ToFlat(¶ms));848 if(ret != 0) {849 printk("invalid number of sample bits %i\n", pHwParams->ulBitsPerSample);850 return UNIXToOSSError(ret);851 }852 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_FRAME_BITS,853 pHwParams->ulBitsPerSample*pHwParams->ulNumChannels, 0);854 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_REFINE, (ULONG)__Stack32ToFlat(¶ms));855 if(ret != 0) {856 printk("invalid number of frame bits %i\n", pHwParams->ulBitsPerSample*pHwParams->ulNumChannels);857 return UNIXToOSSError(ret);858 }859 860 805 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, 861 806 pHwParams->ulBitsPerSample, 0); … … 868 813 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_RATE, 869 814 pHwParams->ulSampleRate, 0); 870 871 815 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_REFINE, (ULONG)__Stack32ToFlat(¶ms)); 872 816 if(ret != 0) { 873 printk("OSS32_WaveSetHwParams (first pass) error %i\n", ret);874 printk("bps: %i\n",pHwParams->ulBitsPerSample);875 printk("format: %i\n",OSSToALSADataType[pHwParams->ulDataType]);876 printk("channels: %i\n",pHwParams->ulNumChannels);877 printk("sample rate: %i\n",pHwParams->ulSampleRate);878 879 // printk("OSS32_WaveSetHwParams invalid sample rate %i\n", pHwParams->ulSampleRate);880 // printk("will set to nearest\n");881 _snd_pcm_hw_params_any(¶ms);882 for (i=0; i<(sizeof(rates)/sizeof(unsigned))-1;i++)883 {884 if (pHwParams->ulSampleRate >= rates[i] &&885 pHwParams->ulSampleRate <= rates[i+1])886 {887 pHwParams->ulSampleRate = rates[i];888 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_RATE,889 pHwParams->ulSampleRate, 0);890 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_REFINE, (ULONG)__Stack32ToFlat(¶ms));891 if(ret == 0)892 {893 _snd_pcm_hw_params_any(¶ms);894 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_SAMPLE_BITS,895 pHwParams->ulBitsPerSample, 0);896 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_FRAME_BITS,897 pHwParams->ulBitsPerSample*pHwParams->ulNumChannels, 0);898 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_FORMAT,899 OSSToALSADataType[pHwParams->ulDataType], 0);900 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS,901 pHwParams->ulNumChannels, 0);902 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_RATE,903 pHwParams->ulSampleRate, 0);904 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_REFINE, (ULONG)__Stack32ToFlat(¶ms));905 goto __next;906 }907 }908 }909 910 // ret1 = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);911 817 DebugInt3(); 912 818 return UNIXToOSSError(ret); 913 819 } 914 __next:915 916 printk("sample rate: %i\n",pHwParams->ulSampleRate);917 820 918 821 //check period size against lower and upper boundaries 919 822 minperiodbytes = hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIOD_BYTES)->min; 920 823 maxperiodbytes = hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIOD_BYTES)->max; 921 922 824 if(periodbytes < minperiodbytes) { 923 825 periodbytes = minperiodbytes; … … 927 829 periodbytes = maxperiodbytes; 928 830 } 831 929 832 minperiodsize = hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min; 930 833 maxperiodsize = hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->max; … … 936 839 periodsize = maxperiodsize; 937 840 } 841 938 842 if(samples_to_bytes(periodsize) < periodbytes) { 939 843 periodbytes = samples_to_bytes(periodsize); … … 943 847 periodsize = bytes_to_samples(periodbytes); 944 848 } 849 945 850 //make sure period size is a whole fraction of the buffer size 946 851 bufsize = hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->max; 947 948 852 if(periodsize) { 949 853 nrperiods = bufsize/periodbytes; 950 854 } 951 855 else { 952 printk("OSS32_WaveSetHwParams error. Invalid periodsize (=0). closing file\n");953 // ret1 = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);954 856 DebugInt3(); 955 857 return OSSERR_INVALID_PARAMETER; 956 858 } 957 958 859 //check nr of periods against lower and upper boundaries 959 860 minnrperiods = hw_param_interval((¶ms), SNDRV_PCM_HW_PARAM_PERIODS)->min; … … 970 871 if(nrperiods == 1) { 971 872 DebugInt3(); 972 printk("OSS32_WaveSetHwParams error. Invalid number of periods(=1). closing file\n");973 // ret1 = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);974 873 return OSSERR_INVALID_PARAMETER; 975 874 } … … 978 877 //initialize parameter block & set sample rate, nr of channels and sample format, nr of periods, 979 878 //period size and buffer size 980 //tryagain:879 tryagain: 981 880 _snd_pcm_hw_params_any(¶ms); 982 881 _snd_pcm_hw_param_set(¶ms, SNDRV_PCM_HW_PARAM_ACCESS, … … 1003 902 periodbytes*nrperiods, 0); 1004 903 1005 //#ifdef DEBUG_PK 1006 printk("Hardware parameters: sample rate %i, data type %i, channels %i, period bytes %i, period size %i, nrperiods %i\n", 1007 pHwParams->ulSampleRate, pHwParams->ulDataType, pHwParams->ulNumChannels, periodbytes, periodsize, nrperiods); 1008 //#endif 904 dprintf(("Hardware parameters: sample rate %d, data type %d, channels %d, period size %d, periods %d", 905 pHwParams->ulSampleRate, pHwParams->ulDataType, pHwParams->ulNumChannels, periodsize, nrperiods)); 906 1009 907 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_HW_PARAMS, (ULONG)__Stack32ToFlat(¶ms)); 1010 printk("OSS32_WaveSetHwParams return %d after SNDRV_PCM_IOCTL_HW_PARAMS ioctl", ret);1011 if (ret == -77 && fTryAgain == FALSE)1012 {1013 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_PREPARE, 0);1014 fTryAgain = TRUE;1015 goto tryagain;1016 }1017 908 if(ret) { 1018 909 if(fTryAgain == FALSE) { … … 1027 918 } 1028 919 } 1029 printk("OSS32_WaveSetHwParams (second pass) error %i\n", ret);1030 printk("bps: %i\n",pHwParams->ulBitsPerSample);1031 printk("format: %i\n",OSSToALSADataType[pHwParams->ulDataType]);1032 printk("channels: %i\n",pHwParams->ulNumChannels);1033 printk("sample rate: %i\n",pHwParams->ulSampleRate);1034 printk("periodsize: %i\n",periodsize);1035 printk("periodbytes: %i\n",periodbytes);1036 printk("periods: %i\n",nrperiods);1037 // ret1 = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);1038 920 return UNIXToOSSError(ret); 1039 921 } … … 1059 941 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_SW_PARAMS, (ULONG)__Stack32ToFlat(&swparams)); 1060 942 } 1061 total = 0;1062 per_bytes = periodbytes;1063 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_STATUS, (ULONG)__Stack32ToFlat(&status));1064 if ( ((status.state != SNDRV_PCM_STATE_PREPARED) &&1065 (status.state != SNDRV_PCM_STATE_SETUP) &&1066 (status.state != SNDRV_PCM_STATE_RUNNING) &&1067 (status.state != SNDRV_PCM_STATE_DRAINING))) {1068 printk("Device is not in proper state: %i. Calling prepare\n", status.state);1069 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_PREPARE, 0);1070 }1071 printk("OSS32_WaveSetHwParams return %d after SNDRV_PCM_IOCTL_SW_PARAMS ioctl, streamid %X", ret,(ULONG)pHandle);1072 943 return UNIXToOSSError(ret); 1073 944 } -
GPL/branches/uniaud32-2.0/uniaud.inc
r340 r356 7 7 # BUILDVERSION must be 3 parts, and only numbers like 5.44.108 8 8 # It is best that 2'nd number is always 2 digits, eg at least 10 9 BUILDVERSION = 1.9. 39 BUILDVERSION = 1.9.4 10 10 11 11 # Fixpack version … … 13 13 # ex RC3 GA FIXPACK2 beta_47 14 14 # Comment out to avoid a fixpack line in bldlevel 15 FIXPACK = SVN r3 4015 FIXPACK = SVN r353 16 16 17 17 # ALSA BUILD VERSION
Note:
See TracChangeset
for help on using the changeset viewer.