Loading maxmod sound with nitrofs

Post Reply
dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Loading maxmod sound with nitrofs

Post by dheart88 » Sun Dec 13, 2009 3:07 pm

I got a problem when using nitrofs as the filesystem to load s3m file (using maxmod).. here's my code:

Code: Select all

#include <nds.h>
#include <filesystem.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>

#include <maxmod9.h> 


//---------------------------------------------------------------------------------
void dirlist(char* path) {
//---------------------------------------------------------------------------------

	DIR* pdir = opendir(path);
	char *dnbuf;

	if (pdir != NULL) {

		while(true) {
			struct dirent* pent = readdir(pdir);
			if(pent == NULL) break;
			
			if(strcmp(".", pent->d_name) != 0 && strcmp("..", pent->d_name) != 0) {
				dnbuf = malloc(strlen(pent->d_name)+strlen(path)+2);
				sprintf(dnbuf, "%s/%s", (strcmp("/",path) == 0)?"":path, pent->d_name);
				
				struct stat *statbuf = malloc(sizeof(statbuf));
				stat(dnbuf, statbuf);

				if(S_ISDIR(statbuf->st_mode)) {
					printf("%s <DIR>\n", dnbuf);
					dirlist(dnbuf);
				} else {
					printf("%s (%d)\n", dnbuf, (int)statbuf->st_size);
				}
				free(dnbuf);
				free(statbuf);
			}
		}
		
		closedir(pdir);
	} else {
		printf("opendir() failure.\n");
	}
}


//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
	
	// Initialise the console, required for printf
	consoleDemoInit();
	
	if (nitroFSInit()) {

		dirlist("/");
		
		//mmInitDefaultMem( (mm_addr)soundbank_bin )
		FILE *x = fopen("nitro:/soundbank_bin", "rb");
		
		
		mmInitDefault("nitro:/soundbank_bin");
		
		mmLoad( 0);
		
		mmSelectMode( MM_MODE_A);
		
		mmSetModuleVolume(1024);
			
		mmStart( 0, MM_PLAY_LOOP );
		
		
		int str;
		FILE *f = fopen("nitro:/dir1/test.txt", "rb");
		if (f != NULL)
		{
			fscanf(f, "%d", &str);
			printf("%d", str);
		}
		else
			printf("error!");

	} else {
		iprintf("nitroFSInit failure: terminating\n");
	}

	while(1) {
		swiWaitForVBlank();
	}

	return 0;
}
Well, it's modified from the example file.. and I changed the makefile into:

Code: Select all

#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif

include $(DEVKITARM)/ds_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# MAXMOD_SOUNDBANK contains a directory of music and sound effect files
#---------------------------------------------------------------------------------
TARGET		:=	$(shell basename $(CURDIR))
BUILD		:=	build
SOURCES		:=	source
DATA		:=
INCLUDES	:=	include
NITRODATA	:=	nitrofiles


#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH	:=	-mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s

CFLAGS	:=	-g -Wall -O2\
 		-fomit-frame-pointer\
		-ffast-math \
		$(ARCH)
		
#CFLAGS+=$(INCLUDE) -DARM9 -DNDSFILENAME=\"$(TARGET).nds\"


CFLAGS	+=	$(INCLUDE) -DARM9
CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS	:=	-g $(ARCH)
LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS	:= 	-lfilesystem -lfat -lnds9 -lmm9
 
 
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS	:=	$(LIBNDS)
 
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT	:=	$(CURDIR)/$(TARGET)

export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
					$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR	:=	$(CURDIR)/$(BUILD)


ifneq ($(strip $(NITRODATA)),)
	export NITRO_FILES	:=	$(CURDIR)/$(NITRODATA)
endif

CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
#BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin

#$(NITRODATA)/soundbank.bin

# build audio file list, include full path
#export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(NITRODATA)/*.*)),$(CURDIR)/$(NITRODATA)/$(dir))
 
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
	export LD	:=	$(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
	export LD	:=	$(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
			$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
 
export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
			-I$(CURDIR)/$(BUILD)
 
export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
 
.PHONY: $(BUILD) clean
 
#---------------------------------------------------------------------------------
$(BUILD):
	@[ -d $@ ] || mkdir -p $@
	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
 
#---------------------------------------------------------------------------------
clean:
	@echo clean ...
	@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9

#---------------------------------------------------------------------------------
else
 
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds	: 	$(OUTPUT).arm9
$(OUTPUT).arm9	:	$(OUTPUT).elf
$(OUTPUT).elf	:	$(OFILES)
 
soundbank.bin:	$(NITRODATA)\
#-------------------------------------------------------------
	@mmutil $^ -osoundbank.bin -hsoundbank.h -d


#---------------------------------------------------------------------------------
%.bin.o	:	%.bin
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)
 
-include $(DEPSDIR)/*.d
 
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
Pls help me ASAP .. or maybe give the the url for the better example file

User avatar
Izhido
Posts: 107
Joined: Fri Oct 19, 2007 10:57 pm
Location: Costa Rica
Contact:

Re: Loading maxmod sound with nitrofs

Post by Izhido » Sun Dec 13, 2009 3:21 pm

It would help us a lot if you actually state what is the problem you're having :).

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: Loading maxmod sound with nitrofs

Post by dheart88 » Sun Dec 13, 2009 3:29 pm

i can't load the song. that's the problem..

btw, I hope the maxmod developer can change this function
void mmInitDefault() -> int mmInitDefault().. so the programmer can understand if it's succeed or fail.. sorry for my bad english

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests