disable the unrecognized nls and x flags
[AROS-Contrib.git] / FryingPan / DTLib / wWAVAudio.cpp
blob83b7c9b5d69f37b3c287a63930529298e909029c
1 /*
2 * FryingPan - Amiga CD/DVD Recording Software (User Interface and supporting Libraries only)
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "wWAVAudio.h"
21 #include <libclass/dos.h>
22 #include <libclass/exec.h>
23 #include <libclass/utility.h>
24 #include <exec/lists.h>
25 #include <Generic/HookT.h>
27 #define FLIP32(a) ((((a)&0xff000000)>>24) | (((a)&0xff0000)>>8) | (((a)&0xff00)<<8) | (((a)&0xff)<<24))
28 #define FLIP16(a) ((((a)&0xff00)>>8) | (((a)&0xff)<<8))
30 #define MKID(a,b,c,d) (((a&255)<<24)|((b&255)<<16)|((c&255)<<8)|(d&255))
31 #define ID_RIFF MKID('R','I','F','F')
32 #define ID_WAVE MKID('W','A','V','E')
33 #define ID_fmt MKID('f','m','t',' ')
34 #define ID_data MKID('d','a','t','a')
37 IFileWriter *wWAVAudio::openWrite(const char* sFile, const IOptItem *di, EDtError &rc)
39 wWAVAudio *pSkel = 0;
40 pSkel = new wWAVAudio(sFile, di, rc);
41 return pSkel;
44 wWAVAudio::wWAVAudio(const char *sName, const IOptItem *di, EDtError &rc)
45 : FileWriter(sName, rc)
47 setLittleEndian(true);
50 const char *wWAVAudio::static_getName()
52 return "WAV Audio Track";
55 bool wWAVAudio::static_isAudio()
57 return true;
60 bool wWAVAudio::static_isData()
62 return false;
65 bool wWAVAudio::static_isSession()
67 return false;
70 bool wWAVAudio::isAudio()
72 return static_isAudio();
75 bool wWAVAudio::isData()
77 return static_isData();
80 const char *wWAVAudio::getName()
82 return static_getName();
85 bool wWAVAudio::setUp()
87 BPTR fh;
88 long off = 0;
90 if (false == FileWriter::setUp())
92 return false;
95 fh = getFile();
96 ASSERT(fh != 0);
98 if (fh)
100 int i32;
101 short i16;
103 i32 = ID_RIFF;
104 i32 = L2BE(i32);
105 off += DOS->Write(fh, &i32, 4);
106 offTotal = off;
107 off += DOS->Write(fh, &i32, 4);
109 i32 = ID_WAVE;
110 i32 = L2BE(i32);
111 off += DOS->Write(fh, &i32, 4); // WAVE
113 i32 = ID_fmt;
114 i32 = L2BE(i32);
115 off += DOS->Write(fh, &i32, 4); // fmt
117 i32 = L2LE(16);
118 off += DOS->Write(fh, &i32, 4); // fmt size
120 i16 = W2LE(1);
121 off += DOS->Write(fh, &i16, 2); // uncompressed format
123 i16 = W2LE(2);
124 off += DOS->Write(fh, &i16, 2); // 2 channels
126 i32 = L2LE(44100);
127 off += DOS->Write(fh, &i32, 4); // frequency (44kHz)
129 i32 = L2LE(44100*2*2);
130 off += DOS->Write(fh, &i32, 4); // bytes per second
132 i16 = W2LE(2*2);
133 off += DOS->Write(fh, &i16, 2); // sample size * channels
135 i16 = W2LE(16);
136 off += DOS->Write(fh, &i16, 2); // sample resolution
138 i32 = ID_data;
139 i32 = L2BE(i32);
140 off += DOS->Write(fh, &i32, 4); // data
141 offSoundChunk = off;
142 off += DOS->Write(fh, &i32, 4); // data length
145 return true;
148 void wWAVAudio::cleanUp()
150 BPTR fh;
151 long off = 0;
152 int i32;
154 fh = getFile();
155 if (fh)
157 off = DOS->Seek(fh, offTotal, OFFSET_BEGINNING); // and grab the total size.
158 i32 = L2LE(off - offTotal - 4);
159 DOS->Write(fh, &i32, 4); // write total size.
160 i32 = L2LE(off - offSoundChunk - 4);
161 DOS->Seek(fh, offSoundChunk, OFFSET_BEGINNING);
162 DOS->Write(fh, &i32, 4); // write ssnd chunk size
165 FileWriter::cleanUp();
168 // vim: ts=3 et