[Dev Question] Initializing MAD?

Discussion in '3DS - Homebrew Development and Emulators' started by kprovost7314, Sep 25, 2016.

  1. kprovost7314
    OP

    kprovost7314 GBAtemp's Official Bara Master

    Member
    1,729
    943
    Dec 24, 2014
    United States
    In that bara manga ( ͡° ͜ʖ ͡°)
    I'm trying to create a way to play a MP3 file with libMAD but I can't find anything on google about how to initialize it other than the official documentation which I still get errors afterwards. This is what I have so far:

    Code:
    /* MAD and LibCTRU streaming example
    *  Author: Kaleb Provost (kprovost7314)
    *  Desc: A PoC that plays MP3 Files
    */
    #include <3ds.h>
    #include <stdio.h>
    #include <mad.h>
    
    #include "Bokuboku_mp3.h"
    
    struct mad_decoder decode;
    struct mad_stream stream;
    struct mad_header header;
    struct mad_pcm output;
    
    
    
    struct buffer {
    
    	unsigned char const *start;
    	unsigned long length;
    };
    
    struct buffer bufferData;
    
    int main(int argc, char **argv)
    {
    	//Initialize gfx (note: not needed if you're using SF2Dlib)
    	gfxInitDefault();
    	
    	consoleInit(GFX_TOP, NULL);
    	printf("Streaming A MP3 file with MAD and LibCTRU\n");
    	
    	csndInit();
    	mad_decoder_init(&decode, &bufferData, stream, 0, 0, output, 0, 0);
    
    	
    	// Main loop
    	while (aptMainLoop())
    	{
    		//Scan all the inputs. This should be done once for each frame
    		hidScanInput();
    		
    		//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
    		//hidKeysHeld returns information about which buttons are currently pressed (regardless if they were pressed or not pressed in the previous frame)
    		//hidKeysUp returns information about which buttons are not pressed but were pressed in the previous frame
    		u32 kDown = hidKeysDown();
    		
    		
    		
    		if (kDown & KEY_START) break; // break in order to return to hbmenu
    		// YOU WANT TO LEAVE ME?????
    		/*
    		I'11 FL00D thE // SYSTEM f0r3v3r
    		JK, Y0u'11 c0M3 b4ck
    		1 kn0w y0u wi11
    		*/
    		
    		
    		// Flush and swap framebuffers, this is needed for rendering these will not be needed when using SF2D lib
    		gfxFlushBuffers();
    		gfxSwapBuffers();
    		
    		//Wait for VBlank, this is needed for rendering these will not be needed when using SF2D lib
    		gspWaitForVBlank();
    	}
    	mad_decoder_finish(&decode);
    	gfxExit();
    	return 0;
    }
    How do I initialize it?