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) {
SDL_MixAudio(stream,
sounds[count].data + sounds[count].position, len,
SDL_MIX_MAXVOLUME >> 2);
soundsVolume * SDL_MIX_MAXVOLUME / MAX_VOLUME);
sounds[count].position += len;
......@@ -93,7 +93,7 @@ void audioCallback (void * userdata, unsigned char * stream, int len) {
SDL_MixAudio(stream,
sounds[count].data + sounds[count].position,
sounds[count].length - sounds[count].position,
SDL_MIX_MAXVOLUME >> 2);
soundsVolume * SDL_MIX_MAXVOLUME / MAX_VOLUME);
sounds[count].position = -1;
......
......@@ -8,7 +8,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -50,6 +50,8 @@
#define S_ROCKET 18
#define S_STOP 19
#define S_BLOCK 20
#define MAX_VOLUME 100
// Datatype
......@@ -67,8 +69,14 @@ typedef struct {
// Variables
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
......
......@@ -48,9 +48,7 @@
#include <string.h>
#if defined(WIZ) || defined(GP2X)
#include "platforms/wiz.h"
extern int volume;
extern int volume_direction;
#include "platforms/wiz.h"
#endif
#ifdef __SYMBIAN32__
......@@ -58,7 +56,7 @@ extern char KOpenJazzPath[256];
#endif
#ifdef SCALE
#include "io/gfx/scale2x/scalebit.h"
#include "io/gfx/scale2x/scalebit.h"
#endif
int loadMain (int argc, char *argv[]) {
......@@ -83,11 +81,11 @@ int loadMain (int argc, char *argv[]) {
#ifdef __SYMBIAN32__
#ifdef UIQ3
firstPath = new Path(firstPath, createString("c:\\shared\\openjazz\\"));
firstPath = new Path(firstPath, createString("c:\\shared\\openjazz\\"));
#else
firstPath = new Path(firstPath, createString("c:\\data\\openjazz\\"));
firstPath = new Path(firstPath, createString("c:\\data\\openjazz\\"));
#endif
firstPath = new Path(firstPath, createString(KOpenJazzPath));
firstPath = new Path(firstPath, createString(KOpenJazzPath));
#endif
......@@ -144,9 +142,9 @@ int loadMain (int argc, char *argv[]) {
#ifdef HOMEDIR
#ifdef WIN32
firstPath = new Path(firstPath, createString(getenv("HOME"), "\\"));
firstPath = new Path(firstPath, createString(getenv("HOME"), "\\"));
#else
firstPath = new Path(firstPath, createString(getenv("HOME"), "/."));
firstPath = new Path(firstPath, createString(getenv("HOME"), "/."));
#endif
#endif
......@@ -165,7 +163,14 @@ int loadMain (int argc, char *argv[]) {
#ifndef FULLSCREEN_ONLY
fullscreen = false;
#endif
// Sound settings
#if defined(WIZ) || defined(GP2X)
volume = 40;
#endif
soundsVolume = MAX_VOLUME >> 2;
// Create the player's name
characterName = createEditableString(CHAR_NAME);
......@@ -229,6 +234,10 @@ int loadMain (int argc, char *argv[]) {
characterCols[2] = file->loadChar();
characterCols[3] = file->loadChar();
// Read the sound effect volume
soundsVolume = file->loadChar();
if (soundsVolume > MAX_VOLUME) soundsVolume = MAX_VOLUME;
delete file;
} else {
......@@ -538,6 +547,9 @@ void freeMain () {
file->storeChar(characterCols[2]);
file->storeChar(characterCols[3]);
// Write the sound effect volume
file->storeChar(soundsVolume);
delete file;
} else {
......
......@@ -57,6 +57,7 @@ class Menu {
#ifdef SCALE
int setupScaling ();
#endif
int setupSound ();
public:
SDL_Color palettes[4][256];
......
......@@ -461,9 +461,44 @@ int Menu::setupScaling () {
#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 () {
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 *setupCharacterColOptions[8] = {"white", "red", "orange", "yellow", "green", "blue", "animation 1", "animation 2"};
const unsigned char setupCharacterCols[8] = {PC_WHITE, PC_RED, PC_ORANGE,
......@@ -475,7 +510,7 @@ int Menu::setup () {
while (true) {
ret = generic(setupOptions, 5, &option);
ret = generic(setupOptions, 6, &option);
if (ret == E_UNUSED) return E_NONE;
if (ret < 0) return ret;
......@@ -553,6 +588,12 @@ int Menu::setup () {
break;
case 5:
setupSound();
break;
}
}
......
......@@ -6,9 +6,9 @@
#include <fcntl.h>
#include <unistd.h>
int volume = 40;
int volume_direction;
#include "io/sound.h"
void WIZ_AdjustVolume( int direction )
{
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