Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126831
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/sound.cpp b/util/allegro/sound.cpp
similarity index 96%
copy from util/sound.cpp
copy to util/allegro/sound.cpp
index 98d62819..d2537bf1 100644
--- a/util/sound.cpp
+++ b/util/allegro/sound.cpp
@@ -1,125 +1,125 @@
#include <allegro.h>
#include <string>
-#include "memory.h"
-#include "sound.h"
+#include "../memory.h"
+#include "../sound.h"
#include "configuration.h"
-#include "load_exception.h"
+#include "../load_exception.h"
using namespace std;
Sound::Sound():
my_sound(NULL),
own(NULL){
}
Sound::Sound(const char * data, int length):
my_sound(NULL),
own(NULL){
PACKFILE_VTABLE table = Memory::makeTable();
Memory::memory memory((unsigned char *) data, length);
PACKFILE * pack = pack_fopen_vtable(&table, &memory);
my_sound = load_wav_pf(pack);
pack_fclose(pack);
if (!my_sound){
throw LoadException("Could not load wav data");
}
own = new int;
*own = 1;
}
Sound::Sound(const string & path) throw( LoadException ):
my_sound(NULL ),
own(NULL){
my_sound = load_sample( path.c_str() );
if ( !my_sound ){
string xf( "Could not load " );
xf += path;
throw LoadException(xf);
}
own = new int;
*own = 1;
}
Sound::Sound( const Sound & copy ):
my_sound( NULL ),
own( NULL ){
own = copy.own;
if ( own ){
*own += 1;
}
my_sound = copy.my_sound;
}
void Sound::destroy(){
if ( own ){
*own -= 1;
if ( *own == 0 ){
delete own;
destroy_sample( my_sound );
own = NULL;
}
}
}
Sound & Sound::operator=( const Sound & rhs ){
if ( own ){
destroy();
}
own = rhs.own;
if ( own ){
*own += 1;
}
my_sound = rhs.my_sound;
return *this;
}
void Sound::stop(){
if (my_sound){
stop_sample(my_sound);
}
}
int scaleVolume(int v){
return (int)(v * (int) Configuration::getSoundVolume() / 100.0);
}
void Sound::play(){
if (my_sound){
play_sample(my_sound, scaleVolume(255), 128, 1000, false);
}
}
void Sound::play(int volume, int pan){
if ( my_sound ){
int p = pan;
if ( p > 255 ){
p = 255;
} else if ( p < 0 ){
p = 0;
}
int v = volume;
if (v < 0){
v = 0;
} else if (v > 255){
v = 255;
}
play_sample( my_sound, scaleVolume(v), p, 1000, false );
}
}
void Sound::playLoop(){
if ( my_sound ){
play_sample( my_sound, 255, 128, 1000, true );
}
}
Sound::~Sound(){
destroy();
}
diff --git a/util/compress.cpp b/util/compress.cpp
index 6953960a..8623ce3b 100644
--- a/util/compress.cpp
+++ b/util/compress.cpp
@@ -1,28 +1,33 @@
+#ifdef USE_ALLEGRO
#include <allegro.h>
+#endif
+
#include "compress.h"
#include "memory.h"
#include "globals.h"
namespace Compress{
void testCompression(unsigned char * input, int length){
+#ifdef USE_ALLEGRO
unsigned char * data = new unsigned char[length*2];
PACKFILE_VTABLE table = Memory::makeTable();
Memory::memory memory(data, length*2);
PACKFILE * pack = pack_fopen_vtable(&table, &memory);
LZSS_PACK_DATA * lzss = create_lzss_pack_data();
int r = lzss_write(pack, lzss, length, input, 1);
if (r != 0){
// printf("lzss error %d: %s!\n", r, ustrerror(errno));
exit(-1);
}
free_lzss_pack_data(lzss);
pack_fclose(pack);
Global::debug(0) << "Compressed " << length << " to " << memory.getSize() << " ratio is " << ((double)memory.getSize() / length) << std::endl;
delete[] data;
+#endif
}
}
diff --git a/util/sdl/sound.cpp b/util/sdl/sound.cpp
new file mode 100644
index 00000000..2d421dc8
--- /dev/null
+++ b/util/sdl/sound.cpp
@@ -0,0 +1,44 @@
+#include "../sound.h"
+
+Sound::Sound(){
+ /* TODO */
+}
+
+/* create from wav file (riff header + pcm) */
+Sound::Sound(const char * data, int length){
+ /* TODO */
+}
+
+/* load from path */
+Sound::Sound(const std::string & path) throw (LoadException){
+ /* TODO */
+}
+
+Sound::Sound(const Sound & copy){
+ /* TODO */
+}
+
+Sound & Sound::operator=( const Sound & rhs ){
+ /* TODO */
+ return *this;
+}
+
+void Sound::play(){
+ /* TODO */
+}
+
+void Sound::play( int volume, int pan ){
+ /* TODO */
+}
+
+void Sound::playLoop(){
+ /* TODO */
+}
+
+void Sound::stop(){
+ /* TODO */
+}
+
+Sound::~Sound(){
+ /* TODO */
+}
diff --git a/util/sound.cpp b/util/sound.cpp
index 98d62819..6fc2f406 100644
--- a/util/sound.cpp
+++ b/util/sound.cpp
@@ -1,125 +1,6 @@
-#include <allegro.h>
-#include <string>
-
-#include "memory.h"
-#include "sound.h"
-#include "configuration.h"
-#include "load_exception.h"
-
-using namespace std;
-
-Sound::Sound():
-my_sound(NULL),
-own(NULL){
-}
-
-Sound::Sound(const char * data, int length):
-my_sound(NULL),
-own(NULL){
- PACKFILE_VTABLE table = Memory::makeTable();
- Memory::memory memory((unsigned char *) data, length);
-
- PACKFILE * pack = pack_fopen_vtable(&table, &memory);
- my_sound = load_wav_pf(pack);
- pack_fclose(pack);
- if (!my_sound){
- throw LoadException("Could not load wav data");
- }
-
- own = new int;
- *own = 1;
-}
-
-Sound::Sound(const string & path) throw( LoadException ):
-my_sound(NULL ),
-own(NULL){
- my_sound = load_sample( path.c_str() );
-
- if ( !my_sound ){
- string xf( "Could not load " );
- xf += path;
- throw LoadException(xf);
- }
-
- own = new int;
- *own = 1;
-}
-
-Sound::Sound( const Sound & copy ):
-my_sound( NULL ),
-own( NULL ){
- own = copy.own;
- if ( own ){
- *own += 1;
- }
- my_sound = copy.my_sound;
-}
-
-void Sound::destroy(){
- if ( own ){
- *own -= 1;
- if ( *own == 0 ){
- delete own;
- destroy_sample( my_sound );
- own = NULL;
- }
- }
-}
-
-Sound & Sound::operator=( const Sound & rhs ){
- if ( own ){
- destroy();
- }
- own = rhs.own;
- if ( own ){
- *own += 1;
- }
- my_sound = rhs.my_sound;
-
- return *this;
-}
-
-void Sound::stop(){
- if (my_sound){
- stop_sample(my_sound);
- }
-}
-
-int scaleVolume(int v){
- return (int)(v * (int) Configuration::getSoundVolume() / 100.0);
-}
-
-void Sound::play(){
- if (my_sound){
- play_sample(my_sound, scaleVolume(255), 128, 1000, false);
- }
-}
-
-void Sound::play(int volume, int pan){
- if ( my_sound ){
- int p = pan;
- if ( p > 255 ){
- p = 255;
- } else if ( p < 0 ){
- p = 0;
- }
- int v = volume;
- if (v < 0){
- v = 0;
- } else if (v > 255){
- v = 255;
- }
-
- play_sample( my_sound, scaleVolume(v), p, 1000, false );
- }
-}
-
-void Sound::playLoop(){
- if ( my_sound ){
- play_sample( my_sound, 255, 128, 1000, true );
- }
-}
-
-Sound::~Sound(){
- destroy();
-}
+#ifdef USE_ALLEGRO
+#include "allegro/sound.cpp"
+#endif
+#ifdef USE_SDL
+#include "sdl/sound.cpp"
+#endif
diff --git a/util/sound.h b/util/sound.h
index 86eb4f27..c3c3298e 100644
--- a/util/sound.h
+++ b/util/sound.h
@@ -1,39 +1,38 @@
-#ifndef _pain_sound_h
-#define _pain_sound_h
+#ifndef _paintown_sound_h
+#define _paintown_sound_h
#include <string>
#include "load_exception.h"
struct SAMPLE;
/* a sound! */
class Sound{
public:
Sound();
/* create from wav file (riff header + pcm) */
Sound(const char * data, int length);
/* load from path */
- Sound( const std::string & path ) throw( LoadException );
- Sound( const Sound & copy );
+ Sound(const std::string & path) throw (LoadException);
+ Sound(const Sound & copy);
Sound & operator=( const Sound & rhs );
void play();
void play( int volume, int pan );
void playLoop();
void stop();
virtual ~Sound();
protected:
void destroy();
SAMPLE * my_sound;
/* reference counting */
int * own;
-
};
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 1:12 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69187
Default Alt Text
(7 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline