Homebrew Homebrew Development

cracker

Nyah!
Member
Joined
Aug 24, 2005
Messages
3,619
Trophies
1
XP
2,213
Country
United States
Simple is a relative term. What platform are you targeting? There are so many takes on ogg decoders but without knowing what hardware you want to use it on there is no way to search for an easy solution for you.
 

cracker

Nyah!
Member
Joined
Aug 24, 2005
Messages
3,619
Trophies
1
XP
2,213
Country
United States
Don't quote me on this, but I'm fairly sure he wants to use it on, you know, 3DS. Since this is the 3DS homebrew development section.

There have been OT talks of general programming info so I wanted the clarification. :P

Yeah, I was hoping for one already ported to the 3ds because I'm not experienced with audio enough to port one myself.

By simple, I mean something like this C code I made up that's similar to SoLoud.
Code:
OggSound myGoodOggSound;
OggStream myGoodOggStream;

PlayHandle myPlayHandle1;
PlayHandle myPlayHandle2;

initAudio(OGG);

loadSound(&myGoodOggSound,"sfx.ogg");
loadStream(&myGoodOggStream,"music.ogg");

myPlayHandle1= playSound(myGoodOggSound);
myPlayHandle2 = playStream(myGoodOggStream);

while(1);

If there are no alternatives, I'll try SDL_Mixer. I don't want to though because it can only play one music stream at a time.

LPP has ogg support that you could borrow from. Here is the piece of code that handles the stream decoding.
 
  • Like
Reactions: Deleted User
D

Deleted User

Guest
Yeah, I was hoping for one already ported to the 3ds because I'm not experienced with audio enough to port one myself.

By simple, I mean something like this C code I made up that's similar to SoLoud.
Code:
OggSound myGoodOggSound;
OggStream myGoodOggStream;

PlayHandle myPlayHandle1;
PlayHandle myPlayHandle2;

initAudio(OGG);

loadSound(&myGoodOggSound,"sfx.ogg");
loadStream(&myGoodOggStream,"music.ogg");

myPlayHandle1= playSound(myGoodOggSound);
myPlayHandle2 = playStream(myGoodOggStream);

while(1);

If there are no alternatives, I'll try SDL_Mixer. I don't want to though because it can only play one music stream at a time.
You could also borrow some some of the code from ctrmus. It's licensed under the GPL v3.0.
 
  • Like
Reactions: Deleted User

tgaiu

Active Member
Newcomer
Joined
Sep 10, 2017
Messages
33
Trophies
0
XP
75
Country
Japan
I attempted to play the ogg file using libtremor but failed.
Is there a mistake in the code?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <3ds.h>

#define MUSIC_CHANNEL 1
#define BUFFER_SIZE 4096
#define STACKSIZE (4 * 1024)

typedef struct {
	
	float rate;
	u32 channels;
	u32 encoding;
	u32 nsamples;
	u32 size;
	char* data;
	bool loop;
	int audiochannel;

	float mix[12];
	ndspInterpType interp;

	OggVorbis_File ovf;
} Music;
Music music;

void load() {
	FILE * file = fopen("example.ogg", "rb");
	if (ov_open(file, &music.ovf, NULL, 0) < 0) {
		printf("ogg vorbis file error\n");
	}
	vorbis_info * vorbisInfo = ov_info(&music.ovf, -1);
	if (vorbisInfo == NULL) {
		printf("could not retrieve ogg audio stream information\n");
	}
	music.rate = (float)vorbisInfo->rate;
	music.channels = (u32)vorbisInfo->channels;
	music.encoding = NDSP_ENCODING_PCM16;
	music.nsamples = (u32)ov_pcm_total(&music.ovf, -1);
	music.size = music.nsamples * music.channels * 2;
	music.audiochannel = 0;
	music.loop = false;
	if (linearSpaceFree() < music.size) {
		printf("not enough linear memory available\n");
	}
	music.data = (char*)linearAlloc(music.size);

	printf("rate:%f\n", music.rate);
	printf("channels:%ld\n", music.channels);
	printf("encoding:%ld\n", music.encoding);
	printf("nsamples:%ld\n", music.nsamples);
	printf("size:%ld\n", music.size);

	int offset = 0;
	int eof = 0;
	int currentSection;

	while (!eof) {
		long ret = ov_read(&music.ovf, &music.data[offset], 4096, &currentSection);
		if (ret == 0) {
			eof = 1;
		}
		else if (ret < 0) {
			ov_clear(&music.ovf);
			linearFree(music.data);
			printf("error in the ogg vorbis stream\n");
		}
		else {
			offset += ret;
		}
	}
	linearFree(&music.ovf);
	ov_clear(&music.ovf);
	fclose(file);
}

