im fucking done... i couldnt get music working
This commit is contained in:
parent
589a0c94a4
commit
60a698ee50
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@
|
|||||||
/build*
|
/build*
|
||||||
|
|
||||||
/resource/image.bin
|
/resource/image.bin
|
||||||
|
/resource/music.raw
|
||||||
/resource/palette.bin
|
/resource/palette.bin
|
||||||
|
|
||||||
/.cache
|
/.cache
|
||||||
|
@ -26,7 +26,8 @@ set(PROJECT_INCLUDE
|
|||||||
|
|
||||||
set(PROJECT_VENDOR
|
set(PROJECT_VENDOR
|
||||||
"filesystem"
|
"filesystem"
|
||||||
"fat")
|
"fat"
|
||||||
|
"mm9")
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${VENDOR_SOURCES})
|
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${VENDOR_SOURCES})
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE})
|
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE})
|
||||||
|
@ -18,4 +18,4 @@ file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS
|
|||||||
|
|
||||||
add_executable(arm7 ${PROJECT_SOURCES})
|
add_executable(arm7 ${PROJECT_SOURCES})
|
||||||
target_include_directories(arm7 PRIVATE ${PROJECT_INCLUDE})
|
target_include_directories(arm7 PRIVATE ${PROJECT_INCLUDE})
|
||||||
target_link_libraries(arm7 PUBLIC dswifi7 mm7)
|
target_link_libraries(arm7 PUBLIC dswifi7 mm7 filesystem fat)
|
||||||
|
@ -30,6 +30,13 @@
|
|||||||
#include <nds.h>
|
#include <nds.h>
|
||||||
#include <dswifi7.h>
|
#include <dswifi7.h>
|
||||||
#include <maxmod7.h>
|
#include <maxmod7.h>
|
||||||
|
#include <filesystem.h>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <nds/debug.h>
|
||||||
|
|
||||||
|
static FILE *in_music = NULL;
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
void VblankHandler(void) {
|
void VblankHandler(void) {
|
||||||
@ -52,6 +59,8 @@ void powerButtonCB() {
|
|||||||
exitflag = true;
|
exitflag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
int main() {
|
int main() {
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
|
128
src/main.cpp
128
src/main.cpp
@ -2,20 +2,24 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <mm_types.h>
|
||||||
#include <nds.h>
|
#include <nds.h>
|
||||||
#include <filesystem.h>
|
#include <filesystem.h>
|
||||||
|
#include <nds/arm9/cache.h>
|
||||||
#include <nds/arm9/decompress.h>
|
#include <nds/arm9/decompress.h>
|
||||||
#include <nds/bios.h>
|
#include <nds/bios.h>
|
||||||
#include <nds/dma.h>
|
#include <nds/dma.h>
|
||||||
#include <nds/system.h>
|
#include <nds/system.h>
|
||||||
#include <nds/timers.h>
|
#include <nds/timers.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <maxmod9.h>
|
||||||
|
|
||||||
#define TIMER_SPEED (BUS_CLOCK/1024)
|
#define TIMER_SPEED (BUS_CLOCK/1024)
|
||||||
|
|
||||||
void wait_forever(const char* msg);
|
void wait_forever(const char* msg);
|
||||||
size_t LoadFile(const char* file, unsigned char **buffer);
|
size_t LoadFile(const char* file, unsigned char **buffer);
|
||||||
void readNextBatch(FILE *input, void *output);
|
void readNextBatch(FILE *input, void *output);
|
||||||
|
void readNextMusic(FILE *input, void *output);
|
||||||
void vbl_handler();
|
void vbl_handler();
|
||||||
|
|
||||||
class CircularQueue {
|
class CircularQueue {
|
||||||
@ -66,12 +70,50 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static uint8_t chunk[256*192*4*7];
|
static uint8_t chunk[256*192*4*7];
|
||||||
static int chunk_counter = 0;
|
static int chunk_counter = 0;
|
||||||
static CircularQueue queue(7);
|
static CircularQueue queue(7);
|
||||||
static FILE *in = NULL;
|
static FILE *in = NULL;
|
||||||
|
static FILE *in_music = NULL;
|
||||||
static int bgp;
|
static int bgp;
|
||||||
|
|
||||||
|
static uint8_t music_buffer[1024*1000];
|
||||||
|
static CircularQueue music_queue(1000);
|
||||||
|
|
||||||
|
mm_word on_stream_request( mm_word length, mm_addr dest, mm_stream_formats format ) {
|
||||||
|
if(in_music){
|
||||||
|
size_t samplesize = 1;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
dmaCopy(&music_buffer[1024*music_queue.front], dest, 1024);
|
||||||
|
music_queue.pop();
|
||||||
|
|
||||||
|
fprintf(stderr, "music %i/%i\n", music_queue.front, music_queue.current);
|
||||||
|
|
||||||
|
|
||||||
|
// fprintf(stderr, "%i %p %i\n", length, dest, format);
|
||||||
|
// int res = fread(music_buffer, 1, length, in_music);
|
||||||
|
// dmaCopy(music_buffer, dest, res);
|
||||||
|
// DC_FlushRange(music_buffer, 1024);
|
||||||
|
// if(res){
|
||||||
|
// length = res;
|
||||||
|
// } else {
|
||||||
|
// mmStreamClose();
|
||||||
|
// fclose(in_music);
|
||||||
|
// length = 0;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
videoSetMode(MODE_5_3D);
|
videoSetMode(MODE_5_3D);
|
||||||
@ -87,18 +129,10 @@ int main(void) {
|
|||||||
nitroFSInit(NULL);
|
nitroFSInit(NULL);
|
||||||
|
|
||||||
in = fopen("nitro:/image.bin", "rb");
|
in = fopen("nitro:/image.bin", "rb");
|
||||||
if (in == NULL) wait_forever("cannot load nitro:/image.bin");
|
if (in == NULL) wait_forever("cannot load image.bin");
|
||||||
|
|
||||||
// unsigned char* bmp = NULL;
|
in_music = fopen("nitro:/music.raw", "rb");
|
||||||
// unsigned char* bmp_decompress = (unsigned char*)malloc(256*192);
|
if (in_music == NULL) wait_forever("cannot load music.raw");
|
||||||
// size_t bmp_len = LoadFile("nitro:/image.bin", &bmp);
|
|
||||||
|
|
||||||
// // size_t bmp_decompress_len = bmp[0] | bmp[1] << 8;
|
|
||||||
// size_t bmp_decompress_len = 0;
|
|
||||||
|
|
||||||
// memcpy(&bmp_decompress_len, bmp, sizeof(uint32));
|
|
||||||
// fprintf(stderr, "%i %i\n", bmp_decompress_len, bmp_len);
|
|
||||||
// fastlz_decompress(&bmp[4], bmp_decompress_len, bmp_decompress, 256*192);
|
|
||||||
|
|
||||||
unsigned char* pal = NULL;
|
unsigned char* pal = NULL;
|
||||||
size_t pal_len = LoadFile("nitro:/palette.bin", &pal);
|
size_t pal_len = LoadFile("nitro:/palette.bin", &pal);
|
||||||
@ -106,10 +140,10 @@ int main(void) {
|
|||||||
bgp = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
|
bgp = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
|
||||||
|
|
||||||
dmaCopy(pal, BG_PALETTE, pal_len);
|
dmaCopy(pal, BG_PALETTE, pal_len);
|
||||||
// // DC_FlushRange(bg, bg_len);
|
|
||||||
// dmaCopy(bmp_decompress, bgGetGfxPtr(bgp), 256*192);
|
|
||||||
// nocashMessage("done\n");
|
|
||||||
|
|
||||||
|
// DC_FlushAll();
|
||||||
|
|
||||||
|
// timerStart(1, ClockDivider_1024, TIMER_FREQ_1024(30), music);
|
||||||
|
|
||||||
// fprintf(stderr, "start debug\n");
|
// fprintf(stderr, "start debug\n");
|
||||||
// int cframe = 0;
|
// int cframe = 0;
|
||||||
@ -138,9 +172,34 @@ int main(void) {
|
|||||||
queue.push();
|
queue.push();
|
||||||
readNextBatch(in, &chunk[256*192*4 * queue.rear]);
|
readNextBatch(in, &chunk[256*192*4 * queue.rear]);
|
||||||
fprintf(stderr, "read %i\n", queue.rear);
|
fprintf(stderr, "read %i\n", queue.rear);
|
||||||
// if (queue.rear == 1) break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(!music_queue.isFull()) {
|
||||||
|
music_queue.push();
|
||||||
|
readNextMusic(in_music, &music_buffer[1024 * music_queue.rear]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DC_FlushAll();
|
||||||
|
|
||||||
|
mm_ds_system sys;
|
||||||
|
sys.mod_count = 0;
|
||||||
|
sys.samp_count = 0;
|
||||||
|
sys.mem_bank = 0;
|
||||||
|
sys.fifo_channel = FIFO_MAXMOD;
|
||||||
|
mmInit( &sys );
|
||||||
|
|
||||||
|
|
||||||
|
mm_stream mystream;
|
||||||
|
mystream.sampling_rate = 1000;
|
||||||
|
mystream.buffer_length = 1024;
|
||||||
|
mystream.callback = on_stream_request;
|
||||||
|
mystream.format = MM_STREAM_16BIT_MONO;
|
||||||
|
mystream.timer = MM_TIMER2;
|
||||||
|
mystream.manual = true;
|
||||||
|
// mmStreamOpen( &mystream );
|
||||||
|
|
||||||
|
DC_FlushAll();
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
||||||
irqSet(IRQ_VBLANK, vbl_handler);
|
irqSet(IRQ_VBLANK, vbl_handler);
|
||||||
@ -150,6 +209,12 @@ int main(void) {
|
|||||||
readNextBatch(in, &chunk[256*192*4 * queue.rear]);
|
readNextBatch(in, &chunk[256*192*4 * queue.rear]);
|
||||||
// fprintf(stderr, "read %i\n", queue.rear);
|
// fprintf(stderr, "read %i\n", queue.rear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!music_queue.isFull()) {
|
||||||
|
music_queue.push();
|
||||||
|
readNextMusic(in_music, &music_buffer[1024 * music_queue.rear]);
|
||||||
|
fprintf(stderr, "read music %i\n", music_queue.rear);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -157,13 +222,16 @@ int main(void) {
|
|||||||
|
|
||||||
void vbl_handler()
|
void vbl_handler()
|
||||||
{
|
{
|
||||||
// if (queue.isEmpty() && chunk_counter == 0) {
|
mmStreamUpdate();
|
||||||
// return;
|
|
||||||
// fprintf(stderr, "NO QUEUE!!!!!");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
if (queue.isEmpty() && chunk_counter == 0) {
|
||||||
|
return;
|
||||||
|
fprintf(stderr, "NO QUEUE!!!!!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
DC_FlushRange(&chunk[256*192*4 * queue.front + 256*192*chunk_counter], 256*192*4);
|
||||||
dmaCopy(&chunk[256*192*4 * queue.front + 256*192*chunk_counter], bgGetGfxPtr(bgp), 256*192);
|
dmaCopy(&chunk[256*192*4 * queue.front + 256*192*chunk_counter], bgGetGfxPtr(bgp), 256*192);
|
||||||
fprintf(stderr, "count: %i, %i\n ", chunk_counter, queue.current);
|
// fprintf(stderr, "count: %i, %i\n ", chunk_counter, queue.current);
|
||||||
chunk_counter++;
|
chunk_counter++;
|
||||||
|
|
||||||
if (chunk_counter >= 4) {
|
if (chunk_counter >= 4) {
|
||||||
@ -172,11 +240,18 @@ void vbl_handler()
|
|||||||
chunk_counter = 0;
|
chunk_counter = 0;
|
||||||
} else {
|
} else {
|
||||||
chunk_counter = 4;
|
chunk_counter = 4;
|
||||||
fprintf(stderr, "NO QUEUE!!!!!");
|
fprintf(stderr, "NO QUEUE!!!!!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *buffer = malloc(256*192*4);
|
||||||
|
|
||||||
|
void readNextMusic(FILE *input, void *output)
|
||||||
|
{
|
||||||
|
fread(output, 1024, 1, input);
|
||||||
|
}
|
||||||
|
|
||||||
void readNextBatch(FILE *input, void *output)
|
void readNextBatch(FILE *input, void *output)
|
||||||
{
|
{
|
||||||
uint32_t chunk_len;
|
uint32_t chunk_len;
|
||||||
@ -185,20 +260,15 @@ void readNextBatch(FILE *input, void *output)
|
|||||||
bool isRLE = chunk_len & 0x01;
|
bool isRLE = chunk_len & 0x01;
|
||||||
chunk_len = chunk_len >> 1;
|
chunk_len = chunk_len >> 1;
|
||||||
|
|
||||||
uint8_t buffer[chunk_len];
|
|
||||||
// uint8_t *buffer2 = (uint8_t*)malloc(256*192*4);
|
|
||||||
fread(buffer, 1, chunk_len, input);
|
fread(buffer, 1, chunk_len, input);
|
||||||
|
DC_FlushRange(buffer, 256*192*4);
|
||||||
|
|
||||||
// DC_FlushRange(output, 256*192*4);
|
|
||||||
if (isRLE)
|
if (isRLE)
|
||||||
{
|
{
|
||||||
// fprintf(stderr, "rle\n");
|
|
||||||
decompress(buffer, output, RLE);
|
decompress(buffer, output, RLE);
|
||||||
// dmaCopy(buffer2, output, 256*192*4);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fprintf(stderr, "fastlz\n");
|
|
||||||
fastlz_decompress(buffer, chunk_len, output, 256*192*4);
|
fastlz_decompress(buffer, chunk_len, output, 256*192*4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,7 +298,7 @@ size_t LoadFile(const char* file, unsigned char **buffer)
|
|||||||
|
|
||||||
void wait_forever(const char* msg)
|
void wait_forever(const char* msg)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "%s", msg);
|
fprintf(stdout, "%s\n", msg);
|
||||||
fprintf(stderr, "%s", msg);
|
fprintf(stderr, "%s\n", msg);
|
||||||
while (1) swiWaitForVBlank();
|
while (1) swiWaitForVBlank();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user