Audio Output

I have been trying to get this going all week without success. Please help
me and stop me going mad!

I have implemmented a buffer which is a 2D array. This has BUFFERSIZE
(currently 20) elements by 4096 (as that is the size of convbuffer). I have
variables holding the posoitions of the audioPointer and the dataPointer. I
have put in the if condition

	if(
           (dataPointer >= BUFFERSIZE/2 && audioPointer < BUFFERSIZE/2)

||
(dataPointer < BUFFERSIZE/2 && audioPointer >=
BUFFERSIZE/2)
)

which basically splits th buffer in two so that it will fill half with data
and then the audio reads that half, then more data is put in and then the
audio reads that. I did this as I found that data was being written too
quickly and as such I was overwriting data before it had been read by the
audio callback. When I run this it appears to be working, by looking at
printf statements. However the sound makes no sense at all.

Could you tell me what I have done wrong. Have I set up the

SDL_AudioSpec fmt;

variable correctly?

fmt.freq = 44100;
fmt.format = AUDIO_S16SYS;
fmt.channels = 2;
fmt.samples = 4096;        
fmt.callback = fill_audio;
fmt.userdata = NULL;

I desperately need to get this running as I am fast running out of time for
my MSc project. This is all that stands in my way of finishing the
practical side.

By the way I don’t understand all of the vorbis stuff myself. The program
used to write a PCM bitstream to stdout. I just want to change that to
output sound to the soundcard.

Thanks,
Paul

<<decoder_example.c>>
-------------- next part --------------
A non-text attachment was scrubbed…
Name: decoder_example.c
Type: application/octet-stream
Size: 13133 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020821/d834570f/attachment.obj

I desperately need to get this running as I am fast running out of time for
my MSc project. This is all that stands in my way of finishing the
practical side.

Do you have to use SDL audio and libvorbis directly?

Using SDL_sound and/org SDL_mixer would simplify this immensely, if the
goal here is just to get sound out of the speakers so you can focus on
other things.

–ryan.

The goal is simply to get sound output. The project is basically to develop
a GUI for this Vorbis. One of my colleagues is trasferring part of the
Vorbis algorithm to hardwaer and we intend to run that with the hardware as
well. First of all though I need to get th e GUI working with the existing
software. My plan was just to use the decoder_example code when the user
hit play. If there is a simper way to get audio output then I would like to
know about it. If not then I need a solution as to why what I had was not
correctly outputting sound.

Thanks
Paul> ----- Original Message -----

From: icculus@icculus.org (Ryan C. Gordon)
To:
Sent: Wednesday, August 21, 2002 8:50 PM
Subject: Re: [SDL] Audio Output

I desperately need to get this running as I am fast running out of time
for

my MSc project. This is all that stands in my way of finishing the
practical side.

Do you have to use SDL audio and libvorbis directly?

Using SDL_sound and/org SDL_mixer would simplify this immensely, if the
goal here is just to get sound out of the speakers so you can focus on
other things.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

The goal is simply to get sound output. The project is basically to develop
a GUI for this Vorbis. One of my colleagues is trasferring part of the
Vorbis algorithm to hardwaer and we intend to run that with the hardware as
well. First of all though I need to get th e GUI working with the existing
software. My plan was just to use the decoder_example code when the user
hit play. If there is a simper way to get audio output then I would like to
know about it. If not then I need a solution as to why what I had was not
correctly outputting sound.

If you need the decoded audio waveform, look at SDL_sound:

 http://icculus.org/SDL_sound/

And the included playsound program that dumps a decoded Ogg file to an
SDL audio callback.

If you don’t need the decoded waveform, and only want to play one Ogg at a
time, SDL_mixer makes this a ten-line-or-less program. :slight_smile:

–ryan.

I have had a look at SDL_sound. I do need the decoded waveform. I am
still lost though so I would really appreciate some pointers. In the code
that I had instead of outputting the pcm data to std out using

    	fwrite(convbuffer,2*vi.channels,bout,outputFile);

