Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: KOS sound streaming

                  
   
  1. #11
    DCEmu Coder GPF's Avatar
    Join Date
    Apr 2004
    Location
    Texas
    Age
    53
    Posts
    796
    Rep Power
    81

    Default Re: KOS sound streaming

    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

  2. #12
    DCEmu Coder GPF's Avatar
    Join Date
    Apr 2004
    Location
    Texas
    Age
    53
    Posts
    796
    Rep Power
    81

    Default Re: KOS sound streaming

    [quote author=GPF link=board=Dev;num=1102054491;start=0#0 date=12/03/04 at 00:14:51]I am currently also trying to figure out how to convert SDL sound to KOS sound streaming but don't know where to start. Is there any examples anywhere? All the kos examples are for sndvorbis and mp3/wav playback.

    My code has the stereo sound in a buffer and then dac sound effects in another buffer, and its using

    SDL_BuildAudioCVT(&acvt, AUDIO_U8, 1, 8000, DEFAULT_FORMAT,DEFAULT_CHANNELS, samplerate)

    and
    SDL_ConvertAudio(&acvt)

    then its mixing the both streams into one

    SDL_MixAudio(sound_buffer+sound_frame_write, dac_data, bpf, SDL_MIX_MAXVOLUME);

    how would I replace this with KOS calls? use multiple channels? Any examples or help is appreciated.

    Thanks,

    Troy[/quote]

    well now that I have the sound streaming working I still need some help figuring out how to get the DAC audio to play correctly its frequency is 8000hz, 1 channel 8 bit sound. How do I set up a filter or start the stream to play this?

    Thanks,
    Troy

  3. #13
    DCEmu Coder GPF's Avatar
    Join Date
    Apr 2004
    Location
    Texas
    Age
    53
    Posts
    796
    Rep Power
    81

    Default Re: KOS sound streaming

    still haven't figured out the DAC sound, but anyway.

    How do I pause the sound or stop so I can restart it later?

    Is there a way to tell where in sound buffer the current position is being played ? so I dont resend the same sound in my callback function

    Thanks,
    Troy

  4. #14
    DCEmu Coder GPF's Avatar
    Join Date
    Apr 2004
    Location
    Texas
    Age
    53
    Posts
    796
    Rep Power
    81

    Default Re: KOS sound streaming

    ok figured it out

    snd_stream_stop(shnd);

    and then

    snd_stream_start(shnd,44100,1);

    to restart it,

    Still need help converting the DAC sound from 8 bit 8000hz mono to 16 bit 44100hz stereo so I can mix it .

    Thanks,
    Troy

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •