Permalink
Browse files

Use Maxmod for sound engine (WIP)

Commit by Le_Rodeur
  • Loading branch information...
1 parent 7884b3c commit ff66547269bda0d9014a7d8d54f418a54178aabd @corenting committed Mar 5, 2012
View
17 Makefile
@@ -70,6 +70,7 @@ SOURCES := source
INCLUDES := include
DATA := data
NITRODATA := nitrofiles
+MUSIC := maxmod_data
#---------------------------------------------------------------------------------
# options for code generation
@@ -90,7 +91,7 @@ LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
-LIBS := -lnflib -lfilesystem -lfat -lnds9 -lmm9
+LIBS := -lmm9 -lnflib -lfilesystem -lfat -lnds9
#---------------------------------------------------------------------------------
@@ -113,13 +114,16 @@ export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
-
+
export NITRO_FILES := $(CURDIR)/$(NITRODATA)
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)/*.*)))
+BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin
+
+export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))
+
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
@@ -174,6 +178,13 @@ else
#---------------------------------------------------------------------------------
$(OUTPUT).nds : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)
+# rule to build soundbank from music files
+#---------------------------------------------------------------------------------
+soundbank.bin : $(AUDIOFILES)
+#---------------------------------------------------------------------------------
+ @mmutil $^ -d -osoundbank.bin -hsoundbank.h
+
+#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
%.bin.o : %.bin
View
BIN nitrofiles/sfx/after1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/after2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/better1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/better2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/doit1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/doit2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/ever1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/ever2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/faster1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/faster2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/harder1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/harder2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/hour1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/hour2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/makeit1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/makeit2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/makesus1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/makesus2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/morethan1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/morethan2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/never1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/never2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/our1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/our2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/over1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/over2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/rulesthenation.raw
Binary file not shown.
View
BIN nitrofiles/sfx/stronger1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/stronger2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/technologic.raw
Binary file not shown.
View
BIN nitrofiles/sfx/workis1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/workis2.raw
Binary file not shown.
View
BIN nitrofiles/sfx/workit1.raw
Binary file not shown.
View
BIN nitrofiles/sfx/workit2.raw
Binary file not shown.
View
390 source/main.c
@@ -9,202 +9,206 @@ Version 1.0
//Includes
#include <stdio.h>
#include <nds.h> //libnds
+#include <filesystem.h>
#include <nf_lib.h> //nflib
-#include "sound.h"
+
+//Maxmod
+#include <maxmod9.h> //lib
+#include "sound.h" //fonctions sons
+#include "soundbank.h" //sons
+#include "soundbank_bin.h" //sons
int main(int argc, char **argv) {
- // Chargement de NitroFS / NitroFS loading
- NF_Set2D(0, 0);
- NF_Set2D(1, 0);
- consoleDemoInit();
- iprintf("\n NitroFS init. Please wait.\n\n");
- iprintf(" Chargement de NitroFS. Veuillez patienter.\n\n");
- swiWaitForVBlank();
- iprintf("OK !\n\n");
- NF_SetRootFolder("NITROFS"); // Dossier DS
-
- // Moteur 2D / 2D Engine
- NF_Set2D(0, 0);
- NF_Set2D(1, 0);
-
- //Son
- soundEnable();
-
- // Les fonds / Backgrounds
- NF_InitTiledBgBuffers(); // buffer
- NF_InitTiledBgSys(0); // haut / top
- NF_InitTiledBgSys(1); // bas / bottom
-
- //Texte / Text
- NF_InitTextSys(0); //haut / top
- NF_InitTextSys(1); //bas / bottom
-
- // Buffers du son / Sound buffer
- NF_InitRawSoundBuffers();
-
- // Chargement de la police de caractère / Loading font
- NF_LoadTextFont("fnt/default", "haut", 256, 256, 0);
- NF_LoadTextFont("fnt/default", "bas", 256, 256, 0);
-
- // Calque police et couleur/ Font layer and color
- NF_CreateTextLayer(0, 0, 0, "haut");
- NF_CreateTextLayer(1, 0, 0, "bas");
- NF_BgSetPalColor(0, 0, 1, 0, 31, 0);
- NF_BgSetPalColor(1, 0, 1, 0, 31, 0);
-
- //Vars
- touchPosition touch;
- u16 newpress;
- s16 x;
- s16 y;
- u8 beat = 0; //high 0 / low 1
-
- NF_ResetRawSoundBuffers();
- NF_ClearTextLayer(1, 0);
- NF_ClearTextLayer(0, 0);
- NF_WriteText(0, 0, 0, 1, "___ ____ ___ ____ ____ ___ ");
- NF_WriteText(0, 0, 0, 2, "| \\ [__ | \\ |__| |___ | ");
- NF_WriteText(0, 0, 0, 3, "|__/ ___] |__/ | | | | ");
- NF_WriteText(0, 0, 25, 5, "1.0");
- NF_WriteText(0, 0, 0, 22, "Corenting (www.corenting.fr)");
- NF_UpdateTextLayers(); // Actualisation du texte
- NF_LoadTiledBg("bg/1", "1", 256, 256);
- NF_CreateTiledBg(1, 3, "1");
-
- initstream("background.raw");
- //Harder Better Faster Stronger
- while(1) {
-
- // Scan touches et tactile
- scanKeys();
- touchRead(&touch);
- newpress = keysDown();
- x = touch.px;
- y = touch.py ;
-
- if (newpress&&(x > 51)&&(y > 182)&&(x < 92)&&(y < 192)) {
- if (beat == 1) {
- beat = 0;
- }
- else {
- beat = 1;
- }
- }
-
- if(beat == 0) {
- NF_WriteText(1, 0, 7, 23, "High");
- NF_UpdateTextLayers(); // Actualisation du texte
- // Chargement des samples
- NF_ResetRawSoundBuffers();
- NF_LoadRawSound("sfx/workit1", 0, 16384, 0);
- NF_LoadRawSound("sfx/makeit1", 1, 16384, 0);
- NF_LoadRawSound("sfx/doit1", 2, 16384, 0);
- NF_LoadRawSound("sfx/makesus1", 3, 16384, 0);
- NF_LoadRawSound("sfx/harder1", 4, 16384, 0);
- NF_LoadRawSound("sfx/better1", 5, 16384, 0);
- NF_LoadRawSound("sfx/faster1", 6, 16384, 0);
- NF_LoadRawSound("sfx/stronger1", 7, 16384, 0);
- NF_LoadRawSound("sfx/morethan1", 8, 16384, 0);
- NF_LoadRawSound("sfx/hour1", 9, 16384, 0);
- NF_LoadRawSound("sfx/our1", 10, 16384, 0);
- NF_LoadRawSound("sfx/never1", 11, 16384, 0);
- NF_LoadRawSound("sfx/ever1", 12, 16384, 0);
- NF_LoadRawSound("sfx/after1", 13, 16384, 0);
- NF_LoadRawSound("sfx/workis1", 14, 16384, 0);
- NF_LoadRawSound("sfx/over1", 15, 16384, 0);
- }
- if(beat == 1) {
- NF_WriteText(1, 0, 7, 23, "Low ");
- NF_UpdateTextLayers(); // Actualisation du texte
- NF_ResetRawSoundBuffers();
- NF_LoadRawSound("sfx/workit2", 0, 16384, 0);
- NF_LoadRawSound("sfx/makeit2", 1, 16384, 0);
- NF_LoadRawSound("sfx/doit2", 2, 16384, 0);
- NF_LoadRawSound("sfx/makesus2", 3, 16384, 0);
- NF_LoadRawSound("sfx/harder2", 4, 16384, 0);
- NF_LoadRawSound("sfx/better2", 5, 16384, 0);
- NF_LoadRawSound("sfx/faster2", 6, 16384, 0);
- NF_LoadRawSound("sfx/stronger2", 7, 16384, 0);
- NF_LoadRawSound("sfx/morethan2", 8, 16384, 0);
- NF_LoadRawSound("sfx/hour2", 9, 16384, 0);
- NF_LoadRawSound("sfx/our2", 10, 16384, 0);
- NF_LoadRawSound("sfx/never2", 11, 16384, 0);
- NF_LoadRawSound("sfx/ever2", 12, 16384, 0);
- NF_LoadRawSound("sfx/after2", 13, 16384, 0);
- NF_LoadRawSound("sfx/workis2", 14, 16384, 0);
- NF_LoadRawSound("sfx/over2", 15, 16384, 0);
- }
-
- if (newpress&&(x > 0)&&(y > 0)&&(x < 58)&&(y < 35)) {
- NF_PlayRawSound(0, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 66)&&(y >= 0)&&(x < 123)&&(y < 35)) {
- NF_PlayRawSound(1, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 132)&&(y >= 0)&&(x < 187)&&(y < 35)) {
- NF_PlayRawSound(2, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 197)&&(y >= 0)&&(x < 255)&&(y < 35)) {
- NF_PlayRawSound(3, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 0)&&(y >= 45)&&(x < 58)&&(y < 80)) {
- NF_PlayRawSound(4, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 67)&&(y >= 45)&&(x < 122)&&(y < 80)) {
- NF_PlayRawSound(5, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 133)&&(y >= 45)&&(x < 189)&&(y < 80)) {
- NF_PlayRawSound(6, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 197)&&(y >= 45)&&(x < 252)&&(y < 80)) {
- NF_PlayRawSound(7, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 0)&&(y >= 89)&&(x < 58)&&(y < 125)) {
- NF_PlayRawSound(8, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 67)&&(y >= 89)&&(x < 122)&&(y < 125)) {
- NF_PlayRawSound(9, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 132)&&(y >= 89)&&(x < 190)&&(y < 125)) {
- NF_PlayRawSound(10, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 198)&&(y >= 89)&&(x < 253)&&(y < 125)) {
- NF_PlayRawSound(11, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 0)&&(y >= 132)&&(x < 57)&&(y < 168)) {
- NF_PlayRawSound(12, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 66)&&(y >= 132)&&(x < 123)&&(y < 168)) {
- NF_PlayRawSound(13, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 132)&&(y >= 132)&&(x < 187)&&(y < 168)) {
- NF_PlayRawSound(14, 127, 127, false, 0);
- }
-
- if (newpress&&(x >= 197)&&(y >= 132)&&(x < 253)&&(y < 168)) {
- NF_PlayRawSound(15, 127, 127, false, 0);
- }
-
- streamUpdate();
- swiWaitForVBlank();
- }
-
-
- return 0;
+// Chargement de NitroFS / NitroFS loading
+NF_Set2D(0, 0);
+NF_Set2D(1, 0);
+consoleDemoInit();
+iprintf("\n NitroFS init. Please wait.\n\n");
+iprintf(" Chargement de NitroFS. Veuillez patienter.\n\n");
+NF_SetRootFolder("NITROFS"); // Défini le dossier root comme celui de NitroFS
+swiWaitForVBlank();
+iprintf("OK !\n\n");
+
+// Moteur 2D / 2D Engine
+NF_Set2D(0, 0);
+NF_Set2D(1, 0);
+
+
+// Les fonds / Backgrounds
+NF_InitTiledBgBuffers(); // buffer
+NF_InitTiledBgSys(0); // haut / top
+NF_InitTiledBgSys(1); // bas / bottom
+
+//Texte / Text
+NF_InitTextSys(0); //haut / top
+NF_InitTextSys(1); //bas / bottom
+
+// Chargement de la police de caractère / Loading font
+NF_LoadTextFont("fnt/default", "haut", 256, 256, 0);
+NF_LoadTextFont("fnt/default", "bas", 256, 256, 0);
+
+// Calque police et couleur/ Font layer and color
+NF_CreateTextLayer(0, 0, 0, "haut");
+NF_CreateTextLayer(1, 0, 0, "bas");
+NF_BgSetPalColor(0, 0, 1, 0, 31, 0);
+NF_BgSetPalColor(1, 0, 1, 0, 31, 0);
+
+//Vars
+touchPosition touch;
+u16 newpress;
+s16 x;
+s16 y;
+u8 beat = 0; //high 0 / low 1
+
+initSounds();
+while(!initStream("background.raw",16384)){NF_WriteText(0, 0, 0, 7, "Error initializing stream");
+}
+
+NF_ClearTextLayer(1, 0);
+NF_ClearTextLayer(0, 0);
+NF_WriteText(0, 0, 0, 1, "___ ____ ___ ____ ____ ___ ");
+NF_WriteText(0, 0, 0, 2, "| \\ [__ | \\ |__| |___ | ");
+NF_WriteText(0, 0, 0, 3, "|__/ ___] |__/ | | | | ");
+NF_WriteText(0, 0, 25, 5, "1.0");
+NF_WriteText(0, 0, 0, 22, "Corenting (www.corenting.fr)");
+NF_UpdateTextLayers(); // Actualisation du texte
+NF_LoadTiledBg("bg/1", "1", 256, 256);
+NF_CreateTiledBg(1, 3, "1");
+
+//Harder Better Faster Stronger
+while(1) {
+
+// Scan touches et tactile
+scanKeys();
+touchRead(&touch);
+newpress = keysDown();
+x = touch.px;
+y = touch.py ;
+
+if (newpress&&(x > 51)&&(y > 182)&&(x < 92)&&(y < 192)) {
+if (beat == 1) {
+beat = 0;
+}
+else {
+beat = 1;
+}
+}
+/*
+if(beat == 0) {
+NF_WriteText(1, 0, 7, 23, "High");
+NF_UpdateTextLayers(); // Actualisation du texte
+// Chargement des samples
+NF_ResetRawSoundBuffers();
+NF_LoadRawSound("sfx/workit1", 0, 16384, 0);
+NF_LoadRawSound("sfx/makeit1", 1, 16384, 0);
+NF_LoadRawSound("sfx/doit1", 2, 16384, 0);
+NF_LoadRawSound("sfx/makesus1", 3, 16384, 0);
+NF_LoadRawSound("sfx/harder1", 4, 16384, 0);
+NF_LoadRawSound("sfx/better1", 5, 16384, 0);
+NF_LoadRawSound("sfx/faster1", 6, 16384, 0);
+NF_LoadRawSound("sfx/stronger1", 7, 16384, 0);
+NF_LoadRawSound("sfx/morethan1", 8, 16384, 0);
+NF_LoadRawSound("sfx/hour1", 9, 16384, 0);
+NF_LoadRawSound("sfx/our1", 10, 16384, 0);
+NF_LoadRawSound("sfx/never1", 11, 16384, 0);
+NF_LoadRawSound("sfx/ever1", 12, 16384, 0);
+NF_LoadRawSound("sfx/after1", 13, 16384, 0);
+NF_LoadRawSound("sfx/workis1", 14, 16384, 0);
+NF_LoadRawSound("sfx/over1", 15, 16384, 0);
+}
+if(beat == 1) {
+NF_WriteText(1, 0, 7, 23, "Low ");
+NF_UpdateTextLayers(); // Actualisation du texte
+NF_ResetRawSoundBuffers();
+NF_LoadRawSound("sfx/workit2", 0, 16384, 0);
+NF_LoadRawSound("sfx/makeit2", 1, 16384, 0);
+NF_LoadRawSound("sfx/doit2", 2, 16384, 0);
+NF_LoadRawSound("sfx/makesus2", 3, 16384, 0);
+NF_LoadRawSound("sfx/harder2", 4, 16384, 0);
+NF_LoadRawSound("sfx/better2", 5, 16384, 0);
+NF_LoadRawSound("sfx/faster2", 6, 16384, 0);
+NF_LoadRawSound("sfx/stronger2", 7, 16384, 0);
+NF_LoadRawSound("sfx/morethan2", 8, 16384, 0);
+NF_LoadRawSound("sfx/hour2", 9, 16384, 0);
+NF_LoadRawSound("sfx/our2", 10, 16384, 0);
+NF_LoadRawSound("sfx/never2", 11, 16384, 0);
+NF_LoadRawSound("sfx/ever2", 12, 16384, 0);
+NF_LoadRawSound("sfx/after2", 13, 16384, 0);
+NF_LoadRawSound("sfx/workis2", 14, 16384, 0);
+NF_LoadRawSound("sfx/over2", 15, 16384, 0);
+}
+*/
+
+if (newpress&&(x > 0)&&(y > 0)&&(x < 58)&&(y < 35)) {
+playSound(SFX_AMBULANCE);
+}
+/*
+if (newpress&&(x >= 66)&&(y >= 0)&&(x < 123)&&(y < 35)) {
+NF_PlayRawSound(1, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 132)&&(y >= 0)&&(x < 187)&&(y < 35)) {
+NF_PlayRawSound(2, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 197)&&(y >= 0)&&(x < 255)&&(y < 35)) {
+NF_PlayRawSound(3, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 0)&&(y >= 45)&&(x < 58)&&(y < 80)) {
+NF_PlayRawSound(4, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 67)&&(y >= 45)&&(x < 122)&&(y < 80)) {
+NF_PlayRawSound(5, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 133)&&(y >= 45)&&(x < 189)&&(y < 80)) {
+NF_PlayRawSound(6, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 197)&&(y >= 45)&&(x < 252)&&(y < 80)) {
+NF_PlayRawSound(7, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 0)&&(y >= 89)&&(x < 58)&&(y < 125)) {
+NF_PlayRawSound(8, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 67)&&(y >= 89)&&(x < 122)&&(y < 125)) {
+NF_PlayRawSound(9, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 132)&&(y >= 89)&&(x < 190)&&(y < 125)) {
+NF_PlayRawSound(10, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 198)&&(y >= 89)&&(x < 253)&&(y < 125)) {
+NF_PlayRawSound(11, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 0)&&(y >= 132)&&(x < 57)&&(y < 168)) {
+NF_PlayRawSound(12, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 66)&&(y >= 132)&&(x < 123)&&(y < 168)) {
+NF_PlayRawSound(13, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 132)&&(y >= 132)&&(x < 187)&&(y < 168)) {
+NF_PlayRawSound(14, 127, 127, false, 0);
+}
+
+if (newpress&&(x >= 197)&&(y >= 132)&&(x < 253)&&(y < 168)) {
+NF_PlayRawSound(15, 127, 127, false, 0);
+}
+*/
+mmStreamUpdate();
+swiWaitForVBlank();
+}
+
+
+return 0;
}
View
136 source/sound.c
@@ -1,78 +1,96 @@
#include <nds.h>
#include <filesystem.h>
#include "sound.h"
+#include "soundbank.h"
+#include "soundbank_bin.h"
FILE* streamfile=0;
long streamFileSize=0;
long streamLoaded=0;
-bool initStream(char* rawfile)
+void initSounds()
{
-mystream.buffer_length = 1024;
-mystream.callback = stream;
-mystream.timer = MM_TIMER0;
-mystream.manual = true;
-streamfile = fopen(rawfile,"rb");
-streamFileSize=0;
-streamLoaded=0;
-if (streamfile)
-{
-fseek(streamfile, 0, SEEK_END);
-streamFileSize = ftell(streamfile);
-fseek(streamfile, 0, SEEK_SET);
-mystream.sampling_rate = 22050;
-mystream.format = MM_STREAM_16BIT_MONO;
-mmStreamOpen(&mystream);
-mmStreamUpdate();
-return 1;
+ int i;
+ bool soundsToLoad[MSL_NSAMPS];
+ for (i=0; i<MSL_NSAMPS; i++)soundsToLoad[i]=1;
+ mmInitDefaultMem((mm_addr)soundbank_bin);
+ //use soundbank from filesystem, you have to create it with mmutils (or change the makefile)
+ for (i=0; i<2; i++)
+ {
+ if(soundsToLoad[i])mmLoadEffect(i); //loads all sfx
+ }
}
-return 0;
+
+bool initStream(char* rawfile,int rate)
+{
+ mystream.buffer_length = 1024;
+ mystream.callback = stream;
+ mystream.timer = MM_TIMER0;
+ mystream.manual = true;
+ streamfile = fopen(rawfile,"rb");
+ /*problem douverture du fichier...*/
+ streamFileSize=0;
+ streamLoaded=0;
+ if (streamfile)
+ {
+ fseek(streamfile, 0, SEEK_END);
+ streamFileSize = ftell(streamfile);
+ fseek(streamfile, 0, SEEK_SET);
+ mystream.sampling_rate = rate;
+ mystream.format = MM_STREAM_16BIT_MONO;
+ mmStreamOpen(&mystream);
+ mmStreamUpdate();
+ return 1;
+ }
+ return 0;
}
void closeStream()
{
-if(streamfile)
-{
-mmStreamClose();
-fclose(streamfile);
-}
+ if(streamfile)
+ {
+ mmStreamClose();
+ fclose(streamfile);
+ }
}
mm_word stream(mm_word length, mm_addr dest, mm_stream_formats format)
{
-if(streamfile)
-{
-size_t samplesize=0;
-switch(format)
-{
-case MM_STREAM_8BIT_MONO:
-samplesize = 1;
-break;
-case MM_STREAM_8BIT_STEREO:
-samplesize = 2;
-break;
-case MM_STREAM_16BIT_MONO:
-samplesize = 2;
-break;
-case MM_STREAM_16BIT_STEREO:
-samplesize = 4;
-break;
+ if(streamfile)
+ {
+ size_t samplesize=0;
+ switch(format)
+ {
+ case MM_STREAM_8BIT_MONO:
+ samplesize = 1;
+ break;
+ case MM_STREAM_8BIT_STEREO:
+ samplesize = 2;
+ break;
+ case MM_STREAM_16BIT_MONO:
+ samplesize = 2;
+ break;
+ case MM_STREAM_16BIT_STEREO:
+ samplesize = 4;
+ break;
+ }
+ int res=0;
+ //test is we will not try to copy somthing out of the file... Seems that nitrofs allows reading farther than the length of the file
+ if(streamFileSize<(streamLoaded+length*samplesize))length%=streamFileSize-streamLoaded;
+ else res = fread(dest,samplesize,length,streamfile);
+ if(res)
+ {
+ length = res;
+ }
+ else
+ {
+ mmStreamClose();
+ fclose(streamfile);
+ length = 0;
+ }
+ streamLoaded+=length*samplesize;
+ }
+ return length;
}
-int res=0;
-//test is we will not try to copy somthing out of the file... Seems that nitrofs allows reading farther than the length of the file
-if(streamFileSize<(streamLoaded+length*samplesize))length%=streamFileSize-streamLoaded;
-else res = fread(dest,samplesize,length,streamfile);
-if(res)
-{
-length = res;
-}
-else
-{
-mmStreamClose();
-fclose(streamfile);
-length = 0;
-}
-streamLoaded+=length*samplesize;
-}
-return length;
-}
+
+
View
23 source/sound.h
@@ -1,24 +1,27 @@
#ifndef _SOUND_H
#define _SOUND_H
#include <maxmod9.h>
+#include <stdio.h>
-#define playSound(x) mmEffect(x)
-#define stopSound(x) mmEffectCancel(x)
-#define loadSound(x) mmLoadEffect(x)
-#define unloadSound(x) mmUnloadEffect(x)
-#define streamUpdate() mmStreamUpdate()
+#define playSound(x) mmEffect(x)
+#define stopSound(x) mmEffectCancel(x)
+#define loadSound(x) mmLoadEffect(x)
+#define unloadSound(x) mmUnloadEffect(x)
+
+#define streamUpdate() mmStreamUpdate()
struct Song{
-const mm_word rate;
-const mm_stream_formats format;
-const char* filename;
+ const mm_word rate;
+ const mm_stream_formats format;
+ const char* filename;
};
mm_stream mystream;
mm_word stream(mm_word length, mm_addr dest, mm_stream_formats format);
-bool initStream(char* rawfile);
+void initSounds();
+bool initStream(char* rawfile,int rate);
void closeStream();
-#endif // _SOUND_H
+#endif // _SOUND_H

0 comments on commit ff66547

Please sign in to comment.