int play() {
	if (music.audiochannel == -1) {
		printf("No available audio channel\n");
		return -1;
	}
	ndspChnWaveBufClear(music.audiochannel);
	ndspChnReset(music.audiochannel);
	ndspChnInitParams(music.audiochannel);
	ndspChnSetMix(music.audiochannel, music.mix);
	ndspChnSetInterp(music.audiochannel, music.interp);
	ndspChnSetRate(music.audiochannel, music.rate);
	ndspChnSetFormat(music.audiochannel, NDSP_CHANNELS(music.channels) | NDSP_ENCODING(music.encoding));
	
	ndspWaveBuf waveBuf;

	waveBuf.data_vaddr = music.data;
	waveBuf.nsamples = music.nsamples;
	waveBuf.looping = music.loop;

	DSP_FlushDataCache((u32*)music.data, music.size);

	ndspChnWaveBufAdd(music.audiochannel, &waveBuf);
	return 0;
}


int main() {
	gfxInitDefault();
	consoleInit(GFX_TOP, nullptr);

	load();
	play();
	while (1) {
		hidScanInput();
		u32 kDown = hidKeysDown();
		if (kDown & KEY_START) break;

		gfxFlushBuffers();
		gfxSwapBuffers();
		gspWaitForVBlank();
	}
	gfxExit();
	ndspExit();
	return 0;
}
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,033
Country
United States
I attempted to play the ogg file using libtremor but failed.
Is there a mistake in the code?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <3ds.h>

#define MUSIC_CHANNEL 1
#define BUFFER_SIZE 4096
#define STACKSIZE (4 * 1024)

typedef struct {
   
    float rate;
    u32 channels;
    u32 encoding;
    u32 nsamples;
    u32 size;
    char* data;
    bool loop;
    int audiochannel;

    float mix[12];
    ndspInterpType interp;

    OggVorbis_File ovf;
} Music;
Music music;

void load() {
    FILE * file = fopen("example.ogg", "rb");
    if (ov_open(file, &music.ovf, NULL, 0) < 0) {
        printf("ogg vorbis file error\n");
    }
    vorbis_info * vorbisInfo = ov_info(&music.ovf, -1);
    if (vorbisInfo == NULL) {
        printf("could not retrieve ogg audio stream information\n");
    }
    music.rate = (float)vorbisInfo->rate;
    music.channels = (u32)vorbisInfo->channels;
    music.encoding = NDSP_ENCODING_PCM16;
    music.nsamples = (u32)ov_pcm_total(&music.ovf, -1);
    music.size = music.nsamples * music.channels * 2;
    music.audiochannel = 0;
    music.loop = false;
    if (linearSpaceFree() < music.size) {
        printf("not enough linear memory available\n");
    }
    music.data = (char*)linearAlloc(music.size);

    printf("rate:%f\n", music.rate);
    printf("channels:%ld\n", music.channels);
    printf("encoding:%ld\n", music.encoding);
    printf("nsamples:%ld\n", music.nsamples);
    printf("size:%ld\n", music.size);

    int offset = 0;
    int eof = 0;
    int currentSection;

    while (!eof) {
        long ret = ov_read(&music.ovf, &music.data[offset], 4096, &currentSection);
        if (ret == 0) {
            eof = 1;
        }
        else if (ret < 0) {
            ov_clear(&music.ovf);
            linearFree(music.data);
            printf("error in the ogg vorbis stream\n");
        }
        else {
            offset += ret;
        }
    }
    linearFree(&music.ovf);
    ov_clear(&music.ovf);
    fclose(file);
}

int play() {
    if (music.audiochannel == -1) {
        printf("No available audio channel\n");
        return -1;
    }
    ndspChnWaveBufClear(music.audiochannel);
    ndspChnReset(music.audiochannel);
    ndspChnInitParams(music.audiochannel);
    ndspChnSetMix(music.audiochannel, music.mix);
    ndspChnSetInterp(music.audiochannel, music.interp);
    ndspChnSetRate(music.audiochannel, music.rate);
    ndspChnSetFormat(music.audiochannel, NDSP_CHANNELS(music.channels) | NDSP_ENCODING(music.encoding));
   
    ndspWaveBuf waveBuf;

    waveBuf.data_vaddr = music.data;
    waveBuf.nsamples = music.nsamples;
    waveBuf.looping = music.loop;

    DSP_FlushDataCache((u32*)music.data, music.size);

    ndspChnWaveBufAdd(music.audiochannel, &waveBuf);
    return 0;
}


