Package flumotion :: Package component :: Package encoders :: Package vorbis :: Module vorbisutils
[hide private]

Source Code for Module flumotion.component.encoders.vorbis.vorbisutils

 1  # -*- Mode: Python -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3  # 
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
 6  # All rights reserved. 
 7   
 8  # This file may be distributed and/or modified under the terms of 
 9  # the GNU General Public License version 2 as published by 
10  # the Free Software Foundation. 
11  # This file is distributed without any warranty; without even the implied 
12  # warranty of merchantability or fitness for a particular purpose. 
13  # See "LICENSE.GPL" in the source distribution for more information. 
14   
15  # Licensees having purchased or holding a valid Flumotion Advanced 
16  # Streaming Server license may use this file in accordance with the 
17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
18  # See "LICENSE.Flumotion" in the source distribution for more information. 
19   
20  # Headers in this file shall remain intact. 
21   
22  __version__ = "$Rev: 7162 $" 
23   
24   
25 -def get_preferred_sample_rate(maxrate):
26 """ Get the preferred 'standard' sample rate not exceeded maxrate""" 27 rates = [192000, 96000, 48000, 44100, 32000, 34000, 22050, 16000, 12000, 28 11025, 8000] 29 30 for rate in rates: 31 if rate <= maxrate: 32 return rate 33 34 return 8000
35 36
37 -def get_max_sample_rate(bitrate, channels):
38 # maybe better in a hashtable/associative array? 39 # ZAHEER: these really are "magic" limits that i found by trial and 40 # error used 41 # by libvorbis's encoder to determine what maximum samplerate it 42 # accepts for a bitrate, numchannels combo 43 # THOMAS: strangely enough they don't seem to be easily extractable from 44 # vorbis/lib/modes/setup_*.h 45 # might make sense to figure this out once and for all and verify 46 # GStreamer's behaviour as well 47 if channels == 2: 48 if bitrate >= 45000: 49 retval = 50000 50 elif bitrate >= 40000: 51 retval = 40000 52 elif bitrate >= 30000: 53 retval = 26000 54 elif bitrate >= 24000: 55 retval = 19000 56 elif bitrate >= 16000: 57 retval = 15000 58 elif bitrate >= 12000: 59 retval = 9000 60 else: 61 retval = -1 62 63 elif channels == 1: 64 if bitrate >= 32000: 65 retval = 50000 66 elif bitrate >= 24000: 67 retval = 40000 68 elif bitrate >= 16000: 69 retval = 26000 70 elif bitrate >= 12000: 71 retval = 15000 72 elif bitrate >= 8000: 73 retval = 9000 74 else: 75 retval = -1 76 77 return retval
78