|
From: <at...@us...> - 2007-11-06 16:46:37
|
Revision: 533
http://cadcdev.svn.sourceforge.net/cadcdev/?rev=533&view=rev
Author: atani
Date: 2007-11-06 08:46:32 -0800 (Tue, 06 Nov 2007)
Log Message:
-----------
SoundFX support on the DS.
Modified Paths:
--------------
tiki/include/Tiki/sound.h
tiki/nds/src/audio/sound.cpp
tiki/nds/src/init_shutdown.cpp
Modified: tiki/include/Tiki/sound.h
===================================================================
--- tiki/include/Tiki/sound.h 2007-11-06 15:54:58 UTC (rev 532)
+++ tiki/include/Tiki/sound.h 2007-11-06 16:46:32 UTC (rev 533)
@@ -14,14 +14,11 @@
#if TIKI_PLAT == TIKI_OSX
# include <OpenAL/al.h>
-#else
-#if TIKI_PLAT == TIKI_SDL
+#elif TIKI_PLAT == TIKI_SDL
# include <AL/al.h>
-#endif
-#if TIKI_PLAT == TIKI_WIN32
+#elif TIKI_PLAT == TIKI_WIN32
# include <al.h>
#endif
-#endif
namespace Tiki {
namespace Audio {
@@ -67,14 +64,13 @@
private:
bool m_stereo;
#if TIKI_PLAT != TIKI_DC && TIKI_PLAT != TIKI_NDS
-
ALuint m_buffer;
#endif
#if TIKI_PLAT == TIKI_DC
-
sfxhnd_t handle;
#endif
#if TIKI_PLAT == TIKI_NDS
+ TransferSoundData m_sndData;
#endif
static float m_default_vol;
Modified: tiki/nds/src/audio/sound.cpp
===================================================================
--- tiki/nds/src/audio/sound.cpp 2007-11-06 15:54:58 UTC (rev 532)
+++ tiki/nds/src/audio/sound.cpp 2007-11-06 16:46:32 UTC (rev 533)
@@ -24,6 +24,7 @@
float Sound::m_default_vol = 0.9f;
bool Sound::initGlobal() {
+ setGenericSound( 11025, 127, 64, 1 );
return true;
}
@@ -42,12 +43,68 @@
assert( false );
}
-Sound::Sound() {}
+Sound::Sound() {
+ memset( &m_sndData, 0, sizeof( TransferSoundData ) );
+}
Sound::~Sound() {}
bool Sound::loadFromFile( const string & fn ) {
- return false;
+ char magic[ 4 ];
+ uint32 len, hz;
+ uint16 chn, bitsize, fmt;
+
+ File wavFile( fn, "r" );
+ wavFile.seek( 8, SEEK_SET );
+ wavFile.read( magic, 4 );
+
+ if ( strncmp( magic, "WAVE", 4 ) ) {
+ Debug::printf( "Sound::loadFromFile: file is not RIFF WAVE\n" );
+ wavFile.close();
+ m_sndData.data = NULL;
+ return false;
+ }
+
+ /* Read WAV header info */
+ wavFile.seek( 0x14, SEEK_SET );
+ wavFile.readle16( &fmt, 1 );
+ wavFile.readle16( &chn, 1 );
+ wavFile.readle32( &hz, 1 );
+ wavFile.seek( 0x22, SEEK_SET );
+ wavFile.readle16( &bitsize, 1 );
+
+ /* Read WAV data */
+ wavFile.seek( 0x28, SEEK_SET );
+ wavFile.readle32( &len, 1 );
+
+ 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;
+ } else if ( bitsize == 16 ) {
+ m_sndData.format = 2;
+ } else {
+ Debug::printf( "Sound::loadFromFile: unsupported bitsize / channel combination\n" );
+ wavFile.close();
+ m_sndData.data = NULL;
+ return false;
+ }
+
+ m_sndData.len = len;
+ m_sndData.rate = hz;
+
+ m_sndData.data = malloc( len );
+ if ( bitsize == 8 ) {
+ wavFile.read( m_sndData.data, len );
+ } 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 );
+ }
+ }
+
+ wavFile.close();
+ return true;
}
// Set the default volume value
@@ -56,16 +113,29 @@
}
int Sound::play() {
- return -1;
+ m_sndData.vol = 128 * m_default_vol;
+ playSound(&m_sndData);
+ return 0;
}
int Sound::play( float vol ) {
- return -1;
+ m_sndData.pan = 64;
+ m_sndData.vol = 128 * vol;
+ playSound(&m_sndData);
+ return 0;
}
int Sound::play( float vol, float pan ) {
- return -1;
+ m_sndData.pan = 64;
+ m_sndData.vol = 128 * vol;
+ playSound(&m_sndData);
+ return 0;
}
-void Sound::play( int ch, float vol, float pan ) {}
+void Sound::play( int ch, float vol, float pan ) {
+ m_sndData.pan = 64;
+ m_sndData.vol = 128 * vol;
+ playSound(&m_sndData);
+ return 0;
+}
Modified: tiki/nds/src/init_shutdown.cpp
===================================================================
--- tiki/nds/src/init_shutdown.cpp 2007-11-06 15:54:58 UTC (rev 532)
+++ tiki/nds/src/init_shutdown.cpp 2007-11-06 16:46:32 UTC (rev 533)
@@ -99,6 +99,10 @@
Tiki::Debug::printf("Enabling SoundStream\n");
Audio::Stream::initGlobal();
}
+ if(g_tiki_init_flags & TIKI_INIT_AUDIO_SFX) {
+ Tiki::Debug::printf("Enabling SoundFX\n");
+ Audio::Sound::initGlobal();
+ }
}
if(g_tiki_init_flags & TIKI_INIT_HID_MASK ) {
Tiki::Debug::printf("Enabling HID\n");
@@ -134,6 +138,7 @@
}
if(g_tiki_init_flags & TIKI_INIT_HID_MASK ) {
Audio::Stream::shutdownGlobal();
+ Audio::Sound::shutdownGlobal();
}
if(g_tiki_init_flags & TIKI_INIT_DEBUG_CONSOLE && console != NULL) {
delete console;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|