#169503 - iainprice - Sat Jul 18, 2009 6:43 pm
Hi,
I want to stream audio, either wav or mp3 within a game. I know there are some out there but they are very complicated and not easy to integrate into a game, they all seem to be stand alone.
Any ideas?
#169564 - iainprice - Thu Jul 23, 2009 9:04 pm
Great bit of code.... have put it in game and it's working, I ma just converting it to work with efs
but... it messes up my sound effects, how can I play samples over the main music?
#169566 - SteveH - Fri Jul 24, 2009 12:39 am
Search this forum (the entire forum) for MS-ADPCM streamer or IMA-ADPCM streamer - there's some source code that will stream wav files from your card with little overhead - I'm looking at the MS-ADPCM at the moment, and it uses about 8 - 16 scanlines to stream the wav file.
#169573 - iainprice - Fri Jul 24, 2009 3:04 pm
locking doesn't seem to make any difference at the moment.....
#170458 - iainprice - Sun Sep 27, 2009 3:16 pm
I am still having no joy with streaming sound and sound effects....
I use the adpcm streamer and build in a raw but the sound effect just makes a click and nothing else.....
[code]/***********************************************************
* ima-adpcm demo by Discostew
* player and decoder template by mukunda
***********************************************************/
#include <nds.h>
#include <maxmod9.h>
#include <fat.h>
#include "directory.h"
#include "ima_adpcm.h"
#include "rifle_raw.h"
IMA_Adpcm_Player player;
bool player_loop = false;
char in_play[] = "|/-\\";
int in_play_delay = 4;
bool dir_filetype = true;
int Execute_Directory_File( char *filename )
{
return player.play( filename, player_loop, false );
}
/******************************************************
* main
*
* Program Entry Point
******************************************************/
int main(void) {
consoleDemoInit();
BG_PALETTE_SUB[0] = 13<<10;
if( !fatInitDefault() ) {
iprintf( "FAT is required.\n" );
while(1) swiWaitForVBlank();
}
mm_ds_system sys;
sys.mod_count = 0;
sys.samp_count = 0;
sys.mem_bank = 0;
sys.fifo_channel = FIFO_MAXMOD;
mmInit( &sys );
LLG_Directory directory( "wav", Execute_Directory_File );
SetYtrigger( 0 );
irqEnable( IRQ_VCOUNT );
int background_sine = 0;
int cur_in_play = 0;
int cur_in_play_delay = 0;
keysSetRepeat( 20, 3 );
swiWaitForVBlank();
while(1)
{
scanKeys();
int keysd = keysDown();
int keysr = keysDownRepeat();
if( keysd & KEY_A ) {
directory.execute();
}
if( keysd & KEY_B ) {
player.stop();
}
if( keysd & KEY_X ) {
if( player.ispaused() )
player.resume();
else
player.pause();
}
if( keysd & KEY_Y ) {
player_loop = !player_loop;
}
if( keysr & KEY_UP ) {
directory.select_prior();
}
if( keysr & KEY_LEFT ) {
//my bit to play sound effect
soundPlaySample(rifle_raw, SoundFormat_8Bit, rifle_raw_size, 11025, 127, 64, false, 0);
}
if( keysr & KEY_DOWN ) {
directory.select_next();
}
if( keysHeld() & KEY_L ) {
player.setvolume( player.getvolume() - 1 );
}
if( keysHeld() & KEY_R ) {
player.setvolume( player.getvolume() + 1 );
}
if( keysd & KEY_START ) {
directory.parent_dir();
}
if( keysd & KEY_SELECT ) {
dir_filetype = !dir_filetype;
if( dir_filetype )
directory.set_filter( "wav" );
else
directory.set_filter( "" );
}
iprintf( "\x1b[23;0H%d ", player.getvolume() );
iprintf( "\x1b[23;6H%s", ( dir_filetype ? "WAV files" : "All files" ));
iprintf( "\x1b[23;21H%s", ( player_loop ? " Loop " : "One shot" ));
if( player.isactive() ) {
iprintf( "\x1b[11;31H%c", ( player.ispaused() ? '-' : in_play[ cur_in_play ]));
cur_in_play_delay++;
if( cur_in_play_delay >= in_play_delay )
{
cur_in_play_delay = 0;
cur_in_play++;
if( cur_in_play >= 4 )
cur_in_play = 0;
}
}
else
{
iprintf( "\x1b[11;31H " );
cur_in_play_delay = 0;
}
// wait until display line 0
swiIntrWait( 0, IRQ_VCOUNT );
// update stream
player.update();
// set backdrop to blueness (some lines were drawn with red to show cpu usage)
BG_PALETTE_SUB[0] = (12+(sinLerp(background_sine & 65535)>>9))<<10;
background_sine += 200;
swiWaitForVBlank();
// set backdrop to RED
BG_PALETTE_SUB[0] = 0x1f;
}
return 0;
}[/code]