author | llornkcor <llornkcor> | 2002-07-20 22:07:31 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-20 22:07:31 (UTC) |
commit | 2342d48be31847e7ead9d1cc682452e8f0122351 (patch) (unidiff) | |
tree | 8329bb94e9d429c905a0ef6b881cf1c0f775bf14 /core/multimedia/opieplayer/modplug/modplugin.cpp | |
parent | 0f24c1fb86d3bb58d8696358b824c0e01752b10d (diff) | |
download | opie-2342d48be31847e7ead9d1cc682452e8f0122351.zip opie-2342d48be31847e7ead9d1cc682452e8f0122351.tar.gz opie-2342d48be31847e7ead9d1cc682452e8f0122351.tar.bz2 |
initial commit of modplugin
Diffstat (limited to 'core/multimedia/opieplayer/modplug/modplugin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/modplug/modplugin.cpp | 263 |
1 files changed, 263 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/modplug/modplugin.cpp b/core/multimedia/opieplayer/modplug/modplugin.cpp new file mode 100644 index 0000000..e606c52 --- a/dev/null +++ b/core/multimedia/opieplayer/modplug/modplugin.cpp | |||
@@ -0,0 +1,263 @@ | |||
1 | /* This file is part of the KDE project | ||
2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
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 GNU | ||
12 | General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; see the file COPYING. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #include "modplugin.h" | ||
21 | |||
22 | #include "memfile.h" | ||
23 | |||
24 | #include <qfileinfo.h> | ||
25 | |||
26 | ModPlugin::ModPlugin() | ||
27 | { | ||
28 | } | ||
29 | |||
30 | ModPlugin::~ModPlugin() | ||
31 | { | ||
32 | close(); | ||
33 | } | ||
34 | |||
35 | const char *ModPlugin::pluginName() | ||
36 | { | ||
37 | return "ModPlugin"; | ||
38 | } | ||
39 | |||
40 | const char *ModPlugin::pluginComment() | ||
41 | { | ||
42 | return "LibModPlug based MOD/XM/S3M/IT module player plugin"; | ||
43 | } | ||
44 | |||
45 | double ModPlugin::pluginVersion() | ||
46 | { | ||
47 | return 1.0; | ||
48 | } | ||
49 | |||
50 | bool ModPlugin::isFileSupported( const QString &file ) | ||
51 | { | ||
52 | static const char * const patterns [] = | ||
53 | { | ||
54 | "669", "amf", "apun", "dsm", "far", "gdm", "imf", "it", | ||
55 | "med", "mod", "mtm", "nst", "s3m", "stm", "stx", "ult", | ||
56 | "uni", "xm" | ||
57 | }; | ||
58 | static const uchar patternCount = sizeof( patterns ) / sizeof( patterns[ 0 ] ); | ||
59 | |||
60 | QString ext = QFileInfo( file ).extension( false /* complete */ ).lower(); | ||
61 | for ( uchar i = 0; i < patternCount; ++i ) | ||
62 | if ( QString::fromLatin1( patterns[ i ] ) == ext ) | ||
63 | return true; | ||
64 | |||
65 | return false; | ||
66 | } | ||
67 | |||
68 | bool ModPlugin::open( const QString &_file ) | ||
69 | { | ||
70 | MemFile f( _file ); | ||
71 | if ( !f.open( IO_ReadOnly ) ) | ||
72 | return false; | ||
73 | |||
74 | CSoundFile::SetWaveConfig( s_frequency, s_bytesPerSample * 8, s_channels ); | ||
75 | |||
76 | CSoundFile::SetWaveConfigEx( false, /* surround */ | ||
77 | true, /* no oversampling */ | ||
78 | false, /* reverb */ | ||
79 | true, /* high quality resampler */ | ||
80 | true, /* megabass ;) */ | ||
81 | true, /* noise reduction */ | ||
82 | false /* some eq stuff I didn't really understand..*/ ); | ||
83 | |||
84 | CSoundFile::SetResamplingMode( SRCMODE_POLYPHASE ); | ||
85 | |||
86 | QByteArray &rawData = f.data(); | ||
87 | if ( !Create( reinterpret_cast<BYTE *>( rawData.data() ), rawData.size() ) ) | ||
88 | return false; | ||
89 | |||
90 | m_songTime = GetSongTime(); | ||
91 | m_maxPosition = GetMaxPosition(); | ||
92 | return true; | ||
93 | } | ||
94 | |||
95 | bool ModPlugin::close() | ||
96 | { | ||
97 | return Destroy(); | ||
98 | } | ||
99 | |||
100 | bool ModPlugin::isOpen() | ||
101 | { | ||
102 | return m_nType != MOD_TYPE_NONE; | ||
103 | } | ||
104 | |||
105 | const QString &ModPlugin::fileInfo() | ||
106 | { | ||
107 | return QString::null; // ### | ||
108 | } | ||
109 | |||
110 | int ModPlugin::audioStreams() | ||
111 | { | ||
112 | return 1; | ||
113 | } | ||
114 | |||
115 | int ModPlugin::audioChannels( int ) | ||
116 | { | ||
117 | return s_channels; | ||
118 | } | ||
119 | |||
120 | int ModPlugin::audioFrequency( int ) | ||
121 | { | ||
122 | return s_frequency; | ||
123 | } | ||
124 | |||
125 | int ModPlugin::audioSamples( int ) | ||
126 | { | ||
127 | return m_songTime * s_frequency; | ||
128 | } | ||
129 | |||
130 | bool ModPlugin::audioSetSample( long sample, int ) | ||
131 | { | ||
132 | float position = ( sample / s_frequency ) * m_maxPosition / m_songTime; | ||
133 | SetCurrentPos( (int)position ); | ||
134 | return true; | ||
135 | } | ||
136 | |||
137 | long ModPlugin::audioGetSample( int ) | ||
138 | { | ||
139 | return GetCurrentPos() * s_frequency; | ||
140 | } | ||
141 | |||
142 | bool ModPlugin::audioReadSamples( short *output, int /*channels*/, long samples, | ||
143 | long &samplesRead, int ) | ||
144 | { | ||
145 | unsigned long totalAmountInBytes = samples * s_bytesPerSample * s_channels; | ||
146 | samplesRead = Read( output, totalAmountInBytes ); | ||
147 | // it can happen that our prediction about the total amount of samples | ||
148 | // is wrong. The mediaplayer can't handle the situation of returning 0 read bytes | ||
149 | // very well. So instead let's fill up the remaining bytes with zeroes. | ||
150 | if ( samplesRead == 0 ) | ||
151 | { | ||
152 | memset( reinterpret_cast<char *>( output ), 0, totalAmountInBytes ); | ||
153 | samplesRead = samples; | ||
154 | } | ||
155 | |||
156 | return true; | ||
157 | } | ||
158 | |||
159 | int ModPlugin::videoStreams() | ||
160 | { | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | int ModPlugin::videoWidth( int ) | ||
165 | { | ||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | int ModPlugin::videoHeight( int ) | ||
170 | { | ||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | double ModPlugin::videoFrameRate( int ) | ||
175 | { | ||
176 | return 0; | ||
177 | } | ||
178 | |||
179 | int ModPlugin::videoFrames( int ) | ||
180 | { | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | bool ModPlugin::videoSetFrame( long, int ) | ||
185 | { | ||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | long ModPlugin::videoGetFrame( int ) | ||
190 | { | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | bool ModPlugin::videoReadFrame( unsigned char **, int, int, int, int, | ||
195 | ColorFormat, int ) | ||
196 | { | ||
197 | return false; | ||
198 | } | ||
199 | |||
200 | bool ModPlugin::videoReadScaledFrame( unsigned char **, int, int, int, int, | ||
201 | int, int, ColorFormat, int ) | ||
202 | { | ||
203 | return false; | ||
204 | } | ||
205 | |||
206 | bool ModPlugin::videoReadYUVFrame( char *, char *, char *, int, int, int, | ||
207 | int, int ) | ||
208 | { | ||
209 | return false; | ||
210 | } | ||
211 | |||
212 | double ModPlugin::getTime() | ||
213 | { | ||
214 | return 0.0; // ### | ||
215 | } | ||
216 | |||
217 | bool ModPlugin::setSMP( int ) | ||
218 | { | ||
219 | return false; | ||
220 | } | ||
221 | |||
222 | bool ModPlugin::setMMX( bool ) | ||
223 | { | ||
224 | return false; | ||
225 | } | ||
226 | |||
227 | bool ModPlugin::supportsAudio() | ||
228 | { | ||
229 | return true; | ||
230 | } | ||
231 | |||
232 | bool ModPlugin::supportsVideo() | ||
233 | { | ||
234 | return false; | ||
235 | } | ||
236 | |||
237 | bool ModPlugin::supportsYUV() | ||
238 | { | ||
239 | return false; | ||
240 | } | ||
241 | |||
242 | bool ModPlugin::supportsMMX() | ||
243 | { | ||
244 | return false; | ||
245 | } | ||
246 | |||
247 | bool ModPlugin::supportsSMP() | ||
248 | { | ||
249 | return false; | ||
250 | } | ||
251 | |||
252 | bool ModPlugin::supportsStereo() | ||
253 | { | ||
254 | return true; | ||
255 | } | ||
256 | |||
257 | bool ModPlugin::supportsScaling() | ||
258 | { | ||
259 | return false; | ||
260 | } | ||
261 | |||
262 | /* vim: et sw=4 | ||
263 | */ | ||