Code:
#include <dc/sound/stream.h>
int samplerate=44100; /* desired output sample rate */
uint16 sound_buffer[SND_STREAM_BUFFER_MAX] = {0};
uint8 dac_buffer[SND_STREAM_BUFFER_MAX] = {0};
snd_stream_hnd_t shnd;
snd_stream_hnd_t shnd2;
void *audio_callback(snd_stream_hnd_t hnd, int samples_requested, int *samples_returned)
{
sound_update((_u16*)(sound_buffer), samples_requested ); //core stereo sound update funct
*samples_returned = samples_requested;
return sound_buffer;
}
void *dac_audio_callback(snd_stream_hnd_t hnd, int samples_requested, int *samples_returned)
{
dac_update((_u8*)(dac_buffer), samples_requested ); //core dac sound update funct
*samples_returned = samples_requested;
return dac_buffer;
}
void
system_sound_chipreset(void)
{
sound_init(samplerate);
return;
}
BOOL
system_sound_init(void)
{
sound_init(samplerate); //inits core sound
snd_stream_init();
shnd = snd_stream_alloc(*audio_callback, SND_STREAM_BUFFER_MAX);
snd_stream_start(shnd,samplerate, 1);
shnd2 = snd_stream_alloc(*dac_audio_callback, SND_STREAM_BUFFER_MAX);
snd_stream_start(shnd2,8192, 0);
return TRUE;
}
void
system_sound_shutdown(void)
{
snd_stream_stop(shnd);
snd_stream_stop(shnd2);
snd_stream_shutdown();
return;
}
void
system_sound_update(int nframes) //called every VBL
{
snd_stream_poll(shnd);
snd_stream_poll(shnd2);
}
OK this works for me with kos 1.3 svn 165
Don't know if this is the most efficient way, should I have 2 different callback functions ? and poll like this.
THanks,
Troy
Bookmarks