Commit 2334cb55 authored by alistert's avatar alistert

Made sound effect volume adjustable.

parent 7cb1543f
...@@ -82,7 +82,7 @@ void audioCallback (void * userdata, unsigned char * stream, int len) { ...@@ -82,7 +82,7 @@ void audioCallback (void * userdata, unsigned char * stream, int len) {
SDL_MixAudio(stream, SDL_MixAudio(stream,
sounds[count].data + sounds[count].position, len, sounds[count].data + sounds[count].position, len,
SDL_MIX_MAXVOLUME >> 2); soundsVolume * SDL_MIX_MAXVOLUME / MAX_VOLUME);
sounds[count].position += len; sounds[count].position += len;
...@@ -93,7 +93,7 @@ void audioCallback (void * userdata, unsigned char * stream, int len) { ...@@ -93,7 +93,7 @@ void audioCallback (void * userdata, unsigned char * stream, int len) {
SDL_MixAudio(stream, SDL_MixAudio(stream,
sounds[count].data + sounds[count].position, sounds[count].data + sounds[count].position,
sounds[count].length - sounds[count].position, sounds[count].length - sounds[count].position,
SDL_MIX_MAXVOLUME >> 2); soundsVolume * SDL_MIX_MAXVOLUME / MAX_VOLUME);
sounds[count].position = -1; sounds[count].position = -1;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Part of the OpenJazz project * Part of the OpenJazz project
* *
* *
* Copyright (c) 2005-2009 Alister Thomson * Copyright (c) 2005-2010 Alister Thomson
* *
* OpenJazz is distributed under the terms of * OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0 * the GNU General Public License, version 2.0
...@@ -50,6 +50,8 @@ ...@@ -50,6 +50,8 @@
#define S_ROCKET 18 #define S_ROCKET 18
#define S_STOP 19 #define S_STOP 19
#define S_BLOCK 20 #define S_BLOCK 20
#define MAX_VOLUME 100
// Datatype // Datatype
...@@ -67,8 +69,14 @@ typedef struct { ...@@ -67,8 +69,14 @@ typedef struct {
// Variables // Variables
EXTERN Sound *sounds; EXTERN Sound *sounds;
EXTERN int nSounds; EXTERN int nSounds;
EXTERN char soundsVolume;
#if defined(WIZ) || defined(GP2X)
EXTERN int volume;
EXTERN int volume_direction;
#endif
// Functions // Functions
......
...@@ -48,9 +48,7 @@ ...@@ -48,9 +48,7 @@
#include <string.h> #include <string.h>
#if defined(WIZ) || defined(GP2X) #if defined(WIZ) || defined(GP2X)
#include "platforms/wiz.h" #include "platforms/wiz.h"
extern int volume;
extern int volume_direction;
#endif #endif
#ifdef __SYMBIAN32__ #ifdef __SYMBIAN32__
...@@ -58,7 +56,7 @@ extern char KOpenJazzPath[256]; ...@@ -58,7 +56,7 @@ extern char KOpenJazzPath[256];
#endif #endif
#ifdef SCALE #ifdef SCALE
#include "io/gfx/scale2x/scalebit.h" #include "io/gfx/scale2x/scalebit.h"
#endif #endif
int loadMain (int argc, char *argv[]) { int loadMain (int argc, char *argv[]) {
...@@ -83,11 +81,11 @@ int loadMain (int argc, char *argv[]) { ...@@ -83,11 +81,11 @@ int loadMain (int argc, char *argv[]) {
#ifdef __SYMBIAN32__ #ifdef __SYMBIAN32__
#ifdef UIQ3 #ifdef UIQ3
firstPath = new Path(firstPath, createString("c:\\shared\\openjazz\\")); firstPath = new Path(firstPath, createString("c:\\shared\\openjazz\\"));
#else #else
firstPath = new Path(firstPath, createString("c:\\data\\openjazz\\")); firstPath = new Path(firstPath, createString("c:\\data\\openjazz\\"));
#endif #endif
firstPath = new Path(firstPath, createString(KOpenJazzPath)); firstPath = new Path(firstPath, createString(KOpenJazzPath));
#endif #endif
...@@ -144,9 +142,9 @@ int loadMain (int argc, char *argv[]) { ...@@ -144,9 +142,9 @@ int loadMain (int argc, char *argv[]) {
#ifdef HOMEDIR #ifdef HOMEDIR
#ifdef WIN32 #ifdef WIN32
firstPath = new Path(firstPath, createString(getenv("HOME"), "\\")); firstPath = new Path(firstPath, createString(getenv("HOME"), "\\"));
#else #else
firstPath = new Path(firstPath, createString(getenv("HOME"), "/.")); firstPath = new Path(firstPath, createString(getenv("HOME"), "/."));
#endif #endif
#endif #endif
...@@ -165,7 +163,14 @@ int loadMain (int argc, char *argv[]) { ...@@ -165,7 +163,14 @@ int loadMain (int argc, char *argv[]) {
#ifndef FULLSCREEN_ONLY #ifndef FULLSCREEN_ONLY
fullscreen = false; fullscreen = false;
#endif #endif
// Sound settings
#if defined(WIZ) || defined(GP2X)
volume = 40;
#endif
soundsVolume = MAX_VOLUME >> 2;
// Create the player's name // Create the player's name
characterName = createEditableString(CHAR_NAME); characterName = createEditableString(CHAR_NAME);
...@@ -229,6 +234,10 @@ int loadMain (int argc, char *argv[]) { ...@@ -229,6 +234,10 @@ int loadMain (int argc, char *argv[]) {
characterCols[2] = file->loadChar(); characterCols[2] = file->loadChar();
characterCols[3] = file->loadChar(); characterCols[3] = file->loadChar();
// Read the sound effect volume
soundsVolume = file->loadChar();
if (soundsVolume > MAX_VOLUME) soundsVolume = MAX_VOLUME;
delete file; delete file;
} else { } else {
...@@ -538,6 +547,9 @@ void freeMain () { ...@@ -538,6 +547,9 @@ void freeMain () {
file->storeChar(characterCols[2]); file->storeChar(characterCols[2]);
file->storeChar(characterCols[3]); file->storeChar(characterCols[3]);
// Write the sound effect volume
file->storeChar(soundsVolume);
delete file; delete file;
} else { } else {
......
...@@ -57,6 +57,7 @@ class Menu { ...@@ -57,6 +57,7 @@ class Menu {
#ifdef SCALE #ifdef SCALE
int setupScaling (); int setupScaling ();
#endif #endif
int setupSound ();
public: public:
SDL_Color palettes[4][256]; SDL_Color palettes[4][256];
......
...@@ -461,9 +461,44 @@ int Menu::setupScaling () { ...@@ -461,9 +461,44 @@ int Menu::setupScaling () {
#endif #endif
int Menu::setupSound () {
while (true) {
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
if (controls.release(C_ESCAPE)) return E_NONE;
if (controls.release(C_ENTER)) return E_NONE;
SDL_Delay(T_FRAME);
clearScreen(0);
// Volume
fontmn2->mapPalette(240, 8, 114, 16);
fontmn2->showString("effect volume", canvasW >> 2, canvasH >> 1);
fontmn2->restorePalette();
drawRect((canvasW >> 2) + 120, canvasH >> 1, soundsVolume >> 1, 11, 175);
if (controls.release(C_LEFT)) soundsVolume -= 4;
if (soundsVolume < 0) soundsVolume = 0;
if (controls.release(C_RIGHT)) soundsVolume += 4;
if (soundsVolume > MAX_VOLUME) soundsVolume = MAX_VOLUME;
}
return E_NONE;
}
int Menu::setup () { int Menu::setup () {
const char *setupOptions[5] = {"character", "keyboard", "joystick", "resolution", "scaling"}; const char *setupOptions[6] = {"character", "keyboard", "joystick", "resolution", "scaling", "sound"};
const char *setupCharacterOptions[5] = {"name", "fur", "bandana", "gun", "wristband"}; const char *setupCharacterOptions[5] = {"name", "fur", "bandana", "gun", "wristband"};
const char *setupCharacterColOptions[8] = {"white", "red", "orange", "yellow", "green", "blue", "animation 1", "animation 2"}; const char *setupCharacterColOptions[8] = {"white", "red", "orange", "yellow", "green", "blue", "animation 1", "animation 2"};
const unsigned char setupCharacterCols[8] = {PC_WHITE, PC_RED, PC_ORANGE, const unsigned char setupCharacterCols[8] = {PC_WHITE, PC_RED, PC_ORANGE,
...@@ -475,7 +510,7 @@ int Menu::setup () { ...@@ -475,7 +510,7 @@ int Menu::setup () {
while (true) { while (true) {
ret = generic(setupOptions, 5, &option); ret = generic(setupOptions, 6, &option);
if (ret == E_UNUSED) return E_NONE; if (ret == E_UNUSED) return E_NONE;
if (ret < 0) return ret; if (ret < 0) return ret;
...@@ -553,6 +588,12 @@ int Menu::setup () { ...@@ -553,6 +588,12 @@ int Menu::setup () {
break; break;
case 5:
setupSound();
break;
} }
} }
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
int volume = 40; #include "io/sound.h"
int volume_direction;
void WIZ_AdjustVolume( int direction ) void WIZ_AdjustVolume( int direction )
{ {
if( direction != VOLUME_NOCHG ) if( direction != VOLUME_NOCHG )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment