stream sound[solved]
Moderator: eKid
Re: streaming audio
The header file contains definitions for the indexes in the sound bank. You need it if you want to load a specific song/sample.
Re: streaming audio
thanks it works now!!!! nice music ![Laughing :lol:](./images/smilies/icon_lol.gif)
![Laughing :lol:](./images/smilies/icon_lol.gif)
Re: streaming audio
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
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?
![Razz :P](./images/smilies/icon_razz.gif)
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?
Re: streaming audio
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.
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.
Re: streaming audio
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:
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?
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,¤t_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;
}
}
}
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?
Re: streaming audio
For a function like that I think something like this should work (expecting 16-bit mono data (2048 samples, 4096 bytes))
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).
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;
}
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).
Re: streaming audio
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?
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?
Re: streaming audio
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;
}
Re: streaming audio
thanks, i'm coding it now. will post the result ![Razz :P](./images/smilies/icon_razz.gif)
![Razz :P](./images/smilies/icon_razz.gif)
Re: streaming audio
ok, it compiled fine, and the begin was good, i heard so yay!
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
![Laughing :lol:](./images/smilies/icon_lol.gif)
mystream.buffer_length = 4096; should it be the lengt of the whole OGG file? i don think so or am i wrong
Who is online
Users browsing this forum: No registered users and 3 guests