I want to output this pcm data to the soundcard.

My understanding is that the pcm data is contained in convbuffer. This is
declared as an array of 4096 elements. I have created a 2D array to act as
a buffer. This is declared as

	ogg_int16_t audioBuffer[BUFFERSIZE][4096];

BUFFERSIZE is #define BUFFERSIZE 20

I have setup a SDL_AudioSpec structure

	SDL_AudioSpec fmt;    //SDL structure definition

For the moment I have set this up as follows

/SDL Play**********/
/* Set 16-bit stereo audio at 44Khz */
fmt.freq = 44100;
fmt.format = AUDIO_S16SYS;
fmt.channels = 2;
fmt.samples = 4096;
fmt.callback = fill_audio;
fmt.userdata = NULL;

//audio_chunk = &convbuffer;
/* Open the audio device and start playing sound! */
if ( SDL_OpenAudio(&fmt, NULL) < 0 ) {
    fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
    //exit(1);
}

/SDL Play**********/

I have two variable acting as pointers on my buffer these are

	int audioPointer=0;

	int dataPointer=BUFFERSIZE/2;

In the decode loop I have th following condition to see whether or not to
decode the next part of the file

	if(
           (dataPointer >= BUFFERSIZE/2 && audioPointer < BUFFERSIZE/2)

||
(dataPointer < BUFFERSIZE/2 && audioPointer >=
BUFFERSIZE/2)
)

I put this in because I found that the buffer was being filled with data too
quickly and that by the time that the audio got read the data had been
overwritten a few times. This caused the file to produce high frequency
noise which didn’t last anywhere near the time of the ogg file.

Instead of writing the pcm data to stdout I do this

/Play Audio*********************/

memcpy(audioBuffer[dataPointer], convbuffer, 1024/sizeof(convbuffer)/);

dataPointer = (dataPointer+1)%BUFFERSIZE;
fprintf(stderr, “Data\n”);
fprintf(stderr, “Frame %ld\n”, (long)(vd.sequence));
//SDL_PauseAudio(0);

/Play Audio*********************/

I have the SDL_PauseAudio(0); at the end of my if condition which contains
the whole of the looped decode part.

My callback function is declared as

/callback function************/

/* The audio function callback takes the following parameters:
stream: A pointer to the audio buffer to be filled
len: The length (in bytes) of the audio buffer
*/

void fill_audio(void *udata, Uint8 *stream, int len)
{

memcpy(stream, audioBuffer[audioPointer], len);
fprintf(stderr, “Audio\n”);
audioPointer = (audioPointer+1)%BUFFERSIZE;
}
/callback function************/

The sound output now appaers to go too slowly and is not recognisable as the
ogg file.

Any help would be really appreciated.

I have included the code as an attachment

The ogg file I am using is 841kb in size so if anybody wants that I can send
that to them

Thanks in advance,
Paul> ----- Original Message -----

From: Ryan C. Gordon [mailto:icculus@icculus.org]
Sent: 22 August 2002 10:29
To: sdl at libsdl.org
Subject: Re: [SDL] Audio Output

The goal is simply to get sound output. The project is basically to
develop
a GUI for this Vorbis. One of my colleagues is trasferring part of the
Vorbis algorithm to hardwaer and we intend to run that with the hardware
as
well. First of all though I need to get th e GUI working with the
existing
software. My plan was just to use the decoder_example code when the user
hit play. If there is a simper way to get audio output then I would like
to
know about it. If not then I need a solution as to why what I had was not
correctly outputting sound.

If you need the decoded audio waveform, look at SDL_sound:

 http://icculus.org/SDL_sound/

And the included playsound program that dumps a decoded Ogg file to an
SDL audio callback.

