|
From: <at...@us...> - 2007-11-06 20:33:01
|
Revision: 534
http://cadcdev.svn.sourceforge.net/cadcdev/?rev=534&view=rev
Author: atani
Date: 2007-11-06 12:32:59 -0800 (Tue, 06 Nov 2007)
Log Message:
-----------
nds sound fx support, sound fx sample
Modified Paths:
--------------
tiki/examples/Makefile
tiki/include/Tiki/sound.h
tiki/nds/src/audio/sound.cpp
tiki/nds/src/init_shutdown.cpp
Added Paths:
-----------
tiki/examples/sound/
tiki/examples/sound/Makefile
tiki/examples/sound/sfx/
tiki/examples/sound/sfx/Makefile
tiki/examples/sound/sfx/resources/
tiki/examples/sound/sfx/resources/click.wav
tiki/examples/sound/sfx/resources/pc-ascii.png
tiki/examples/sound/sfx/src/
tiki/examples/sound/sfx/src/SoundFX.cpp
tiki/examples/sound/sfx/src/main.cpp
Modified: tiki/examples/Makefile
===================================================================
--- tiki/examples/Makefile 2007-11-06 16:46:32 UTC (rev 533)
+++ tiki/examples/Makefile 2007-11-06 20:32:59 UTC (rev 534)
@@ -1,5 +1,5 @@
-SUBDIRS = events menu console net nehe
+SUBDIRS = events menu console net nehe sound
TIKI_DIR ?= $(CURDIR)/../
include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules
Added: tiki/examples/sound/Makefile
===================================================================
--- tiki/examples/sound/Makefile (rev 0)
+++ tiki/examples/sound/Makefile 2007-11-06 20:32:59 UTC (rev 534)
@@ -0,0 +1,8 @@
+
+SUBDIRS = sfx
+
+TIKI_DIR ?= $(CURDIR)/../../
+include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules
+
+all: subdirs
+clean: clean_subdirs
Property changes on: tiki/examples/sound/sfx
___________________________________________________________________
Name: svn:ignore
+ build
Debug
Release
*.nds
*.ds.gba
sound_fx
Added: tiki/examples/sound/sfx/Makefile
===================================================================
--- tiki/examples/sound/sfx/Makefile (rev 0)
+++ tiki/examples/sound/sfx/Makefile 2007-11-06 20:32:59 UTC (rev 534)
@@ -0,0 +1,26 @@
+
+CFLAGS=-I$(TIKI_DIR)$(TIKI_PLAT)/include -I$(TIKI_DIR)include
+OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp))
+
+ifeq ($(TIKI_PLAT),nds)
+NDS_CART_CODE ?= SOUN
+NDS_CART_ID ?= TK
+NDS_CART_NAME ?= SoundFX
+NDS_CART_VERSION ?= 1
+endif
+
+all: sound_fx
+sound_fx: $(OBJS)
+ $(build_romdisk)
+ $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o sound_fx$(PLATFORM_BINARY_EXT) $(ROMDISK_OBJ)
+ $(post_build)
+
+clean:
+ -rm -f $(OBJS) sound_fx$(PLATFORM_BINARY_EXT) $(ROMDISK_OBJ)
+ifeq ($(TIKI_PLAT),nds)
+ -rm -f sound_fx.nds sound_fx.ds.gba
+endif
+
+TIKI_DIR ?= $(CURDIR)/../../../
+DEPSDIR=$(CURDIR)
+include $(TIKI_DIR)$(TIKI_PLAT)/Makefile.rules
Property changes on: tiki/examples/sound/sfx/Makefile
___________________________________________________________________
Name: svn:executable
+ *
Added: tiki/examples/sound/sfx/resources/click.wav
===================================================================
(Binary files differ)
Property changes on: tiki/examples/sound/sfx/resources/click.wav
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: tiki/examples/sound/sfx/resources/pc-ascii.png
===================================================================
(Binary files differ)
Property changes on: tiki/examples/sound/sfx/resources/pc-ascii.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Property changes on: tiki/examples/sound/sfx/src
___________________________________________________________________
Name: svn:ignore
+ *.d
Added: tiki/examples/sound/sfx/src/SoundFX.cpp
===================================================================
--- tiki/examples/sound/sfx/src/SoundFX.cpp (rev 0)
+++ tiki/examples/sound/sfx/src/SoundFX.cpp 2007-11-06 20:32:59 UTC (rev 534)
@@ -0,0 +1,27 @@
+/*
+* SoundFX.cpp
+* Basic menu example
+*
+* Copyright (C)2007 Atani Software
+*
+*/
+
+#include <Tiki/tiki.h>
+#include <pch.h>
+
+#if TIKI_PLAT == TIKI_WIN32
+#include <windows.h>
+
+static char szAppName[] = "SoundFX";
+int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
+#else
+extern "C" int tiki_main( int argc, char *argv[] );
+int main( int argc, char *argv[] )
+#endif
+{
+#if TIKI_PLAT != TIKI_WIN32
+ return tiki_main( argc, argv );
+#else
+ return Tiki::DoMain( szAppName, hInst, hPrevInstance, lpCmdLine, nCmdShow );
+#endif
+}
Added: tiki/examples/sound/sfx/src/main.cpp
===================================================================
--- tiki/examples/sound/sfx/src/main.cpp (rev 0)
+++ tiki/examples/sound/sfx/src/main.cpp 2007-11-06 20:32:59 UTC (rev 534)
@@ -0,0 +1,116 @@
+/*
+* main.cpp
+* Sound FX example
+*
+* Copyright (C)2007 Atani Software
+*
+*/
+
+#include <Tiki/tiki.h>
+#include <Tiki/sound.h>
+#include <Tiki/hid.h>
+#include <Tiki/gl.h>
+#include <Tiki/drawables/console.h>
+
+using namespace Tiki;
+using namespace Tiki::Audio;
+using namespace Tiki::GL;
+using namespace Tiki::Hid;
+
+float volume = 0.50f;
+float panning = 0.0f;
+
+RefPtr<Sound> sound;
+RefPtr<Console> console;
+RefPtr<Texture> console_font;
+
+volatile bool g_quitting = false;
+void tkCallback( const Event & evt, void * data ) {
+ if ( evt.type == Event::EvtQuit ) {
+ g_quitting = true;
+ }
+ else if (evt.type == Event::EvtKeypress) {
+ switch(evt.key) {
+ case '\n':
+ case '\r':
+ sound->play(volume, panning);
+ break;
+ case Event::KeyLeft:
+ panning -= 0.05f;
+ if(panning < -1.0f) {
+ panning = -1.0f;
+ }
+
+ break;
+ case Event::KeyRight:
+ panning += 0.05f;
+ if(panning > 1.0f) {
+ panning = 1.0f;
+ }
+ break;
+ case Event::KeyDown:
+ volume -= 0.05f;
+ if(volume < 0.0f) {
+ volume = 0.0f;
+ }
+ break;
+ case Event::KeyUp:
+ volume += 0.05f;
+ if(volume > 1.0f) {
+ volume = 1.0f;
+ }
+
+ break;
+ case Event::KeyEsc:
+ g_quitting = true;
+ break;
+
+ }
+
+ }
+}
+
+extern "C" int tiki_main(int argc, char *argv[])
+{
+ Tiki::init(argc, argv);
+ Hid::callbackReg( tkCallback, NULL );
+
+#if TIKI_PLAT == TIKI_DC
+ console_font = new Texture( "/rd/pc-ascii.png", true );
+ sound = new Sound("/rd/click.wav");
+#else
+ console_font = new Texture( "pc-ascii.png", true );
+ sound = new Sound("click.wav");
+#endif
+ console = new Console( 80, 25, console_font );
+
+ Vector screenExtents = Frame::getScreenExtents();
+ console->setSize(screenExtents.x, screenExtents.y);
+ screenExtents *= 0.5f;
+ console->setTranslate(screenExtents);
+ console->setAutoWrap( true );
+ console->setAutoScroll( true );
+ console->color( BLACK, GREY );
+ console->clear();
+
+ while (!g_quitting)
+ {
+ console->clear();
+ console->printf("Press ESC to exit\n");
+ console->printf("Panning: %02.02f\n", panning);
+ console->printf("Volume: %02.02f\n", volume);
+
+ Frame::begin();
+ console->draw(Drawable::Opaque);
+ Frame::transEnable();
+ console->draw(Drawable::Trans);
+ Frame::finish();
+ }
+
+ delete sound;
+ delete console;
+ delete console_font;
+
+ Tiki::shutdown();
+ return 0;
+}
Modified: tiki/include/Tiki/sound.h
===================================================================
--- tiki/include/Tiki/sound.h 2007-11-06 16:46:32 UTC (rev 533)
+++ tiki/include/Tiki/sound.h 2007-11-06 20:32:59 UTC (rev 534)
@@ -13,11 +13,11 @@
#include "object.h"
#if TIKI_PLAT == TIKI_OSX
-# include <OpenAL/al.h>
+#include <OpenAL/al.h>
#elif TIKI_PLAT == TIKI_SDL
-# include <AL/al.h>
+#include <AL/al.h>
#elif TIKI_PLAT == TIKI_WIN32
-# include <al.h>
+#include <al.h>
#endif
namespace Tiki {
@@ -70,7 +70,10 @@
sfxhnd_t handle;
#endif
#if TIKI_PLAT == TIKI_NDS
- TransferSoundData m_sndData;
+ uint8 *m_buffer;
+ uint32 m_rate;
+ uint32 m_size;
+ uint8 m_format;
#endif
static float m_default_vol;
Modified: tiki/nds/src/audio/sound.cpp
===================================================================
--- tiki/nds/src/audio/sound.cpp 2007-11-06 16:46:32 UTC (rev 533)
+++ tiki/nds/src/audio/sound.cpp 2007-11-06 20:32:59 UTC (rev 534)
@@ -11,6 +11,8 @@
#include "Tiki/sound.h"
#include "Tiki/file.h"
+#include <nds.h>
+
#include <string.h>
using namespace Tiki::Audio;
@@ -25,6 +27,7 @@
bool Sound::initGlobal() {
setGenericSound( 11025, 127, 64, 1 );
+
return true;
}
@@ -43,9 +46,7 @@
assert( false );
}
-Sound::Sound() {
- memset( &m_sndData, 0, sizeof( TransferSoundData ) );
-}
+Sound::Sound() {}
Sound::~Sound() {}
@@ -61,7 +62,7 @@
if ( strncmp( magic, "WAVE", 4 ) ) {
Debug::printf( "Sound::loadFromFile: file is not RIFF WAVE\n" );
wavFile.close();
- m_sndData.data = NULL;
+ m_buffer = NULL;
return false;
}
@@ -80,26 +81,25 @@
Debug::printf( "WAVE file is %s, %dHZ, %d bits/sample, %d bytes total, format %d\n",
chn == 1 ? "mono" : "stereo", hz, bitsize, len, fmt );
if ( bitsize == 8 ) {
- m_sndData.format = 1;
+ m_format = 1;
} else if ( bitsize == 16 ) {
- m_sndData.format = 2;
+ m_format = 2;
} else {
Debug::printf( "Sound::loadFromFile: unsupported bitsize / channel combination\n" );
wavFile.close();
- m_sndData.data = NULL;
+ m_buffer = NULL;
return false;
}
- m_sndData.len = len;
- m_sndData.rate = hz;
-
- m_sndData.data = malloc( len );
+ m_size = len;
+ m_rate = hz;
+ m_buffer = new u8[ m_size ];
if ( bitsize == 8 ) {
- wavFile.read( m_sndData.data, len );
+ wavFile.read( m_buffer, m_size );
} else {
//byte swapping may be needed, depending on host endianness
- for ( int i = 0; i < size; i += 2 ) {
- wavFile.readle16( ( uint8 * ) m_sndData.data + i, 1 );
+ for ( int i = 0; i < m_size; i += 2 ) {
+ wavFile.readle16( ( uint8 * ) m_buffer + i, 1 );
}
}
@@ -113,29 +113,29 @@
}
int Sound::play() {
- m_sndData.vol = 128 * m_default_vol;
- playSound(&m_sndData);
+ play( 0, m_default_vol, 0.0f );
return 0;
}
int Sound::play( float vol ) {
- m_sndData.pan = 64;
- m_sndData.vol = 128 * vol;
- playSound(&m_sndData);
+ play( 0, vol, 0.0f );
return 0;
}
int Sound::play( float vol, float pan ) {
- m_sndData.pan = 64;
- m_sndData.vol = 128 * vol;
- playSound(&m_sndData);
+ play( 0, vol, pan );
return 0;
}
void Sound::play( int ch, float vol, float pan ) {
- m_sndData.pan = 64;
- m_sndData.vol = 128 * vol;
- playSound(&m_sndData);
- return 0;
+ TransferSoundData sound = {
+ m_buffer,
+ m_size,
+ m_rate,
+ static_cast<u8>(128 * vol),
+ pan == 0.0f ? 64 : (pan < 0.0f ? 128 + static_cast<u8>(64 * pan) : 64 + static_cast<u8>(64 * pan)),
+ m_format
+ };
+ playSound( &sound );
}
Modified: tiki/nds/src/init_shutdown.cpp
===================================================================
--- tiki/nds/src/init_shutdown.cpp 2007-11-06 16:46:32 UTC (rev 533)
+++ tiki/nds/src/init_shutdown.cpp 2007-11-06 20:32:59 UTC (rev 534)
@@ -11,8 +11,9 @@
#include "Tiki/sound.h"
#include "Tiki/stream.h"
#include "Tiki/hid.h"
+#include "Tiki/drawables/console.h"
-#include <nds.h>s
+#include <nds.h>
#include <fat.h>
#include <dswifi9.h>
#include <dssoundstream.h>
@@ -22,7 +23,7 @@
SendCommandToArm7( 0x87654321 );
}
-Tiki::GL::NDSSubScreenConsole *console = NULL;
+Tiki::GL::NDSSubScreenConsole *debug_console = NULL;
extern const u8 ascii_font_bin[];
extern const u32 ascii_font_bin_size;
@@ -42,7 +43,7 @@
SUB_BG1_CR = BG_64x32 | BG_COLOR_16 | BG_MAP_BASE( 2 ) | BG_TILE_BASE( 1 );
vramSetBankC( VRAM_C_SUB_BG );
memcpy( ( void * )BG_TILE_RAM_SUB( 1 ), ascii_font_bin, ascii_font_bin_size );
- console = new Tiki::GL::NDSSubScreenConsole( 64, 24 );
+ debug_console = new Tiki::GL::NDSSubScreenConsole( 64, 24 );
*/
}
@@ -140,8 +141,8 @@
Audio::Stream::shutdownGlobal();
Audio::Sound::shutdownGlobal();
}
- if(g_tiki_init_flags & TIKI_INIT_DEBUG_CONSOLE && console != NULL) {
- delete console;
+ if(g_tiki_init_flags & TIKI_INIT_DEBUG_CONSOLE && debug_console != NULL) {
+ delete debug_console;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|