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
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.
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
)
40 pSkel
= new wWAVAudio(sFile
, di
, rc
);
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()
60 bool wWAVAudio::static_isData()
65 bool wWAVAudio::static_isSession()
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()
90 if (false == FileWriter::setUp())
105 off
+= DOS
->Write(fh
, &i32
, 4);
107 off
+= DOS
->Write(fh
, &i32
, 4);
111 off
+= DOS
->Write(fh
, &i32
, 4); // WAVE
115 off
+= DOS
->Write(fh
, &i32
, 4); // fmt
118 off
+= DOS
->Write(fh
, &i32
, 4); // fmt size
121 off
+= DOS
->Write(fh
, &i16
, 2); // uncompressed format
124 off
+= DOS
->Write(fh
, &i16
, 2); // 2 channels
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
133 off
+= DOS
->Write(fh
, &i16
, 2); // sample size * channels
136 off
+= DOS
->Write(fh
, &i16
, 2); // sample resolution
140 off
+= DOS
->Write(fh
, &i32
, 4); // data
142 off
+= DOS
->Write(fh
, &i32
, 4); // data length
148 void wWAVAudio::cleanUp()
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();