Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126742
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/allegro/sound.cpp b/util/allegro/sound.cpp
index c9cc5909..31a9f0aa 100644
--- a/util/allegro/sound.cpp
+++ b/util/allegro/sound.cpp
@@ -1,106 +1,106 @@
#include <allegro.h>
#include <string>
#include "../memory.h"
#include "../sound.h"
#include "configuration.h"
#include "../load_exception.h"
using namespace std;
/* allegro uses volume in the range of 0-255 */
static const int MAX_VOLUME = 255;
Sound::Sound():
own(NULL){
}
Sound::Sound(const char * data, int length):
own(NULL){
PACKFILE_VTABLE table = Memory::makeTable();
Memory::memory memory((unsigned char *) data, length);
PACKFILE * pack = pack_fopen_vtable(&table, &memory);
this->data.sample = load_wav_pf(pack);
pack_fclose(pack);
if (!this->data.sample){
throw LoadException("Could not load wav data");
}
own = new int;
*own = 1;
}
Sound::Sound(const string & path) throw( LoadException ):
own(NULL){
data.sample = load_sample( path.c_str() );
if ( !data.sample ){
string xf( "Could not load " );
xf += path;
throw LoadException(xf);
}
own = new int;
*own = 1;
}
void Sound::destroy(){
if ( own ){
*own -= 1;
if ( *own == 0 ){
delete own;
destroy_sample(data.sample);
own = NULL;
}
}
}
void Sound::initialize(){
/* default for alsa is 8, so reserve a few more */
reserve_voices(16, -1);
/* is calling this function a good idea? */
set_volume_per_voice(0);
// out<<"Install sound: "<<install_sound( DIGI_AUTODETECT, MIDI_NONE, "" )<<endl;
install_sound(DIGI_AUTODETECT, MIDI_NONE, "");
}
void Sound::stop(){
if (data.sample){
stop_sample(data.sample);
}
}
static double scaleVolume(double v){
return v * Configuration::getSoundVolume() / 100.0;
}
void Sound::play(){
if (data.sample){
- play_sample(data.sample, scaleVolume(1.0), 128, 1000, false);
+ play_sample(data.sample, (int)(scaleVolume(1.0) * MAX_VOLUME), 128, 1000, false);
}
}
void Sound::play(double volume, int pan){
if ( data.sample){
if (pan > 255 ){
pan = 255;
} else if ( pan < 0 ){
pan = 0;
}
int v = volume;
if (v < 0){
v = 0;
} else if (v > 1){
v = 1;
}
play_sample( data.sample, (int)(scaleVolume(v) * MAX_VOLUME), pan, 1000, false );
}
}
void Sound::playLoop(){
if ( data.sample ){
play_sample( data.sample, 255, 128, 1000, true );
}
}
diff --git a/util/sdl/sound.cpp b/util/sdl/sound.cpp
index 1b1118f5..2dd8824e 100644
--- a/util/sdl/sound.cpp
+++ b/util/sdl/sound.cpp
@@ -1,69 +1,71 @@
#include "../sound.h"
#include <SDL.h>
#include "mixer/SDL_mixer.h"
Sound::Sound():
own(NULL){
}
/* 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){
data.chunk = Mix_LoadWAV(path.c_str());
if (!data.chunk){
printf("Can't load sound %s\n", path.c_str());
// throw LoadException("Could not load sound " + path);
} else {
own = new int;
*own = 1;
}
}
void Sound::initialize(){
// int audio_rate = 22050;
/* allegro uses 44100 by default with alsa9 */
int audio_rate = 44100;
// Uint16 audio_format = AUDIO_S16;
Uint16 audio_format = MIX_DEFAULT_FORMAT;
int audio_channels = 2;
int audio_buffers = 4096;
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
printf("Unable to open audio: %s!\n", Mix_GetError());
// exit(1);
}
}
void Sound::play(){
+ /* FIXME: scale the volume based on the configuration sound setting */
Mix_VolumeChunk(data.chunk, MIX_MAX_VOLUME);
Mix_PlayChannel(-1, data.chunk, 0);
}
void Sound::play(double volume, int pan){
+ /* FIXME: scale the volume based on the configuration sound setting */
Mix_VolumeChunk(data.chunk, (int)(volume * MIX_MAX_VOLUME));
Mix_PlayChannel(-1, data.chunk, 0);
}
void Sound::playLoop(){
/* TODO */
}
void Sound::destroy(){
if ( own ){
*own -= 1;
if ( *own == 0 ){
delete own;
Mix_FreeChunk(data.chunk);
own = NULL;
}
}
}
void Sound::stop(){
if (data.channel != -1){
Mix_HaltChannel(data.channel);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 12:48 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69105
Default Alt Text
(4 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline