forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SDL sample converters

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Thu May 29, 2008 3:14 am    Post subject: SDL sample converters Reply with quote

SDL has the ability to convert the format and rate of samples to the mixer format and rate, but there's a slight catch - it only converts the rate by powers of two. Look at this in SDL_audiocvt.c:

Code:
      /* We may need a slow conversion here to finish up */
      if ( (lo_rate/100) != (hi_rate/100) ) {
#if 1
         /* The problem with this is that if the input buffer is
            say 1K, and the conversion rate is say 1.1, then the
            output buffer is 1.1K, which may not be an acceptable
            buffer size for the audio driver (not a power of 2)
         */
         /* For now, punt and hope the rate distortion isn't great.
         */
#else
         if ( src_rate < dst_rate ) {
            cvt->rate_incr = (double)lo_rate/hi_rate;
            cvt->len_mult *= 2;
            cvt->len_ratio /= cvt->rate_incr;
         } else {
            cvt->rate_incr = (double)hi_rate/lo_rate;
            cvt->len_ratio *= cvt->rate_incr;
         }
         cvt->filters[cvt->filter_index++] = SDL_RateSLOW;
#endif
      }


The "slow" rate conversion isn't enabled because on some audio cards, it can result in the mixed sample being a length that the card can't handle. The PSP wants sample lengths to be a multiple of 64, but the only result from not doing so is the possibility of a slight pop or crackle at the end of the sample. Because of that, I changed the "#if 1" to "#if 0" and recompiled SDL. This fixes the pitch problem in Duke Nukem 3D. Duke3D uses samples at 5 and 8 kHz, and relies on SDL to resample them to 11025 Hz when mixing the sounds. Without the change, the samples were being resampled to the closest power of two between 5/8 kHz and 44100 Hz (the mixer rate).

Any thoughts on enabling the slow conversion in the repo copy of SDL?
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group