summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-11-13 08:33:15 (UTC)
committer llornkcor <llornkcor>2003-11-13 08:33:15 (UTC)
commit3451f19533b2dd342a57bceda4aec20edd4048b7 (patch) (unidiff)
tree9065ee04704e4f095a093696be94b1776b873c1e
parent452f0cc3d9fdd792d2050ceaffd33b3d1611fcc3 (diff)
downloadopie-3451f19533b2dd342a57bceda4aec20edd4048b7.zip
opie-3451f19533b2dd342a57bceda4aec20edd4048b7.tar.gz
opie-3451f19533b2dd342a57bceda4aec20edd4048b7.tar.bz2
update wavfile
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/wavFile.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp
index 7bfffb6..b177c91 100644
--- a/noncore/multimedia/opierec/wavFile.cpp
+++ b/noncore/multimedia/opierec/wavFile.cpp
@@ -24,9 +24,9 @@
24WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate, 24WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate,
25 int channels, int resolution, int format ) 25 int channels, int resolution, int format )
26 : QObject( parent) 26 : QObject( parent)
27{ 27{
28qDebug("new wave file"); 28//qDebug("new wave file");
29 bool b = makeNwFile; 29 bool b = makeNwFile;
30 wavSampleRate=sampleRate; 30 wavSampleRate=sampleRate;
31 wavFormat=format; 31 wavFormat=format;
32 wavChannels=channels; 32 wavChannels=channels;
@@ -40,9 +40,9 @@ qDebug("new wave file");
40} 40}
41 41
42bool WavFile::newFile() { 42bool WavFile::newFile() {
43 43
44 qDebug("Set up new file"); 44// qDebug("Set up new file");
45 Config cfg("OpieRec"); 45 Config cfg("OpieRec");
46 cfg.setGroup("Settings"); 46 cfg.setGroup("Settings");
47 47
48 currentFileName=cfg.readEntry("directory",QDir::homeDirPath()); 48 currentFileName=cfg.readEntry("directory",QDir::homeDirPath());
@@ -59,19 +59,24 @@ bool WavFile::newFile() {
59 else 59 else
60 currentFileName += date; 60 currentFileName += date;
61 currentFileName+=".wav"; 61 currentFileName+=".wav";
62 62
63 qDebug("set up file for recording: "+currentFileName); 63// qDebug("set up file for recording: "+currentFileName);
64 char *pointer; 64 char pointer[] = "/tmp/opierec-XXXXXX";
65 int fd = 0;
65 66
66 if( currentFileName.find("/mnt",0,true) == -1 67 if( currentFileName.find("/mnt",0,true) == -1
67 && currentFileName.find("/tmp",0,true) == -1 ) { 68 && currentFileName.find("/tmp",0,true) == -1 ) {
68 // if destination file is most likely in flash (assuming jffs2) 69 // if destination file is most likely in flash (assuming jffs2)
69 // we have to write to a different filesystem first 70 // we have to write to a different filesystem first
70 71
71 useTmpFile = true; 72 useTmpFile = true;
72 pointer=tmpnam(NULL); 73 if(( fd = mkstemp( pointer)) < 0 ) {
73 qDebug("Opening tmp file %s",pointer); 74 perror("mkstemp failed");
75 return false;
76 }
77
78// qDebug("Opening tmp file %s",pointer);
74 track.setName( pointer); 79 track.setName( pointer);
75 80
76 } else { //just use regular file.. no moving 81 } else { //just use regular file.. no moving
77 82
@@ -100,9 +105,9 @@ void WavFile::closeFile() {
100 track.close(); 105 track.close();
101} 106}
102 107
103int WavFile::openFile(const QString &currentFileName) { 108int WavFile::openFile(const QString &currentFileName) {
104 qDebug("open play file "+currentFileName); 109// qDebug("open play file "+currentFileName);
105 closeFile(); 110 closeFile();
106 111
107 track.setName(currentFileName); 112 track.setName(currentFileName);
108 113
@@ -125,13 +130,13 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
125 (*hdr).fmtLen = 16; // format length = 16 130 (*hdr).fmtLen = 16; // format length = 16
126 131
127 if( wavFormat == WAVE_FORMAT_PCM) { 132 if( wavFormat == WAVE_FORMAT_PCM) {
128 (*hdr).fmtTag = 1; // PCM 133 (*hdr).fmtTag = 1; // PCM
129 qDebug("set header WAVE_FORMAT_PCM"); 134// qDebug("set header WAVE_FORMAT_PCM");
130 } 135 }
131 else { 136 else {
132 (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM 137 (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM
133 qDebug("set header WAVE_FORMAT_DVI_ADPCM"); 138 // qDebug("set header WAVE_FORMAT_DVI_ADPCM");
134 } 139 }
135 140
136 // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels 141 // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels
137 (*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels 142 (*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels
@@ -143,10 +148,10 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
143 148
144 strncpy((*hdr).dataID, "data", 4); 149 strncpy((*hdr).dataID, "data", 4);
145 150
146 write( fd,hdr, sizeof(*hdr)); 151 write( fd,hdr, sizeof(*hdr));
147 qDebug("writing header: bitrate%d, samplerate %d, channels %d", 152// qDebug("writing header: bitrate%d, samplerate %d, channels %d",
148 wavResolution, wavSampleRate, wavChannels); 153// wavResolution, wavSampleRate, wavChannels);
149 return true; 154 return true;
150} 155}
151 156
152bool WavFile::adjustHeaders(int fd, int total) { 157bool WavFile::adjustHeaders(int fd, int total) {
@@ -154,14 +159,14 @@ bool WavFile::adjustHeaders(int fd, int total) {
154 int i = total + 36; 159 int i = total + 36;
155 write( fd, &i, sizeof(i)); 160 write( fd, &i, sizeof(i));
156 lseek( fd, 40, SEEK_SET); 161 lseek( fd, 40, SEEK_SET);
157 write( fd, &total, sizeof(total)); 162 write( fd, &total, sizeof(total));
158 qDebug("adjusting header %d", total); 163// qDebug("adjusting header %d", total);
159 return true; 164 return true;
160} 165}
161 166
162int WavFile::parseWavHeader(int fd) { 167int WavFile::parseWavHeader(int fd) {
163 qDebug("Parsing wav header"); 168// qDebug("Parsing wav header");
164 char string[4]; 169 char string[4];
165 int found; 170 int found;
166 short fmt; 171 short fmt;
167 unsigned short ch, bitrate; 172 unsigned short ch, bitrate;
@@ -257,10 +262,10 @@ int WavFile::parseWavHeader(int fd) {
257 qDebug("Could not read from sound file.\n"); 262 qDebug("Could not read from sound file.\n");
258 return -1; 263 return -1;
259 } else { 264 } else {
260 wavNumberSamples = longdata; 265 wavNumberSamples = longdata;
261 qDebug("file has length of %d \nlasting %d seconds", longdata, 266 qDebug("file has length of %d \nlasting %d seconds", (int)longdata,
262 (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) ); 267 (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) );
263// wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); 268// wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8));
264 269
265 return longdata; 270 return longdata;
266 } 271 }