If you don’t need the decoded waveform, and only want to play one Ogg at a
time, SDL_mixer makes this a ten-line-or-less program. :slight_smile:

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-------------- next part --------------
A non-text attachment was scrubbed…
Name: decoder_example.c
Type: application/octet-stream
Size: 13133 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020822/2199b138/attachment.obj

El Thu, 22 Aug 2002 11:51:28 +0100
Paul Newton <Paul.Newton at sli-institute.ac.uk> escribi?:

/callback function************/

/* The audio function callback takes the following parameters:
stream: A pointer to the audio buffer to be filled
len: The length (in bytes) of the audio buffer
*/

void fill_audio(void *udata, Uint8 *stream, int len)
{

memcpy(stream, audioBuffer[audioPointer], len);
fprintf(stderr, “Audio\n”);
audioPointer = (audioPointer+1)%BUFFERSIZE;
}
/callback function************/

I think this callback function will cause you some trouble… :slight_smile:

Lets take an ogg file you want to play. On first approach, the whole process
is: read file, decode file, send decoded audio to soundcard.

With SDL, things are slightly more complex, as SDL is designed for more complex
applications. SDL uses a different, separate thread to feed the soundcard with
new data when needed.

So the approach now is: read file, decode file, feed data to the soundcard as
neeeded.

Or, taking into account the thread scheme: thread-1: read a chunk of file,
decode chunk, repeat; thread-2: send data to the soundcard, wait until more
data is needed, repeat.

Lets take the thread-2 loop. Your callback is called when more data is needed.
To avoid pops and clicks, the callback is called before the audio buffer is
completely played back; the exact amount of data required varies from call to
call depending of how much data remains in the audio buffer (thus the 'len’
parameter).

Now you surely understand what’s bad on your callback: on each call to
fill_audio, you send a portion of a buffer (of size ‘len’) and skip a full
buffer (of size 4096) so there’s a block of data (of size 4096 - len) that is
never played.

You can try this approach as a start-up (not tested):

#define BLOCK_SIZE 4096

void fill_audio(void *udata, Uint8 *stream, int len)
{
static int already_sent = 0;
int first_chunk = len % (BLOCK_SIZE - already_sent);
int second_chunk = len - first_chunk;
if (first_chunk > 0)
memcpy(stream, audioBuffer[audioPointer]+already_sent, first_chunk);
if (second_chunk > 0)
{
audioPointer = (audioPointer+1)%BUFFERSIZE;
memcpy(stream + first_chunk, audiobuffer[audioPointer], second_chunk);
already_sent = second_chunk;
}
else
already_sent += first_chunk;
fprintf(stderr, “Audio\n”);
}

Hope this help anyway.

Regards,
Wizord.

Now you surely understand what’s bad on your callback: on each call to
fill_audio, you send a portion of a buffer (of size ‘len’) and skip a full
buffer (of size 4096) so there’s a block of data (of size 4096 - len) that is
never played.

There’s actually a lot wrong with the program. I tried to pinpoint the
problem and found five or six serious bugs right off the bat.

  • The array of arrays should take a hike. Use a single ring buffer of 16k
    or more.

  • You open the audio device before you know what format your data will be.

  • You assume that 4096 samples == 4096 bytes to be written in the
    callback (it isn’t), so you’re throwing away half of your data.

  • You are writing a trash buffer on the first call to the audio callback,
    since the ogg decoder is filling in the second half of the buffer while
    the audio callback is reading the first, uninitialized arrays.

  • you’re praying that the audio callback and the decoder stay in sync with
    a large enough buffer, but both need to do checks: one to see whether
    there is data to be read, and the other to see if there’s room for data to
    be written. In the decoder’s case, it needs to wait until there’s more
    room. In the audio callback’s case, it needs to write silence and give up.

  • You don’t call SDL_LockAudio() before updating those buffers.

Do yourself a favor and get SDL_sound, and look at what playsound.c
does…it’s almost exactly what you want to do, and it hides the
complexity of decoding an ogg file.