int main() {
    gfxInitDefault();
    consoleInit(GFX_TOP, nullptr);

    load();
    play();
    while (1) {
        hidScanInput();
        u32 kDown = hidKeysDown();
        if (kDown & KEY_START) break;

        gfxFlushBuffers();
        gfxSwapBuffers();
        gspWaitForVBlank();
    }
    gfxExit();
    ndspExit();
    return 0;
}
I don’t see a call to ndspInit?
 

tgaiu

Active Member
Newcomer
Joined
Sep 10, 2017
Messages
33
Trophies
0
XP
75
Country
Japan
I don’t see a call to ndspInit?
I made those improvements but got errors.
Code:
[HW.Memory <Error> core\memory.cpp:GetPointer:283: unknown GetPointer @ 0x00000000
[Audio.DSP <Warning> audio_core\hle\source.cpp:DequeueBuffer:312: source_id=0 buffer_id=20 length=0: Invalid physical address 0x00000000
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <3ds.h>

#define MUSIC_CHANNEL 1
#define BUFFER_SIZE 4096
#define STACKSIZE (4 * 1024)

typedef struct {

	float rate;
	u32 channels;
	u32 encoding;
	u32 nsamples;
	u32 size;
	u8* data;
	bool loop;
	int audiochannel;

	float mix[12];
	ndspInterpType interp;

	OggVorbis_File ovf;
} Music;
Music music;

void load() {
	FILE * file = fopen("example.ogg", "rb");
	if (ov_open(file, &music.ovf, NULL, 0) < 0) {
		printf("ogg vorbis file error\n");
	}
	vorbis_info * vorbisInfo = ov_info(&music.ovf, -1);
	if (vorbisInfo == NULL) {
		printf("could not retrieve ogg audio stream information\n");
	}
	music.rate = (float)vorbisInfo->rate;
	music.channels = (u32)vorbisInfo->channels;
	music.encoding = NDSP_ENCODING_PCM16;
	music.nsamples = (u32)ov_pcm_total(&music.ovf, -1);
	music.size = music.nsamples * music.channels * 2;
	music.audiochannel = 0;
	music.loop = false;
	if (linearSpaceFree() < music.size) {
		printf("not enough linear memory available\n");
	music.data = static_cast<u8*>(linearAlloc(music.size));

	printf("rate:%f\n", music.rate);
	printf("channels:%ld\n", music.channels);
	printf("encoding:%ld\n", music.encoding);
	printf("nsamples:%ld\n", music.nsamples);
	printf("size:%ld\n", music.size);

	int offset = 0;
	int eof = 0;
	int currentSection;

	while (!eof) {
		long ret = ov_read(&music.ovf, &music.data[offset], 4096, &currentSection);
		if (ret == 0) {
			eof = 1;
		}
		else if (ret < 0) {
			ov_clear(&music.ovf);
			linearFree(music.data);
			printf("error in the ogg vorbis stream\n");
		}
		else {
			offset += ret;
		}
	}
	linearFree(&music.ovf);
	ov_clear(&music.ovf);
	fclose(file);
}

int play() {
	if (music.audiochannel == -1) {
		printf("No available audio channel\n");
		return -1;
	}
	ndspChnWaveBufClear(music.audiochannel);
	ndspChnReset(music.audiochannel);
	ndspChnInitParams(music.audiochannel);
	ndspChnSetMix(music.audiochannel, music.mix);
	ndspChnSetInterp(music.audiochannel, music.interp);
	ndspChnSetRate(music.audiochannel, music.rate);
	ndspChnSetFormat(music.audiochannel, NDSP_CHANNELS(music.channels) | NDSP_ENCODING(music.encoding));

	ndspWaveBuf waveBuf;
	memset(&waveBuf, 0, sizeof(ndspWaveBuf));
	waveBuf.data_vaddr = music.data;
	waveBuf.nsamples = music.nsamples;
	waveBuf.looping = music.loop;
	waveBuf.status = NDSP_WBUF_FREE;

	DSP_FlushDataCache(music.data, music.size);

	ndspChnWaveBufAdd(music.audiochannel, &waveBuf);
	return 0;
}


int main() {
	gfxInitDefault();
	consoleInit(GFX_TOP, nullptr);

	ndspInit();
	ndspSetOutputMode(NDSP_OUTPUT_STEREO);
	ndspSetOutputCount(1);

	load();
	play();
	while (aptMainLoop()) {
		hidScanInput();
		u32 keys = hidKeysDown();
		if (keys & KEY_START)
			break;

		gfxFlushBuffers();
		gfxSwapBuffers();
		gspWaitForVBlank();
	}
	ndspChnWaveBufClear(music.audiochannel);
	gfxExit();
	ndspExit();
	return 0;
}
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,033
Country
United States
I made those improvements but got errors.
Code:
[HW.Memory <Error> core\memory.cpp:GetPointer:283: unknown GetPointer @ 0x00000000
[Audio.DSP <Warning> audio_core\hle\source.cpp:DequeueBuffer:312: source_id=0 buffer_id=20 length=0: Invalid physical address 0x00000000
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <3ds.h>

#define MUSIC_CHANNEL 1
#define BUFFER_SIZE 4096
#define STACKSIZE (4 * 1024)

typedef struct {

    float rate;
    u32 channels;
    u32 encoding;
    u32 nsamples;
    u32 size;
    u8* data;
    bool loop;
    int audiochannel;

    float mix[12];
    ndspInterpType interp;

    OggVorbis_File ovf;
} Music;
Music music;

void load() {
    FILE * file = fopen("example.ogg", "rb");
    if (ov_open(file, &music.ovf, NULL, 0) < 0) {
        printf("ogg vorbis file error\n");
    }
    vorbis_info * vorbisInfo = ov_info(&music.ovf, -1);
    if (vorbisInfo == NULL) {
        printf("could not retrieve ogg audio stream information\n");
    }
    music.rate = (float)vorbisInfo->rate;
    music.channels = (u32)vorbisInfo->channels;
    music.encoding = NDSP_ENCODING_PCM16;
    music.nsamples = (u32)ov_pcm_total(&music.ovf, -1);
    music.size = music.nsamples * music.channels * 2;
    music.audiochannel = 0;
    music.loop = false;
    if (linearSpaceFree() < music.size) {
        printf("not enough linear memory available\n");
    music.data = static_cast<u8*>(linearAlloc(music.size));

    printf("rate:%f\n", music.rate);
    printf("channels:%ld\n", music.channels);
    printf("encoding:%ld\n", music.encoding);
    printf("nsamples:%ld\n", music.nsamples);
    printf("size:%ld\n", music.size);

    int offset = 0;
    int eof = 0;
    int currentSection;

    while (!eof) {
        long ret = ov_read(&music.ovf, &music.data[offset], 4096, &currentSection);
        if (ret == 0) {
            eof = 1;
        }
        else if (ret < 0) {
            ov_clear(&music.ovf);
            linearFree(music.data);
            printf("error in the ogg vorbis stream\n");
        }
        else {
            offset += ret;
        }
    }
    linearFree(&music.ovf);
    ov_clear(&music.ovf);
    fclose(file);
}

int play() {
    if (music.audiochannel == -1) {
        printf("No available audio channel\n");
        return -1;
    }
    ndspChnWaveBufClear(music.audiochannel);
    ndspChnReset(music.audiochannel);
    ndspChnInitParams(music.audiochannel);
    ndspChnSetMix(music.audiochannel, music.mix);
    ndspChnSetInterp(music.audiochannel, music.interp);
    ndspChnSetRate(music.audiochannel, music.rate);
    ndspChnSetFormat(music.audiochannel, NDSP_CHANNELS(music.channels) | NDSP_ENCODING(music.encoding));

    ndspWaveBuf waveBuf;
    memset(&waveBuf, 0, sizeof(ndspWaveBuf));
    waveBuf.data_vaddr = music.data;
    waveBuf.nsamples = music.nsamples;
    waveBuf.looping = music.loop;
    waveBuf.status = NDSP_WBUF_FREE;

    DSP_FlushDataCache(music.data, music.size);

    ndspChnWaveBufAdd(music.audiochannel, &waveBuf);
    return 0;
}


int main() {
    gfxInitDefault();
    consoleInit(GFX_TOP, nullptr);

    ndspInit();
    ndspSetOutputMode(NDSP_OUTPUT_STEREO);
    ndspSetOutputCount(1);

    load();
    play();
    while (aptMainLoop()) {
        hidScanInput();
        u32 keys = hidKeysDown();
        if (keys & KEY_START)
            break;

        gfxFlushBuffers();
        gfxSwapBuffers();
        gspWaitForVBlank();
    }
    ndspChnWaveBufClear(music.audiochannel);
    gfxExit();
    ndspExit();
    return 0;
}
Check if linearAlloc succeeded?
Why are you calling linearFree in the load function - on non “linear” region memory(music.ovf)?
 

tgaiu

Active Member
Newcomer
Joined
Sep 10, 2017
Messages
33
Trophies
0
XP
75
Country
Japan
Check if linearAlloc succeeded?
Why are you calling linearFree in the load function - on non “linear” region memory(music.ovf)?
I made a mistake in placing linearFree.
linearAlloc seemed to be successful.
It seems that gspWaitForVBlank () is causing problems, but is it OK to delete this?
 

niBBasian

Member
Newcomer
Joined
Nov 27, 2017
Messages
7
Trophies
0
Age
28
XP
63
Country
Singapore
guys i know this sounds silly but i am new to the modding scene and also to gba temp . BUT I DONT KNOW HOW TO POST A FU#%ING question!!!!!!!!!!!!!!!HOW DO U POST ON GBATEMP NET!!!!!!!!!!!!!!!!!!
 

NatsumiX

Well-Known Member
Newcomer
Joined
Oct 9, 2017
Messages
69
Trophies
0
XP
110
Country
United States
guys i know this sounds silly but i am new to the modding scene and also to gba temp . BUT I DONT KNOW HOW TO POST A FU#%ING question!!!!!!!!!!!!!!!HOW DO U POST ON GBATEMP NET!!!!!!!!!!!!!!!!!!
aoyNMDx.png
 

tgaiu

Active Member
Newcomer
Joined
Sep 10, 2017
Messages
33
Trophies
0
XP
75
Country
Japan
I made those improvements but got errors.
Code:
[HW.Memory <Error> core\memory.cpp:GetPointer:283: unknown GetPointer @ 0x00000000
[Audio.DSP <Warning> audio_core\hle\source.cpp:DequeueBuffer:312: source_id=0 buffer_id=20 length=0: Invalid physical address 0x00000000
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <3ds.h>

#define MUSIC_CHANNEL 1
#define BUFFER_SIZE 4096
#define STACKSIZE (4 * 1024)

typedef struct {

    float rate;
    u32 channels;
    u32 encoding;
    u32 nsamples;
    u32 size;
    u8* data;
    bool loop;
    int audiochannel;

    float mix[12];
    ndspInterpType interp;

    OggVorbis_File ovf;
} Music;
Music music;

void load() {
    FILE * file = fopen("example.ogg", "rb");
    if (ov_open(file, &music.ovf, NULL, 0) < 0) {
        printf("ogg vorbis file error\n");
    }
    vorbis_info * vorbisInfo = ov_info(&music.ovf, -1);
    if (vorbisInfo == NULL) {
        printf("could not retrieve ogg audio stream information\n");
    }
    music.rate = (float)vorbisInfo->rate;
    music.channels = (u32)vorbisInfo->channels;
    music.encoding = NDSP_ENCODING_PCM16;
    music.nsamples = (u32)ov_pcm_total(&music.ovf, -1);
    music.size = music.nsamples * music.channels * 2;
    music.audiochannel = 0;
    music.loop = false;
    if (linearSpaceFree() < music.size) {
        printf("not enough linear memory available\n");
    music.data = static_cast<u8*>(linearAlloc(music.size));

    printf("rate:%f\n", music.rate);
    printf("channels:%ld\n", music.channels);
    printf("encoding:%ld\n", music.encoding);
    printf("nsamples:%ld\n", music.nsamples);
    printf("size:%ld\n", music.size);

    int offset = 0;
    int eof = 0;
    int currentSection;

    while (!eof) {
        long ret = ov_read(&music.ovf, &music.data[offset], 4096, &currentSection);
        if (ret == 0) {
            eof = 1;
        }
        else if (ret < 0) {
            ov_clear(&music.ovf);
            linearFree(music.data);
            printf("error in the ogg vorbis stream\n");
        }
        else {
            offset += ret;
        }
    }
    linearFree(&music.ovf);
    ov_clear(&music.ovf);
    fclose(file);
}

int play() {
    if (music.audiochannel == -1) {
        printf("No available audio channel\n");
        return -1;
    }
    ndspChnWaveBufClear(music.audiochannel);
    ndspChnReset(music.audiochannel);
    ndspChnInitParams(music.audiochannel);
    ndspChnSetMix(music.audiochannel, music.mix);
    ndspChnSetInterp(music.audiochannel, music.interp);
    ndspChnSetRate(music.audiochannel, music.rate);
    ndspChnSetFormat(music.audiochannel, NDSP_CHANNELS(music.channels) | NDSP_ENCODING(music.encoding));

    ndspWaveBuf waveBuf;
    memset(&waveBuf, 0, sizeof(ndspWaveBuf));
    waveBuf.data_vaddr = music.data;
    waveBuf.nsamples = music.nsamples;
    waveBuf.looping = music.loop;
    waveBuf.status = NDSP_WBUF_FREE;

    DSP_FlushDataCache(music.data, music.size);

    ndspChnWaveBufAdd(music.audiochannel, &waveBuf);
    return 0;
}


int main() {
    gfxInitDefault();
    consoleInit(GFX_TOP, nullptr);

    ndspInit();
    ndspSetOutputMode(NDSP_OUTPUT_STEREO);
    ndspSetOutputCount(1);

    load();
    play();
    while (aptMainLoop()) {
        hidScanInput();
        u32 keys = hidKeysDown();
        if (keys & KEY_START)
            break;

        gfxFlushBuffers();
        gfxSwapBuffers();
        gspWaitForVBlank();
    }
    ndspChnWaveBufClear(music.audiochannel);
    gfxExit();
    ndspExit();
    return 0;
}

I tried a variety of hands, but I get a similar error.
Please let me know if you know the solution.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <3ds.h>

typedef struct {
	float rate;
	u32 channels;
	u32 encoding;
	u32 nsamples;
	u32 size;
	char* data;
	bool loop;
	int audiochannel;
	float mix[12];
	ndspInterpType interp;
	OggVorbis_File ovf;
} Music;
Music music;

void load() {
	FILE * file = fopen("test.ogg", "rb");
	if (ov_open(file, &music.ovf, NULL, 0) < 0) {
		printf("ogg vorbis file error\n");
	}
	vorbis_info * vorbisInfo = ov_info(&music.ovf, -1);
	if (vorbisInfo == NULL) {
		printf("could not retrieve ogg audio stream information\n");
	}
	music.rate = (float)vorbisInfo->rate;
	music.channels = (u32)vorbisInfo->channels;
	music.encoding = NDSP_ENCODING_PCM16;
	music.nsamples = (u32)ov_pcm_total(&music.ovf, -1);
	music.size = music.nsamples * music.channels * 2;
	music.audiochannel = 0;
	music.loop = false;
	music.interp = NDSP_INTERP_NONE;
	if (linearSpaceFree() < music.size) {
		printf("not enough linear memory available\n");
	}
	music.data = static_cast<char*>(linearAlloc(music.size));
	if (!music.data){
		fclose(file);
	}
	printf("buffersize:%d\n", linearGetSize(music.data));
	printf("rate:%f\n", music.rate);
	printf("channels:%ld\n", music.channels);
	printf("encoding:%ld\n", music.encoding);
	printf("nsamples:%ld\n", music.nsamples);
	printf("size:%ld\n", music.size);

	// Decoding loop
	int offset = 0;
	int eof = 0;
	int currentSection = 0;
	int readSize = 0;
	int comSize = 0;
	char* tmpBuffer = static_cast<char*>(linearAlloc(music.size));
	while (1) {
		readSize = ov_read(&music.ovf, (char*)tmpBuffer, 4096, &currentSection);
		if (readSize == 0) break; //EOF
		memcpy(music.data + comSize, tmpBuffer, readSize);
		comSize += readSize;
	}
	fclose(file);
}

int play() {
	if (music.audiochannel == -1) {
		printf("No available audio channel\n");
		return -1;
	}
	ndspChnReset(music.audiochannel);
	ndspChnInitParams(music.audiochannel);
	ndspChnSetMix(music.audiochannel, music.mix);
	ndspChnSetInterp(music.audiochannel, music.interp);
	ndspChnSetRate(music.audiochannel, music.rate);
	ndspChnSetFormat(music.audiochannel, NDSP_CHANNELS(music.channels) | NDSP_ENCODING(music.encoding));
	
	ndspWaveBuf waveBuf;
	memset(&waveBuf, 0, sizeof(ndspWaveBuf));
	waveBuf.data_vaddr = (const void*)music.data;
	waveBuf.nsamples = music.nsamples;
	waveBuf.looping = music.loop;
	waveBuf.status = NDSP_WBUF_FREE;
	DSP_FlushDataCache(music.data, music.size);
	ndspChnWaveBufAdd(music.audiochannel, &waveBuf);
	return 0;
}


int main() {
	gfxInitDefault();
	consoleInit(GFX_TOP, nullptr);

	ndspInit();
	ndspSetOutputMode(NDSP_OUTPUT_STEREO);
	ndspSetOutputCount(1);

	load();
	play();
	while (aptMainLoop()) {
		hidScanInput();
		u32 keys = hidKeysDown();
		if (keys & KEY_START)
			break;
		gfxFlushBuffers();
		gfxSwapBuffers();
		gspWaitForVBlank();
	}
	linearFree(&music.ovf);
	ov_clear(&music.ovf);
	ndspChnWaveBufClear(music.audiochannel);
	gfxExit();
	ndspExit();
	return 0;
}
 

cracker

Nyah!
Member
Joined
Aug 24, 2005
Messages
3,619
Trophies
1
XP
2,213
Country
United States
That's not necessarily a problem with your code. Even legit games have that error in Citra. You will need to use the real hardware to test it.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • Psionic Roshambo @ Psionic Roshambo:
    I would like a Predator game "Kill Team" it takes place in the Jungle of the first movie, your team is sent to hunt the predator, using current tech drones and a trained team. Set traps use strategy to hunt and trap or kill the predator.
  • BigOnYa @ BigOnYa:
    Ill stick with my Battlefield. Yea a predator hunting game like that would be cool. Esp if you can be Arnold and say "Get to da choppa"
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Maybe Arnold could do a cameo voice acting, he is the one briefing you on the mission
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Honestly surprised they didn't make a tie in game for Predators that movie was awesome
  • Psionic Roshambo @ Psionic Roshambo:
    I was kinda sad the Yakuza guy died sword fighting a predator lol
  • Psionic Roshambo @ Psionic Roshambo:
    The Russian guy went out like a boss
  • Psionic Roshambo @ Psionic Roshambo:
    Double claymores to the face definitely kill a predator lol
  • BigOnYa @ BigOnYa:
    I went today and looked at a motorcycle someone was selling. I get there and the battery on it was dead, so the guy grabbed a battery charger and hooked it up. He plugged it into the wall, and the motorcycle sparked and started smoking. Come to find out the bike uses a 6 volt battery and the guy had the charger set to 12v. I said sorry to the dude and walked away. I felt bad for him tho.
  • Psionic Roshambo @ Psionic Roshambo:
    Sounds like it would be an exciting ride....
  • Psionic Roshambo @ Psionic Roshambo:
    Not sure I would want something on fire between my legs
  • BigOnYa @ BigOnYa:
    He ruined it basically. Sad cause it was a decent old bike. It would take more money to rewire the bike than it was worth tho.
  • Psionic Roshambo @ Psionic Roshambo:
    Yeah I'm sure at minimum the starter was fried
  • Psionic Roshambo @ Psionic Roshambo:
    Alternator and battery
  • BigOnYa @ BigOnYa:
    Prob alot of fried parts. It was still smoking when I left.
  • K3Nv2 @ K3Nv2:
    I would've said show me how it rides
  • Psionic Roshambo @ Psionic Roshambo:
    I always wanted one of those Smart Cars with a Hyabusa motor in it.
  • K3Nv2 @ K3Nv2:
    I'm getting sick and tired of cheap ass baking pans now
  • BigOnYa @ BigOnYa:
    I think it be cool to have one that would fit in my pickup truck bed, then I could put down ramps n drive it off.
  • K3Nv2 @ K3Nv2:
    Used this one 5 times already impossible to clean
  • BigOnYa @ BigOnYa:
    You need the $900 copper coated ones, they are good for 10 times cooking before they are un cleanable
  • Psionic Roshambo @ Psionic Roshambo:
    Condoms are only meant to be used once Ken lol
  • K3Nv2 @ K3Nv2:
    Well damn that explains how you were born
    Psionic Roshambo @ Psionic Roshambo: Lol