More Audio Problems

It’s me again.
Sorry for nagging again with newbie questions, it’s just that I don’t get the audio output.
I have written a small test program that opens the SDL audio device and streams white noise (i.e. random numbers).
Everything I get is silence.

  • The callback gets called (checked that)
  • OpenAudio returns 0 (checked that)
  • OpenAudio returns the desired specs (checked that)
  • My volume controls are ok and my headphone is not broken :slight_smile:

To test if the SDL.dll works, I have also downloaded the game “Rocks 'n Diamonds” and replaced the SDL.dll that came with the game with the SDL.dll that I am linking my program against and can actually get sound output.

Here is a stripped down version of the code:---------------------------------------------------------

#include “SDL.h”
#include <stdio.h>
#include <stdlib.h>

void audio_update( void *userdata, Uint8 *mem, int len )
{
short *buffer = (short *) mem;
int bufsize = len / 2;
for( int i = 0; i < bufsize; ++i ) buffer[i] = rand();
}

int main( int argc, char *argv[] )
{
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO );

SDL_AudioSpec spec, spec2;
spec.freq = 22050;
spec.format = AUDIO_S16SYS;
spec.channels = 1;
spec.samples = 4096;
spec.callback = audio_update;
spec.userdata = 0;

SDL_OpenAudio( &spec, &spec2 );
SDL_PauseAudio( false );
SDL_WaitEvent(0);

SDL_Quit();
}