–ryan.

Now you surely understand what’s bad on your callback: on each call to
fill_audio, you send a portion of a buffer (of size ‘len’) and skip a full
buffer (of size 4096) so there’s a block of data (of size 4096 - len) that
is
never played.

There’s actually a lot wrong with the program. I tried to pinpoint the
problem and found five or six serious bugs right off the bat.

  • The array of arrays should take a hike. Use a single ring buffer of 16k
    or more.

OK so I set it to

#define BUFFERSIZE 16384

audioBuffer[BUFFERSIZE];

  • You open the audio device before you know what format your data will be.

Ok will sort that

  • You assume that 4096 samples == 4096 bytes to be written in the
    callback (it isn’t), so you’re throwing away half of your data.

Yeah sussed that after I had sent the email

  • You are writing a trash buffer on the first call to the audio callback,
    since the ogg decoder is filling in the second half of the buffer while
    the audio callback is reading the first, uninitialized arrays.

I was aware of this

  • you’re praying that the audio callback and the decoder stay in sync with
    a large enough buffer, but both need to do checks: one to see whether
    there is data to be read, and the other to see if there’s room for data to
    be written. In the decoder’s case, it needs to wait until there’s more
    room. In the audio callback’s case, it needs to write silence and give up.

How do I best go about checking this with the new rolling buffer.

I did this after I sent the email yesterday and got something that resembled
music, although I know that the code isn’t really useful for what I want to
do.

unsigned int Buffer[44100];
unsigned int * bufferPointer;
unsigned int count=0;

  memcpy(bufferPointer, convbuffer, 4*bout);
  fprintf(pointers, "BufferPointer = %d\n", count);
  fprintf(pointers, "Data\n");
  bufferPointer+=bout;
  count+=bout;
  if(count>44100)
  {
   bufferFlag=1;
     SDL_PauseAudio(0);
   bufferPointer=0;
   bufferPointer = Buffer;
   count=0;
  }
  • You don’t call SDL_LockAudio() before updating those buffers.

Will add this

Do yourself a favor and get SDL_sound, and look at what playsound.c
does…it’s almost exactly what you want to do, and it hides the
complexity of decoding an ogg file.

I had a look at this but am not sure the best way to use this. I need to
decode the Ogg file by myself as the calls it will be making to the Vorbis
files is necessary as the other person in the project is modifying these and
I need to go to his updated libraries.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

----- Original Message -----
From: Ryan C. Gordon [mailto:icculus@icculus.org]
Sent: 22 August 2002 18:52
To: sdl at libsdl.org
Subject: Re: [SDL] Audio Output

unsigned int Buffer[44100];

This comes back to what I said about not knowing the format ahead of time.
The ogg I tried was 22050 samples per second.

Pseudo code:

while (still decoding ogg)
{
amountToAddToBuf = how much you can decode in one shot
SDL_LockAudio();
n = how much room is left in ring buffer
if (n < amountToAddToBuf)
amountToAddToBuf = n;

  if (n == 0)
  {
      SDL_UnlockAudio();
      SDL_Delay(100);  /* sleep awhile so playback can catch up. */
  }
  else
  {
      decodeIntoBuffer(); /* fill in ring buffer with some data. */
      SDL_UnlockAudio();
  }

}

… remember the ring buffer wraps around, and does not necessarily
start at position zero. Since your decoding loop will run a lot more than
the audio callback (at least, until it fills up the buffer and starts
sleeping), you could cheat and copy to the end of the buffer and start at
position zero for the next iteration.

The audio callback:

callback(uint8 *stream, int len, void *blah)
{
x = amount of data in the buffer at this moment;
if (len < x)
x = len;

   // deal with ring buffer wraparound here! I'm not going to.
  memcpy(stream, position in ring buffer, x);
  len -= x;

  // update start position of ring buffer and how much is left in it.
  updateBufferToReflectThatWeUsedSome();

  // do we need more data than is available?!
  if (len)
      memset(stream + x, '\0', len);  // write silence.

}

