2 * @file redbookreader.cpp
3 * @author Wei-Cheng Pan
5 * Copyright (C) 2008 Wei-Cheng Pan <legnaleurc@gmail.com>
7 * This file is part of Khopper.
9 * Khopper is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * Khopper is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "redbookreader.hpp"
24 using namespace khopper::codec
;
25 using khopper::error::IOError
;
27 RedbookReader::RedbookReader( const QUrl
& uri
):
28 AbstractReader( uri
),
29 file_( uri
.toLocalFile() ) {
31 format
.setByteOrder( AudioFormat::LittleEndian
);
32 format
.setChannels( 2 );
33 format
.setFrequency( 44100 );
34 format
.setSampleSize( 2 );
35 format
.setSampleType( AudioFormat::SignedInt
);
36 this->setAudioFormat( format
);
39 bool RedbookReader::atEnd() const {
40 return this->file_
.atEnd();
43 bool RedbookReader::seek( qint64 pos
) {
44 bool ret
= this->AbstractReader::seek( pos
);
45 ret
&= this->file_
.seek( pos
);
49 qint64
RedbookReader::size() const {
50 return this->file_
.size();
53 void RedbookReader::doOpen() {
54 bool ret
= this->file_
.open( QIODevice::ReadOnly
);
56 throw IOError( QString( "%1 : %2 (from khopper::codec::RedbookReader)" ).arg( this->file_
.fileName() ).arg( this->file_
.errorString() ) );
58 this->setDuration( this->file_
.size() * 1000 / 44100 / 2 / 2 );
61 void khopper::codec::RedbookReader::doClose() {
65 qint64
RedbookReader::readData( char * data
, qint64 maxSize
) {
66 return this->file_
.read( data
, maxSize
);