Announcement

Collapse
No announcement yet.

compilling tyrquake choppy audio debian

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • compilling tyrquake choppy audio debian

    i have been trying to get tyrquake to work on debian jessie. since the stable release is a bit dated, i tried to compile the latest revision. it works, it is fast,etc. now lets talk about the issue:

    choppy audio. yes, i compiled it with SND_TARGET=sdl and the audio feels like i am playing on a 486, although the framerate is perfect. i suspect this is a buffer issue <http://disenchant.net/git/?p=tyrquake&a=blob&h=0d6e0e558471f82d42f0cc5ed2fec 9e6f387fa51&hb=0ca7766d0fed7e73284b55dd9c6d559c194 4c84e&f=common%2Fsnd_sdl.c> but i have no coding skills to fix it myself.

    i also tried to switch to oss4 over alsa and recompiled it with default settings (default SND_TARGET uses oss), but it plays no sound (dmesg output is osscore: mmap() not possible with currently selected sample format.).

    there is another target called sndio, but that is meant for openbsd iirc.

    alsa-oss plays sound but it is even choppier than sdl.

    the easier path seems to be fixing the sdl sound issue, at the moment. is anyone willing to give me pointers to fix on my own, or even write a patch? opengl engines runs somewhat slow on my laptop, hence my interest on tyrquake.

    thanks in advance.

  • #2
    Have you removed pulse audio completely? Jack is the only sound server that supports realtime kernel BTW.You are running RT right?
    Last edited by bluntz; 05-01-2016, 07:12 PM.
    WARNING
    May be too intense for some viewers.
    Stress Relief Device
    ....BANG HEAD HERE....
    ---------------------------
    .
    .
    .
    .
    .--------------------------

    Comment


    • #3
      i modified the file myself. it works for me, but keep in mind that i barely know what the fuck i'm doing here.

      i changed samples and bits, iirc.

      Code:
      //snd_sdl.c from tyrquake, modified by jordon, who has no idea
      //about what he is doing here.
      /*
      Copyright (C) 1996-1997 Id Software, Inc.
      
      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your option) any later version.
      
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      
      See the GNU General Public License for more details.
      
      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
      */
      
      #include <stdio.h>
      
      #include "SDL.h"
      #include "SDL_audio.h"
      #include "SDL_endian.h"
      
      #include "console.h"
      #include "quakedef.h"
      #include "sdl_common.h"
      #include "sound.h"
      #include "sys.h"
      
      static dma_t the_shm;
      static int snd_inited;
      
      static int desired_speed = 11025;
      static int desired_bits = 16; //8 did not work well, so 16bits it is
      
      /* must not be modified while sound system is running */
      static unsigned sdl_buflen;
      
      /* must only be accessed between SDL_LockAudio() and SDL_UnlockAudio() */
      static unsigned char *sdl_buf;
      static unsigned rpos;
      static unsigned wpos;
      
      /*
       * paint_audio()
       *
       * SDL calls this function from another thread, so any shared variables need
       * access to be serialised in some way. We use SDL_LockAudio() to ensure the
       * SDL thread is locked out before we update the shared buffer or read/write
       * positions.
       */
      static void
      paint_audio(void *unused, Uint8 *stream, int len)
      {
          while (rpos + len > sdl_buflen) {
              memcpy(stream, sdl_buf + rpos, sdl_buflen - rpos);
              stream += sdl_buflen - rpos;
              len -= sdl_buflen - rpos;
              rpos = 0;
          }
          if (len) {
              memcpy(stream, sdl_buf + rpos, len);
              rpos += len;
          }
      }
      
      qboolean
      SNDDMA_Init(void)
      {
          SDL_AudioSpec desired, obtained;
      
          snd_inited = 0;
      
          /* Set up the desired format */
          desired.freq = desired_speed;
          switch (desired_bits) {
          case 8:
              desired.format = AUDIO_U8;
              break;
          case 16:
              if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
                  desired.format = AUDIO_S16MSB;
              else
                  desired.format = AUDIO_S16LSB;
              break;
          default:
              Con_Printf("Unknown number of audio bits: %d\n", desired_bits);
              return false;
          }
          desired.channels = 2;
          desired.samples = 512; /* FIXME ~= rate * _s_mixahead / 2 ? */
          desired.callback = paint_audio;
      
          /* Init the SDL Audio Sub-system */
          Q_SDL_InitOnce();
          if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
              Con_Printf("Couldn't init SDL audio: %s\n", SDL_GetError());
              return false;
          }
      
          /* Open the audio device */
          if (SDL_OpenAudio(&desired, &obtained) < 0) {
              Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError());
              return false;
          }
      
          /* Make sure we can support the audio format */
          switch (obtained.format) {
          case AUDIO_U8:
              /* Supported */
              break;
          case AUDIO_S16LSB:
          case AUDIO_S16MSB:
              if (((obtained.format == AUDIO_S16LSB) &&
                   (SDL_BYTEORDER == SDL_LIL_ENDIAN)) ||
                  ((obtained.format == AUDIO_S16MSB) &&
                   (SDL_BYTEORDER == SDL_BIG_ENDIAN))) {
                  /* Supported */
                  break;
              }
              /* Unsupported, fall through */;
          default:
              /* Not supported -- force SDL to do our bidding */
              SDL_CloseAudio();
              if (SDL_OpenAudio(&desired, NULL) < 0) {
                  Con_Printf("Couldn't open SDL audio: %s\n",
                             SDL_GetError());
                  return 0;
              }
              memcpy(&obtained, &desired, sizeof(desired));
              break;
          }
      
          /* Fill the audio DMA information block */
          shm = &the_shm;
          shm->samplebits = (obtained.format & 0xFF);
          shm->speed = obtained.freq;
          shm->channels = obtained.channels;
          shm->samplepos = 0;
          shm->submission_chunk = 1;
      
          /* Allow enough buffer for ~0.5s of mix ahead */
      //    shm->samples = obtained.samples * obtained.channels * 8;
      //    well uh, a base 2 number seemed to give the best results, so yeah
          shm->samples = 1024; //you can try 2048 if it is still choppy
          sdl_buflen = shm->samples * (shm->samplebits / 8);
      
          shm->buffer = Hunk_AllocName(sdl_buflen, "shm->buffer");
          sdl_buf = Hunk_AllocName(sdl_buflen, "sdl_buf");
      
          memset(shm->buffer, obtained.silence, sdl_buflen);
          memset(sdl_buf, obtained.silence, sdl_buflen);
      
          if (!shm->buffer || !sdl_buf)
              Sys_Error("%s: Failed to allocate buffer for sound!", __func__);
      
          rpos = wpos = 0;
          snd_inited = 1;
      
          /* FIXME - hack because sys_win does this differently */
          snd_blocked = 0;
      
          SDL_PauseAudio(0);
      
          return true;
      }
      
      int
      SNDDMA_GetDMAPos(void)
      {
          if (!snd_inited)
              return 0;
      
          SDL_LockAudio();
          shm->samplepos = rpos / (shm->samplebits / 8);
          SDL_UnlockAudio();
      
          return shm->samplepos;
      }
      
      void
      SNDDMA_Shutdown(void)
      {
          if (snd_inited) {
              SDL_CloseAudio();
              snd_inited = 0;
          }
      }
      
      /*
      ==============
      SNDDMA_Submit
      
      Send sound to device if buffer isn't really the dma buffer
      ===============
      */
      void SNDDMA_Submit(void)
      {
          static unsigned old_paintedtime;
          unsigned len;
      
          if (!snd_inited || snd_blocked)
              return;
      
          SDL_LockAudio();
      
          if (paintedtime < old_paintedtime)
              old_paintedtime = 0;
      
          len = paintedtime - old_paintedtime;
          len *= shm->channels * (shm->samplebits / 8);
          old_paintedtime = paintedtime;
      
          while (wpos + len > sdl_buflen) {
              memcpy(sdl_buf + wpos, shm->buffer + wpos, sdl_buflen - wpos);
              len -= sdl_buflen - wpos;
              wpos = 0;
          }
          if (len) {
              memcpy(sdl_buf + wpos, shm->buffer + wpos, len);
              wpos += len;
          }
      
          SDL_UnlockAudio();
      }
      
      #ifdef _WIN32
      void
      S_BlockSound(void)
      {
          if (!snd_blocked)
              SDL_PauseAudio(1);
          snd_blocked++;
      }
      
      void
      S_UnblockSound(void)
      {
          snd_blocked--;
          if (!snd_blocked)
              SDL_PauseAudio(0);
      }
      #endif
      
      /*
       * shm->buffer is not the real DMA buffer, so no locking needed here
       */
      int SNDDMA_LockBuffer(void) { return 0; }
      void SNDDMA_UnlockBuffer(void) { }

      Comment


      • #4
        Well if you are modding the source then I would suggest you have a look at Quakespasm and just use its method as it works very well. Good luck!
        WARNING
        May be too intense for some viewers.
        Stress Relief Device
        ....BANG HEAD HERE....
        ---------------------------
        .
        .
        .
        .
        .--------------------------

        Comment


        • #5
          i tried getting jackd to work but i could not figure out how to configure it, hence the source code method. thank you for the help though. i also tried to adapt quakespasms snd_sdl.c code to tyrquake but it was too much work, and i figured what i had to edit in the process.

          again, thank you!

          Comment

          Working...
          X