aboutsummaryrefslogtreecommitdiff
path: root/sound/softsynth
diff options
context:
space:
mode:
authorJohannes Schickel2010-12-08 01:35:12 +0000
committerJohannes Schickel2010-12-08 01:35:12 +0000
commitd451084fb44a536d0f161bccb5b73088df253c9c (patch)
treec3a7b31db380016a5b1734668b955116be937973 /sound/softsynth
parent08262d90fb214f292aacf2b927ecb39fe50aef66 (diff)
downloadscummvm-rg350-d451084fb44a536d0f161bccb5b73088df253c9c.tar.gz
scummvm-rg350-d451084fb44a536d0f161bccb5b73088df253c9c.tar.bz2
scummvm-rg350-d451084fb44a536d0f161bccb5b73088df253c9c.zip
MT32: Get rid of ANSIFile.
svn-id: r54827
Diffstat (limited to 'sound/softsynth')
-rw-r--r--sound/softsynth/mt32/mt32_file.cpp110
-rw-r--r--sound/softsynth/mt32/mt32_file.h17
-rw-r--r--sound/softsynth/mt32/synth.cpp20
3 files changed, 40 insertions, 107 deletions
diff --git a/sound/softsynth/mt32/mt32_file.cpp b/sound/softsynth/mt32/mt32_file.cpp
index ce5c2874c4..cdf9fa13f6 100644
--- a/sound/softsynth/mt32/mt32_file.cpp
+++ b/sound/softsynth/mt32/mt32_file.cpp
@@ -20,95 +20,51 @@
*/
-// FIXME: Disable symbol overrides so that we can use system headers.
-// But we *really* should get rid of this usage of FILE, fopen etc.
-#define FORBIDDEN_SYMBOL_ALLOW_ALL
-
-
-#include <stdio.h>
-
#include "mt32emu.h"
namespace MT32Emu {
- bool ANSIFile::open(const char *filename, OpenMode mode) {
- const char *fmode;
- if (mode == OpenMode_read) {
- fmode = "rb";
- } else {
- fmode = "wb";
- }
- fp = fopen(filename, fmode);
- return (fp != NULL);
- }
-
- void ANSIFile::close() {
- fclose((FILE *)fp);
- }
+bool File::readBit16u(Bit16u *in) {
+ Bit8u b[2];
+ if (read(&b[0], 2) != 2)
+ return false;
+ *in = ((b[0] << 8) | b[1]);
+ return true;
+}
- size_t ANSIFile::read(void *in, size_t size) {
- return fread(in, 1, size, (FILE *)fp);
- }
+bool File::readBit32u(Bit32u *in) {
+ Bit8u b[4];
+ if (read(&b[0], 4) != 4)
+ return false;
+ *in = ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
+ return true;
+}
- bool ANSIFile::readBit8u(Bit8u *in) {
- int c = fgetc((FILE *)fp);
- if (c == EOF)
- return false;
- *in = (Bit8u)c;
- return true;
+bool File::writeBit16u(Bit16u out) {
+ if (!writeBit8u((Bit8u)((out & 0xFF00) >> 8))) {
+ return false;
}
-
- bool File::readBit16u(Bit16u *in) {
- Bit8u b[2];
- if (read(&b[0], 2) != 2)
- return false;
- *in = ((b[0] << 8) | b[1]);
- return true;
+ if (!writeBit8u((Bit8u)(out & 0x00FF))) {
+ return false;
}
+ return true;
+}
- bool File::readBit32u(Bit32u *in) {
- Bit8u b[4];
- if (read(&b[0], 4) != 4)
- return false;
- *in = ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
- return true;
+bool File::writeBit32u(Bit32u out) {
+ if (!writeBit8u((Bit8u)((out & 0xFF000000) >> 24))) {
+ return false;
}
-
- size_t ANSIFile::write(const void *out, size_t size) {
- return fwrite(out, 1, size, (FILE *)fp);
+ if (!writeBit8u((Bit8u)((out & 0x00FF0000) >> 16))) {
+ return false;
}
-
- bool ANSIFile::writeBit8u(Bit8u out) {
- return fputc(out, (FILE *)fp) != EOF;
+ if (!writeBit8u((Bit8u)((out & 0x0000FF00) >> 8))) {
+ return false;
}
-
- bool File::writeBit16u(Bit16u out) {
- if (!writeBit8u((Bit8u)((out & 0xFF00) >> 8))) {
- return false;
- }
- if (!writeBit8u((Bit8u)(out & 0x00FF))) {
- return false;
- }
- return true;
+ if (!writeBit8u((Bit8u)(out & 0x000000FF))) {
+ return false;
}
+ return true;
+}
- bool File::writeBit32u(Bit32u out) {
- if (!writeBit8u((Bit8u)((out & 0xFF000000) >> 24))) {
- return false;
- }
- if (!writeBit8u((Bit8u)((out & 0x00FF0000) >> 16))) {
- return false;
- }
- if (!writeBit8u((Bit8u)((out & 0x0000FF00) >> 8))) {
- return false;
- }
- if (!writeBit8u((Bit8u)(out & 0x000000FF))) {
- return false;
- }
- return true;
- }
+} // End of namespace MT32Emu
- bool ANSIFile::isEOF() {
- return feof((FILE *)fp) != 0;
- }
-}
diff --git a/sound/softsynth/mt32/mt32_file.h b/sound/softsynth/mt32/mt32_file.h
index b311ad9626..e6641660ee 100644
--- a/sound/softsynth/mt32/mt32_file.h
+++ b/sound/softsynth/mt32/mt32_file.h
@@ -22,7 +22,7 @@
#ifndef MT32EMU_FILE_H
#define MT32EMU_FILE_H
-#include <stdio.h>
+#include "common/scummsys.h"
namespace MT32Emu {
@@ -47,19 +47,6 @@ public:
virtual bool isEOF() = 0;
};
-class ANSIFile: public File {
-private:
- void *fp;
-public:
- bool open(const char *filename, OpenMode mode);
- void close();
- size_t read(void *in, size_t size);
- bool readBit8u(Bit8u *in);
- size_t write(const void *out, size_t size);
- bool writeBit8u(Bit8u out);
- bool isEOF();
-};
-
-}
+} // End of namespace MT32Emu
#endif
diff --git a/sound/softsynth/mt32/synth.cpp b/sound/softsynth/mt32/synth.cpp
index 6a16db22ec..8cf2233654 100644
--- a/sound/softsynth/mt32/synth.cpp
+++ b/sound/softsynth/mt32/synth.cpp
@@ -162,21 +162,11 @@ void Synth::initReverb(Bit8u newRevMode, Bit8u newRevTime, Bit8u newRevLevel) {
}
File *Synth::openFile(const char *filename, File::OpenMode mode) {
- if (myProp.openFile != NULL) {
- return myProp.openFile(myProp.userData, filename, mode);
- }
- char pathBuf[2048];
- if (myProp.baseDir != NULL) {
- strcpy(&pathBuf[0], myProp.baseDir);
- strcat(&pathBuf[0], filename);
- filename = pathBuf;
- }
- ANSIFile *file = new ANSIFile();
- if (!file->open(filename, mode)) {
- delete file;
- return NULL;
- }
- return file;
+ // It should never happen that openFile is NULL in our use case.
+ // Just to cover the case where something is horrible wrong we
+ // use an assert here.
+ assert(myProp.openFile != NULL);
+ return myProp.openFile(myProp.userData, filename, mode);
}
void Synth::closeFile(File *file) {