In there, you need to deal with ring buffer wraparound. Also "silence"
isn’t always zero, but it’ll do for now.

Have the appropriate amount of fun.

–ryan.

I have had a go at this but still without success. I know get audio output
that resembles music but it still isn’t right.

My full code is attached

It only sounds like music when my callback function look slike this

void fill_audio(void *udata, Uint8 *stream, int len)
{
int x=0;
fprintf(stderr, “Audio\n\n\n\n\n\n\n\n\n\n\n\n”);
fprintf(stderr, “len = %d\n”, len);
x = dataPointer;
if(len > x)
x = len;

memcpy(stream, audioBuffer, x);
len -= x;
//fprintf(stderr, “len = %d\n”, len);
//audioPointer = (audioPointer + x) % BUFFERSIZE;

if(len)
memset(stream + x, ‘\0’, len); //write silence

flag=0;
}

This is not what you advised you had

if(len < x)

When I have this then I just get a clicking noise

The flag variable is so that the decoder would stop decoding so that the
audio would catch up. I tried SDL Delay but the structure of the vorbis
decoder didn’t seem to suit this.

Finally my code for dealing with the ring buffer wrap around seems messy. I
tried the cheat that you suggested but it won’t catch any overflow on the
last iteration (I don’t think). I hope that I am getting close but some
more advice would be greatly appreciated.

I know that I am setting up my SDL_AudioSpec before I know the format. I
will sort this later. At the moment I do know the format of the one file I
am testing this on.

Thanks,
Paul> ----- Original Message -----

From: Ryan C. Gordon [mailto:icculus@icculus.org]
Sent: 23 August 2002 15:17
To: sdl at libsdl.org
Subject: RE: [SDL] Audio Output

unsigned int Buffer[44100];

This comes back to what I said about not knowing the format ahead of time.
The ogg I tried was 22050 samples per second.

Pseudo code:

while (still decoding ogg)
{
amountToAddToBuf = how much you can decode in one shot
SDL_LockAudio();
n = how much room is left in ring buffer
if (n < amountToAddToBuf)
amountToAddToBuf = n;

  if (n == 0)
  {
      SDL_UnlockAudio();
      SDL_Delay(100);  /* sleep awhile so playback can catch up. */
  }
  else
  {
      decodeIntoBuffer(); /* fill in ring buffer with some data. */
      SDL_UnlockAudio();
  }

}

… remember the ring buffer wraps around, and does not necessarily
start at position zero. Since your decoding loop will run a lot more than
the audio callback (at least, until it fills up the buffer and starts
sleeping), you could cheat and copy to the end of the buffer and start at
position zero for the next iteration.

The audio callback:

callback(uint8 *stream, int len, void *blah)
{
x = amount of data in the buffer at this moment;
if (len < x)
x = len;

   // deal with ring buffer wraparound here! I'm not going to.
  memcpy(stream, position in ring buffer, x);
  len -= x;

  // update start position of ring buffer and how much is left in it.
  updateBufferToReflectThatWeUsedSome();

  // do we need more data than is available?!
  if (len)
      memset(stream + x, '\0', len);  // write silence.

}

In there, you need to deal with ring buffer wraparound. Also "silence"
isn’t always zero, but it’ll do for now.

Have the appropriate amount of fun.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-------------- next part --------------
A non-text attachment was scrubbed…
Name: decoder_example.c
Type: application/octet-stream
Size: 14920 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020826/c90329ba/attachment.obj

Further to my last post. I have changed the code and now get a reasonable
output. However there is a regular clicking noise present.

How can I fix this.

I am not entiely sure that my buffer control is correct but the music now
plays back, sounding like it sjould, in the time it should. Only problem is
this clicking

