[SDL] SDL_Mixer and speed/pitch shift

Sylvain Beucler beuc at beuc.net
Sun Aug 5 22:59:02 PDT 2007


Hi,

I was thinking that was not possible; for example, if you want to play
a sound slower, it takes a bigger buffer to store it, and the callback
works with a fixed-length buffer. So at first glance I believe
SDL_Mixer will stop the pitch-shifted sound before it ends.

Do you think it is possible to bypass this limitation?


Thanks for the link.

-- 
Sylvain

On Mon, Aug 06, 2007 at 12:27:19AM -0500, James Haley wrote:
> Hi,
> 
> You're correct that SDL_mixer itself doesn't have support for 
> pitch-shifting sounds. However, since it does give you direct access to the 
> sound stream buffer via the mixing callback functions (such as the post-mix 
> callback), you can implement it yourself.
> 
> My Eternity Engine Doom port has a rudimentary pitch shifting ability. 
> Looking at it might give you an idea on what would be involved.
> Link to the file:
> http://eternity.mancubus.net/svn/trunk/eternity/source/sdl/i_sound.c
> 
> EE just does all its own digital sound mixing and then pipes it through 
> SDL_mixer, which we use mainly for playing music. I should probably note 
> that our sound engine crashes on some x86 Mac machines due apparently to 
> some mysterious bug in SDL_mixer or its interaction with some particular 
> sound driver (it sends us a bad buffer seemingly at random). As of the 
> latest release, this is still a problem for one of my users, so watch out 
> for that when accessing the stream buffer directly.
> 
> Yours,
> James Haley
> 
> >From: Sylvain Beucler <beuc at beuc.net>
> >Reply-To: "A list for developers using the SDL library. (includes  
> >SDL-announce)" <sdl at lists.libsdl.org>
> >To: sdl at lists.libsdl.org
> >Subject: Re: [SDL] SDL_Mixer and speed/pitch shift
> >Date: Mon, 6 Aug 2007 00:21:36 +0200
> >MIME-Version: 1.0
> >Received: from diego.dreamhost.com ([66.33.216.104]) by 
> >bay0-mc11-f9.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Sun, 
> >5 Aug 2007 15:21:45 -0700
> >Received: from diego.dreamhost.com (localhost [127.0.0.1])by 
> >diego.dreamhost.com (Postfix) with ESMTP id 4B7FF4800A;Sun,  5 Aug 2007 
> >15:21:41 -0700 (PDT)
> >Received: from smtp3-g19.free.fr (smtp3-g19.free.fr [212.27.42.29])by 
> >diego.dreamhost.com (Postfix) with ESMTP id 9EA8448006for 
> ><sdl at lists.libsdl.org>; Sun,  5 Aug 2007 15:21:38 -0700 (PDT)
> >Received: from smtp3-g19.free.fr (localhost.localdomain [127.0.0.1])by 
> >smtp3-g19.free.fr (Postfix) with ESMTP id 11A0638F1for 
> ><sdl at lists.libsdl.org>; Mon,  6 Aug 2007 00:21:37 +0200 (CEST)
> >Received: from localhost.localdomain (unknown [82.238.35.175])by 
> >smtp3-g19.free.fr (Postfix) with ESMTP id EC72238DFfor 
> ><sdl at lists.libsdl.org>; Mon,  6 Aug 2007 00:21:36 +0200 (CEST)
> >Received: from me by localhost.localdomain with local (Exim 
> >4.63)(envelope-from <beuc at beuc.net>) id 1IHoTg-0006Zz-BDfor 
> >sdl at lists.libsdl.org; Mon, 06 Aug 2007 00:21:36 +0200
> >X-Message-Delivery: Vj0zLjQuMDt1cz0wO2k9MDtsPTA7YT0w
> >X-Message-Info: 
> >KYGz7ipbXiQwgYXFWQLpmdesWxUDBbFeBb6euDEH2q4rALn62YNWFanUZM/SkKpxFki9KJ2QxxqrlU/kf20YGSUnl4vVVtPD
> >X-Original-To: sdl at lists.libsdl.org
> >References: <20070801150315.GA7104 at perso.beuc.net>
> >X-Operating-System: GNU/Linux
> >User-Agent: Mutt/1.5.13 (2006-08-11)
> >X-BeenThere: sdl at lists.libsdl.org
> >X-Mailman-Version: 2.1.9
> >Precedence: list
> >List-Id: "A list for developers using the SDL library. 
> >(includesSDL-announce)" <sdl-libsdl.org>
> >List-Unsubscribe: 
> ><http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org>,<mailto:sdl-request at lists.libsdl.org?subject=unsubscribe>
> >List-Archive: <http://lists.libsdl.org/private.cgi/sdl-libsdl.org>
> >List-Post: <mailto:sdl at lists.libsdl.org>
> >List-Help: <mailto:sdl-request at lists.libsdl.org?subject=help>
> >List-Subscribe: 
> ><http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org>,<mailto:sdl-request at lists.libsdl.org?subject=subscribe>
> >Errors-To: sdl-bounces at lists.libsdl.org
> >Return-Path: sdl-bounces at lists.libsdl.org
> >X-OriginalArrivalTime: 05 Aug 2007 22:21:45.0469 (UTC) 
> >FILETIME=[01E9B2D0:01C7D7AF]
> >
> >Nobody using pitch shift here? :/
> >
> >Cheers,
> >
> >--
> >Sylvain
> >
> >On Wed, Aug 01, 2007 at 05:03:15PM +0200, Sylvain Beucler wrote:
> >> Hi,
> >>
> >> I'd like to use SDL_Mixer to play multiple sounds at once, and with
> >> different speeds for each sound.
> >>
> >> This allow, for example, to play a normal voice and an acute voice
> >> from the same sound file, by playing it with a greater frequency for
> >> the acute voice.
> >>
> >> This feature (which is often refered to as "pitch shift") seems to be
> >> missing from SDL_Mixer.
> >> (I don't think I can implement it with an SDL_Mixer Effect either,
> >> because the callback can only modify a fixed-length sample.)
> >>
> >>
> >> Is there a way to implement pitch shift with SDL_Mixer? Or an
> >> alternate SDL library that would do that (but I also need midi/BGM
> >> support in the mixer)?
> >>
> >>
> >> For example, DirectX provides it through
> >> DirectSoundBuffer::SetFrequency(frequency), and Allegro provides it
> >> with play_sample(sample, t vol, pan, freq, loop).
> >>
> >>
> >> Thanks!


More information about the SDL mailing list