SDL_audio gibt nix aus..



  • Also ums mal zu vereinfachen, ich möchte ein Sägezahnsignal per SDL_audio generieren und ausgeben. das Ganze läuft bei mir in einer Klasse ab.

    Initialisierungen funktionieren reibungslos, aber Ton hab ich keinen (auch mein Lautsprecher ist an ^^)
    Hier ein Auszug meiner Klasse

    cSynth::cSynth ()
    {
    	phonems = NULL;
    	text    = NULL;
    	cntPhonems = 0;
    
        audiodevice             = new SDL_AudioSpec;
        audiodevice->freq        = 44100;
        audiodevice->format      = AUDIO_S16;
        audiodevice->channels    = 1;
        audiodevice->samples     = 512;  // 512 samples per char, 8 chars per buffer
        audiodevice->callback    = cSynth::fillBuffer;
        audiodevice->userdata    = (void *)this;
    
    }
    int cSynth::saw	 	        ()
    {
    
        actpos = 0;
        if (SDL_OpenAudio (audiodevice, NULL) < 0) 
           fprintf(stderr, "Fehler beim Öffnen des Audiooutputs\n");
        SDL_PauseAudio(0);
           if (SDL_GetAudioStatus() == SDL_AUDIO_STOPPED || SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) 
                  fprintf(stderr, "Soundausgabe steht\n");
           else    
                  fprintf(stdout, "Soundausgabe läuft\n");
    
            SDL_Delay(3000);
        SDL_CloseAudio();
    }
    
    void cSynth::fillBuffer (void *userdata, Uint8 *stream, int len)
    {
         cSynth *This = (cSynth *) userdata;
         int i;
         float saw = 0;
         SDL_LockAudio();
         for (i = 0; i < len / 2; i++)
         {
             saw      += 150.0f / (float)This->audiodevice->freq - (int) saw;
    //         fprintf (stdout, "%d - Spiele %d\n", i, (Sint16) ((saw - 0.5) * 0x10000));
             stream[i * 2 ] = (Sint16) ((saw - 0.5) * 0x10000)  ;
         }
         SDL_UnlockAudio();
    }
    

    Die Main schaut dann soo aus

    int main(int argc, char *argv[])
    {
        if (-1 == SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO))
           fprintf(stderr, "Kein init möglich!");
    
        cSynth *synth = new cSynth;
    
        synth->say("Hallo Welt");
    
        system("PAUSE");
    
        delete synth;
        SDL_Quit();
        return EXIT_SUCCESS;
    }
    

    Ist auch alles eingebunden.. Ich bekomme keinen Fehler aber auch keinen Output 😞


Anmelden zum Antworten