Thanks,
Paul> ----- Original Message -----

From: Ryan C. Gordon [mailto:icculus@icculus.org]
Sent: 23 August 2002 15:17
To: sdl at libsdl.org
Subject: RE: [SDL] Audio Output

unsigned int Buffer[44100];

This comes back to what I said about not knowing the format ahead of time.
The ogg I tried was 22050 samples per second.

Pseudo code:

while (still decoding ogg)
{
amountToAddToBuf = how much you can decode in one shot
SDL_LockAudio();
n = how much room is left in ring buffer
if (n < amountToAddToBuf)
amountToAddToBuf = n;

  if (n == 0)
  {
      SDL_UnlockAudio();
      SDL_Delay(100);  /* sleep awhile so playback can catch up. */
  }
  else
  {
      decodeIntoBuffer(); /* fill in ring buffer with some data. */
      SDL_UnlockAudio();
  }

}

… remember the ring buffer wraps around, and does not necessarily
start at position zero. Since your decoding loop will run a lot more than
the audio callback (at least, until it fills up the buffer and starts
sleeping), you could cheat and copy to the end of the buffer and start at
position zero for the next iteration.

The audio callback:

callback(uint8 *stream, int len, void *blah)
{
x = amount of data in the buffer at this moment;
if (len < x)
x = len;

   // deal with ring buffer wraparound here! I'm not going to.
  memcpy(stream, position in ring buffer, x);
  len -= x;

  // update start position of ring buffer and how much is left in it.
  updateBufferToReflectThatWeUsedSome();

  // do we need more data than is available?!
  if (len)
      memset(stream + x, '\0', len);  // write silence.

}

In there, you need to deal with ring buffer wraparound. Also "silence"
isn’t always zero, but it’ll do for now.

Have the appropriate amount of fun.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-------------- next part --------------
A non-text attachment was scrubbed…
Name: decoder_example.c
Type: application/octet-stream
Size: 15246 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020827/10244ce5/attachment.obj

Haven’t followed this thread closely, but here are some ideas:

  • Is the clicking frequency affected if you change the size
    of the SDL audio buffer, the intermediate buffer or other
    buffers, if any?

  • Is the size of the intermediate buffer (the one that the
    callback reads from) guaranteed to be a multiple of the
    buffer size argument of the callback? (Hint: You probably
    shouldn’t assume anything about that argument - not even
    that it will be constant between calls! If nothing else,
    not making such assumptions gives your code a much better
    chance to work with other callback designs, such as VST,
    LADSPA or JACK plugins.)

  • Is there some processing going on that loses it’s state
    regularly? (Like once per intermediate buffer wrap, or
    something…)

  • What happens in the callback/streaming sync when buffers
    wrap, are swapped, or whatever you do?

//David

.---------------------------------------
| David Olofson
| Programmer

david.olofson at reologica.se
Address:
REOLOGICA Instruments AB
Scheelev?gen 30
223 63 LUND
Sweden
---------------------------------------
Phone: 046-12 77 60
Fax: 046-12 50 57
Mobil:
E-mail: david.olofson at reologica.se
WWW: http://www.reologica.se

