stream sound[solved]

support for the gba/nds sound library from www.maxmod.org

Moderator: eKid

eKid
Posts: 65
Joined: Sat Dec 06, 2008 6:07 pm
Contact:

Re: streaming audio

Post by eKid » Sat Mar 21, 2009 1:34 pm

The header file contains definitions for the indexes in the sound bank. You need it if you want to load a specific song/sample.

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: streaming audio

Post by Tomdev » Sat Mar 21, 2009 4:02 pm

thanks it works now!!!! nice music :lol:

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: streaming audio

Post by Tomdev » Fri Jun 26, 2009 9:26 am

sorry for the double post, but now i have to do real streaming with raw data:P I've looked in the example and i saw that you have to call mmStreamUpdate manually. but i'm very new to streaming. i can decode some music intro raw music and play that part, but that part is only 4k raw music, not very much to hear :P so i have to update the stream every time as the example said to hear the whole file, but how? my situation:

i've an audio file, 44100hz 2 channels, i decode 4k of the current part of the audio file in my decode function.

but how do i know when i've to update the buffer and call mStreamUpdate manually?

eKid
Posts: 65
Joined: Sat Dec 06, 2008 6:07 pm
Contact:

Re: streaming audio

Post by eKid » Fri Jun 26, 2009 2:06 pm

When you call mmStreamUpdate, it gives you the number of samples that needs to be filled.

Do you need to decode exactly 4k samples? If so, then you want to have a buffer size that is a bit larger than 4k, so you have enough room to decode into, plus enough room for some overhead and then the actual sample decoding. 5k buffer size should be safe with simple raw data. In your stream update routine, you don't have to fill all of the samples that are requested, so you can decode 4k blocks at a time. You first check if the 'length' parameter given to see if it is >= 4096, and then you fill that many samples and then return '4096' so it knows that's how many samples you filled. If it's less than 4096 then you can just return 0 and the streaming request will be saved for the next call (and more samples will be requested). The remaining amount of samples that weren't filled are saved for the next time you call mmStreamUpdate.

Note that this only applies for the 'manual' streaming mode. In the automatic mode the mmStreamUpdate function is called internally and you must fill all of the samples requested.

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: streaming audio

Post by Tomdev » Fri Jun 26, 2009 3:13 pm

i'm very bad at sound, but what i do is decoding an ogg vorbis file. i've compiled tremor(the fixed point version) and i can decode. so for now i've this function:

Code: Select all

void Update_OGG_Stream(u8 channels, OggVorbis_File * vf, void * buffer){

readed = 0;// we hebben immers nog niks gelezen in deze update
 
while(readed<OGG_BUFFER_SIZE){

    long ret = ov_read(vf,buffer,(OGG_BUFFER_SIZE-readed)*2*channels,&current_section); // ret returns how much the function actually decoded

    if (ret == 0) {// we zijn aan het eind van de file
  	iprintf("we zijn klaar!");

    } else if (ret < 0) {// er is iets mis gegaan
	iprintf("fout tijdens decoden");
    } else {
	buffer+=ret;
        readed+=ret/channels*2;
    }
  }
}
OGG_BUFFER_SIZE is defined as 4096, 4k.

you said that mmStreamUpdate returns how much samples need to be filled? so say it returned 2000 i could fill 2000 samples with a bit modified function? and am i understanding the function mmStreamUpdate correctly, because i think it returns how much samples the stream needs and I have to decode that amount to the addres it returns. but like this i don have to care about timing? and i don't need to decode 4096 bytes, it may variate. but you said samples, and i'm talking about decoded data in bytes, is this very different or not?

eKid
Posts: 65
Joined: Sat Dec 06, 2008 6:07 pm
Contact:

Re: streaming audio

Post by eKid » Fri Jun 26, 2009 4:48 pm

For a function like that I think something like this should work (expecting 16-bit mono data (2048 samples, 4096 bytes))

Code: Select all

mm_word on_stream_request( mm_word length, mm_addr dest, mm_stream_formats format ) {

	int filled = 0;
	s16 *target = (s16*)dest;

	while( length >= 2048 ) {
		length -= 2048;
		filled += 2048;
		Update_OGG_Stream( 1, vorbisfile, target );
		target += 2048;
	}
	return filled;
}
For OGG decoding I would assume a much heavier load so I would go with probably an 8k buffer (4k samples) or so for 4k byte chunks.

Another somewhat unrelated thing to note is that the streaming startup routine will call the stream request function to pre-fill the buffer. So you should make sure the vorbis file is opened before starting the stream (or test for that error in the filling routine).

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: streaming audio

Post by Tomdev » Fri Jun 26, 2009 5:57 pm

but the data is 2 channels, that's stereo isn't it(or am i the worst coder at sound?)

and yes ogg decoding could be very heavy, but i've already chosen the low memory and fixed point decoder, so I could not make it less heavier, could i?

eKid
Posts: 65
Joined: Sat Dec 06, 2008 6:07 pm
Contact:

Re: streaming audio

Post by eKid » Fri Jun 26, 2009 6:02 pm

Err yeah, 2 channels = stereo, so in that case it would be more of something like this:

Code: Select all

mm_word on_stream_request( mm_word length, mm_addr dest, mm_stream_formats format ) {

	int filled = 0;
	s16 *target = (s16*)dest;

	while( length >= 1024 ) {
		length -= 1024;
		filled += 1024;
		Update_OGG_Stream( 2, vorbisfile, target );
		target += 2048;
	}
	return filled;
}

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: streaming audio

Post by Tomdev » Fri Jun 26, 2009 6:05 pm

thanks, i'm coding it now. will post the result :P

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: streaming audio

Post by Tomdev » Fri Jun 26, 2009 6:31 pm

ok, it compiled fine, and the begin was good, i heard so yay! :lol: but it keeped repeating, what could be wrong? maybe this:

mystream.buffer_length = 4096; should it be the lengt of the whole OGG file? i don think so or am i wrong

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests