summaryrefslogtreecommitdiff
path: root/library/sound.cpp
Unidiff
Diffstat (limited to 'library/sound.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/sound.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/library/sound.cpp b/library/sound.cpp
index c8704f9..5b67995 100644
--- a/library/sound.cpp
+++ b/library/sound.cpp
@@ -1,79 +1,82 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qpe/resource.h> 21#include <qpe/resource.h>
22#include <qpe/sound.h> 22#include <qpe/sound.h>
23#include <qpe/qcopenvelope_qws.h> 23#include <qpe/qcopenvelope_qws.h>
24 24
25#include <qsound.h> 25#include <qsound.h>
26#include <qfile.h> 26#include <qfile.h>
27 27
28#include <unistd.h> 28#include <unistd.h>
29#include <fcntl.h> 29#include <fcntl.h>
30#include <sys/ioctl.h> 30#include <sys/ioctl.h>
31
32#ifndef QT_NO_SOUND
31#include <sys/soundcard.h> 33#include <sys/soundcard.h>
34#endif
32 35
33#include "config.h" 36#include "config.h"
34#include <qmessagebox.h> 37#include <qmessagebox.h>
35#ifndef QT_NO_SOUND 38#ifndef QT_NO_SOUND
36static int WAVsoundDuration(const QString& filename) 39static int WAVsoundDuration(const QString& filename)
37{ 40{
38 // bad solution 41 // bad solution
39 42
40 // most of this is copied from qsoundqss.cpp 43 // most of this is copied from qsoundqss.cpp
41 44
42 QFile input(filename); 45 QFile input(filename);
43 if ( !input.open(IO_ReadOnly) ) 46 if ( !input.open(IO_ReadOnly) )
44 return 0; 47 return 0;
45 48
46 struct QRiffChunk { 49 struct QRiffChunk {
47 char id[4]; 50 char id[4];
48 Q_UINT32 size; 51 Q_UINT32 size;
49 char data[4/*size*/]; 52 char data[4/*size*/];
50 } chunk; 53 } chunk;
51 54
52 struct { 55 struct {
53 Q_INT16 formatTag; 56 Q_INT16 formatTag;
54 Q_INT16 channels; 57 Q_INT16 channels;
55 Q_INT32 samplesPerSec; 58 Q_INT32 samplesPerSec;
56 Q_INT32 avgBytesPerSec; 59 Q_INT32 avgBytesPerSec;
57 Q_INT16 blockAlign; 60 Q_INT16 blockAlign;
58 Q_INT16 wBitsPerSample; 61 Q_INT16 wBitsPerSample;
59 } chunkdata; 62 } chunkdata;
60 63
61 int total = 0; 64 int total = 0;
62 65
63 while(1) { 66 while(1) {
64 // Keep reading chunks... 67 // Keep reading chunks...
65 const int n = sizeof(chunk)-sizeof(chunk.data); 68 const int n = sizeof(chunk)-sizeof(chunk.data);
66 if ( input.readBlock((char*)&chunk,n) != n ) 69 if ( input.readBlock((char*)&chunk,n) != n )
67 break; 70 break;
68 if ( qstrncmp(chunk.id,"data",4) == 0 ) { 71 if ( qstrncmp(chunk.id,"data",4) == 0 ) {
69 total += chunkdata.avgBytesPerSec ? 72 total += chunkdata.avgBytesPerSec ?
70 chunk.size * 1000 / chunkdata.avgBytesPerSec : 0; 73 chunk.size * 1000 / chunkdata.avgBytesPerSec : 0;
71//qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0); 74//qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0);
72 input.at(input.at()+chunk.size-4); 75 input.at(input.at()+chunk.size-4);
73 } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { 76 } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) {
74 char d[4]; 77 char d[4];
75 if ( input.readBlock(d,4) != 4 ) 78 if ( input.readBlock(d,4) != 4 )
76 return 0; 79 return 0;
77 if ( qstrncmp(d,"WAVE",4) != 0 ) { 80 if ( qstrncmp(d,"WAVE",4) != 0 ) {
78 // skip 81 // skip
79//qDebug("skip %.4s RIFF chunk",d); 82//qDebug("skip %.4s RIFF chunk",d);