Writing decoded audio to stdout

Kevin Nowaczyk beakerboy99 at yahoo.com
Tue Feb 8 22:35:34 EST 2005


I have a working application which decodes ogg and mp3
files and plays them.  I'd like to add the option of
writing the audio to stdout in other to link in other
software through a pipe.  

I can succesfully use:
Sound_Sample* sample = Sound_NewSampleFromFile
(p.string ().c_str (), NULL, decode_buffersize); 

What do I need to do to this sample to make it work
with the Sound_Decode() function.  Here's what I have
currently.  It's a cut-up version of the working SDL
implementation.  I took the code from the callback and
moved it into the play funtion.  It looks like I may
need to know how to cut my sample up into smaller
pieces like SDL_AudioSpec userdata.  ANy help would be
greatly appreciated.

void AudioPlayer::play (fs::path p)
{
    Uint32 audio_buffersize = DEFAULT_AUDIOBUF;
    Uint32 decode_buffersize = DEFAULT_DECODEBUF;

    Sound_Sample *sample;

    sample = Sound_NewSampleFromFile (p.string
().c_str (), NULL, decode_buffersize);

    if (!sample)
      {
        fprintf(stderr, "Couldn't load \"%s\"!\n"
                        "  reason: [%s].\n",
p.string().c_str(), Sound_GetError());
        return;
      }

    if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
      {
        fprintf(stderr, "Error in decoding sound
file!\n"
                        "  reason: [%s].\n",
Sound_GetError());
      }

    int bw = 0;
    Uint8 stream1[decode_buffersize];
    while (bw < decode_buffersize)
      {
        int cpysize;
        if (!read_more_data(sample))
          {
            memset(stream1 + bw, '\0',
decode_buffersize - bw);
            done_flag = 1;
            return;
          }
        cpysize = decode_buffersize - bw;
        if (cpysize > deco1G1Gded_bytes)
            cpysize = decoded_bytes;

        if (cpysize > 0)
          {
            memcpy(stream1 + bw , decoded_ptr,
cpysize);
            bw += cpysize;
            decoded_ptr += cpysize;
            decoded_bytes -= cpysize;
          }
      }
i//    printf ("%s", stream1);
    std::cout << stream1;
    Sound_FreeSample(sample);
}



		
__________________________________ 
Do you Yahoo!? 
All your favorites on one personal page – Try My Yahoo!
http://my.yahoo.com 



More information about the sdlsound mailing list