Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 124534 - SDL clicks when outputting stream data
Summary: SDL clicks when outputting stream data
Status: RESOLVED WORKSFORME
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Games (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo Games
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-01 09:48 UTC by Giles Constant
Modified: 2006-03-16 01:31 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giles Constant 2006-03-01 09:48:21 UTC
Ok, firstly, I apollogise if this is my code, although various people have looked at this (including people on the SDL mailing list) and no-one can find fault with it, and it works elsewhere.

The following code produces a nice sine wave sound on my friend's debian system, but makes clicking noises every other buffer swap on all of my gentoo boxes.  I have the following configuration:

(gentoo-sources) kernel 2.6.15
ALSA (tried on VIA inteli8x0 and audigy), with:
  realtime-lsm installed (although i don't believe I'm calling it)
  RTC Timer support enabled
SDL: media-libs/libsdl-1.2.9-r1

Here's the program.  Compile with "gcc sdlsound.c -lSDL". :

#include <SDL/SDL.h>
#include <SDL/SDL_audio.h>

#include <math.h>
#include <string.h>

#define sinf __builtin_sinf
#define printf __builtin_printf
#define exit __builtin_exit
#define M_PI 3.14159265358979323846

#define AUDIO_FREQ 48000

float sine_pos = 0;
float sine_speed = M_PI * 2.0 * 440.0 / (float) AUDIO_FREQ;

void mix(void* data, Uint8* stream, int len)
{
    Uint8* s_ptr;
    Uint8* stream_end = stream + len;

    for (s_ptr = stream; s_ptr < stream_end; s_ptr+= sizeof(Sint16)) {
        *((Sint16*) s_ptr) = (Sint16) (10000.0f * sinf(sine_pos));
        sine_pos += sine_speed;
        if (sine_pos >= 2*M_PI) sine_pos -= 2*M_PI; // Fix FP accuracy.
    }
}

int main(int argc, char* argv[])
{
    SDL_AudioSpec desired;
    SDL_AudioSpec obtained;

    memset(&desired, 0, sizeof(desired));
    memset(&obtained, 0, sizeof(obtained));

    desired.freq = AUDIO_FREQ;
    desired.format = AUDIO_S16SYS;
    desired.channels = 1;
    desired.samples = 16384;
    desired.callback = mix;
    desired.userdata = NULL;

    if (SDL_Init(SDL_INIT_AUDIO)) {
        printf("Couldn't initialise SDL\n"); exit(1);
    }

    if (SDL_OpenAudio(&desired, &obtained) < 0) {
        printf("Failed to open audio: %s\n", SDL_GetError()); exit(1);
    } else if (obtained.format != AUDIO_S16SYS) {
        printf("Failed to open correct audio format\n"); exit(1);
    } else if (obtained.freq != AUDIO_FREQ) {
        printf("Failed to open correct audio format\n"); exit(1);
    }

    SDL_PauseAudio(0);
    SDL_Delay(10000);
    SDL_PauseAudio(1);
    SDL_CloseAudio();

    return 0;
}
Comment 1 Mr. Bones. (RETIRED) gentoo-dev 2006-03-16 00:17:03 UTC
does it work correctly with libsdl-1.2.8-r1 ?
Comment 2 Giles Constant 2006-03-16 01:31:24 UTC
Sorry - should've updated this - it's a bug in the snd-hda-intel driver!  Both my laptop and my work machine have the same chipset.  I now have a creative audigy notebook ZS plugged into the laptop and the problem has gone away.  I was mistaken - I didn't have intel-8x0, it was hda-intel.

Zynaddsubfx (the softsynth) suffered from the same problem with this chipset.