3 Copyright 2005 Kenneth Hayber <ken@hayber.us>, All rights reserved.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License.
9 This program is distributed in the hope that it will be useful
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 print 'No WAV support'
34 A decoder to process WAV sound files. Utilizes the standard python wave module
35 Called from the Player class to read and decode WAV files.
37 def __init__(self
, filename
, buffersize
):
38 """Initialize the decoder"""
39 self
.buffersize
= buffersize
40 self
.filename
= filename
43 """Open the file and prepare for decoding"""
44 self
.wv
= wave
.open(self
.filename
, 'r')
47 """Close the file and do any needed cleanup"""
51 """Return the length of the file in seconds as an integer"""
52 return self
.wv
.getnframes() / self
.wv
.getframerate()
55 """Return the sample rate of the file in samples per second"""
56 return self
.wv
.getframerate()
59 """Return the number of channels in the file"""
60 return self
.wv
.getnchannels()
64 Read data from the file and decode to PCM data. Return a buffer
65 of data and length, or (None, 0) at EOF
67 buff
= self
.wv
.readframes(self
.buffersize
)
74 """Return the current playback position in seconds"""
75 return self
.wv
.tell() / self
.wv
.getframerate()
78 """Jump to pos as a percentage of the total length of the file"""
79 self
.wv
.setpos(int(pos
* self
.wv
.getnframes()))
82 """Print some info about this WAV file"""
83 print "no info for WAV files"