`-----> We Make Rheology RealOn Tue, 27/08/2002 12:01:05 , Paul Newton <Paul.Newton at sli-institute.ac.uk> wrote:

Further to my last post. I have changed the code and now get a reasonable
output. However there is a regular clicking noise present.

Further to my last post. I have changed the code and now get a reasonable
output. However there is a regular clicking noise present.

Haven’t followed this thread closely, but here are some ideas:

  • Is the clicking frequency affected if you change the size
    of the SDL audio buffer, the intermediate buffer or other
    buffers, if any?

If I change the buffer then the audio plays back at the wrong speed. If I
increase the buffer it plays too fast. The clicking isn’t too bad then. If
I reduce the buffer the sound plays back too slow and the clcicking is
really bad.

  • Is the size of the intermediate buffer (the one that the
    callback reads from) guaranteed to be a multiple of the
    buffer size argument of the callback? (Hint: You probably
    shouldn’t assume anything about that argument - not even
    that it will be constant between calls! If nothing else,
    not making such assumptions gives your code a much better
    chance to work with other callback designs, such as VST,
    LADSPA or JACK plugins.)

No

  • Is there some processing going on that loses it’s state
    regularly? (Like once per intermediate buffer wrap, or
    something…)

No

  • What happens in the callback/streaming sync when buffers
    wrap, are swapped, or whatever you do?

The way that I set up the bufffer was as a ring buffer. However I set a
flag when the buffer is full so no more processing takes place. The audio
then runs. I think that after this empties the buffer as it does the
clicking is the time that it takes to refill the buffer before more audio
can be output. I am currently working on getting the buffer to wrap
properly but without a lot of success at the moment.

Paul

//David

.---------------------------------------
| David Olofson
| Programmer

david.olofson at reologica.se
Address:
REOLOGICA Instruments AB
Scheelev?gen 30
223 63 LUND
Sweden
---------------------------------------
Phone: 046-12 77 60
Fax: 046-12 50 57
Mobil:
E-mail: david.olofson at reologica.se
WWW: http://www.reologica.se

`-----> We Make Rheology Real


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

----- Original Message -----
From: David Olofson [mailto:david.olofson@reologica.se]
Sent: 27 August 2002 15:12
To: sdl at libsdl.org
Subject: RE: [SDL] Audio Output
On Tue, 27/08/2002 12:01:05 , Paul Newton <Paul.Newton at sli-institute.ac.uk> wrote:

This is not what you advised you had

if(len < x)

…and that’s what you should do. Otherwise you will memcpy() past the end
of your ring buffer.

This is not a matter of incremental fixes and band-aids until it sounds
right. You need to do this all the way instead of tweaking little pieces
and hoping it magically works, because it won’t.

–ryan.

This is not what you advised you had

if(len < x)

…and that’s what you should do. Otherwise you will memcpy() past the end
of your ring buffer.

This is not a matter of incremental fixes and band-aids until it sounds
right. You need to do this all the way instead of tweaking little pieces
and hoping it magically works, because it won’t.

As I said when I had what you suggested I just got a clicking noise. I did
a printf right at the start of the call back to find out the size of len.
It was 41102. That is why I changed it and I do get music output, except
for the annoying clicking noise.

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

----- Original Message -----
From: icculus@icculus.org (Ryan C. Gordon)
To:
Sent: Tuesday, August 27, 2002 10:44 PM
Subject: RE: [SDL] Audio Output

OK I have changed my buffers but am back to the clicking sound output again.

Could somebody have a look at the code and see what is wrong with it.

Thanks,
Paul> ----- Original Message -----

From: Paul Newton [mailto:@Paul_Newton]
Sent: 28 August 2002 09:12
To: sdl at libsdl.org
Subject: Re: [SDL] Audio Output

----- Original Message -----
From: icculus@icculus.org (Ryan C. Gordon)
To:
Sent: Tuesday, August 27, 2002 10:44 PM
Subject: RE: [SDL] Audio Output

This is not what you advised you had

if(len < x)

…and that’s what you should do. Otherwise you will memcpy() past the end
of your ring buffer.

This is not a matter of incremental fixes and band-aids until it sounds
right. You need to do this all the way instead of tweaking little pieces
and hoping it magically works, because it won’t.

As I said when I had what you suggested I just got a clicking noise. I did
a printf right at the start of the call back to find out the size of len.
It was 41102. That is why I changed it and I do get music output, except
for the annoying clicking noise.

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-------------- next part --------------
A non-text attachment was scrubbed…
Name: decoder_example.c
Type: application/octet-stream
Size: 16248 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020829/c09d992f/attachment.obj