Linux/FreeBSD/Mac OS X etc sound

Found a bug? Please report it, but remember to follow the bug reporting guidelines.
Missing a sane feature? Let us know!
But please do NOT request ports to other systems.

Moderator: ZSNES Mods

Best audio API

SDL
10
20%
AO
10
20%
OpenAL
14
29%
Semi Portable OSS
6
12%
Non Portable ALSA
5
10%
Non Portable CoreAudio
1
2%
Other
3
6%
 
Total votes: 49

Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

I need to add that changing samplerate while running zsnes will require a restart for the device to get set... sounds like an easy fix tho...
Nach
ZSNES Developer
ZSNES Developer
Posts: 3903
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

Spike wrote:I got it working on my emu10k1.

I didn't :(

Spike wrote: if (ioctl(fdAudio, SNDCTL_DSP_SETFRAGMENT, "32") == -1)
fprintf(stderr, "Could not set PCM format on device.\n");

fragment size should be set to something sensible...

if (ioctl(fdAudio, SNDCTL_DSP_SPEED, &oss_samplerate) == -1)
fprintf(stderr, "Could not set PCM format on device.\n");

and of course set the samplerate!

That makes it better for me, but it still sounds terrible.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

Code: Select all

    printf("Sample: %d\n", oss_samplerate);

        if (!AudioOpen)         

        if ((fdAudio = open("/dev/dsp",  O_WRONLY, 0)) == -1)
        fprintf(stderr, "Error opening /dev/dsp\n");

        if (ioctl(fdAudio, SNDCTL_DSP_SETFMT, &oss_format) == -1)
        fprintf(stderr, "Could not set DSP SETFMT on device.\n");

        AudioOpen = 1;

        ioctl(fdAudio, SNDCTL_DSP_RESET, 0);

        if (ioctl(fdAudio, SNDCTL_DSP_SETFRAGMENT, "32") == -1)
        fprintf(stderr, "Could not set DSP FRAGMENT format on device.\n");

        if (ioctl(fdAudio, SNDCTL_DSP_SPEED, &oss_samplerate) == -1)
        fprintf(stderr, "Could not set DSP SPEED on device.\n");

        if (ioctl(fdAudio, SNDCTL_DSP_CHANNELS, &oss_channels) == -1)
        fprintf(stderr, "Could not set DSP CHANNELS on device.\n");

        if (ioctl(fdAudio, SNDCTL_DSP_SYNC, 0) == -1)
        fprintf(stderr, "Could not set DSP SYNC on device.\n");

        if (ioctl (fdAudio, SNDCTL_DSP_NONBLOCK, &blah) < 0)
        fprintf(stderr, "Could not set DSP NONBLOCK on device.\n");

  ntschi = SAMPLE_NTSC_HI_SCALE*oss_samplerate;



Fixes that issue... samplerate changes when i command it to now

Nach wrote:
Spike wrote:I got it working on my emu10k1.

I didn't :(

Spike wrote: if (ioctl(fdAudio, SNDCTL_DSP_SETFRAGMENT, "32") == -1)
fprintf(stderr, "Could not set PCM format on device.\n");

fragment size should be set to something sensible...

if (ioctl(fdAudio, SNDCTL_DSP_SPEED, &oss_samplerate) == -1)
fprintf(stderr, "Could not set PCM format on device.\n");

and of course set the samplerate!

That makes it better for me, but it still sounds terrible.


Which soundchip do you have? Seems not all soundchips respond to OSS commands as properly as others. So this may work some cards, but not others. :(

Just needs more work.

EDIT: emu10k1, nm... odd
Difference may be in using plain OSS drivers and that ALSA OSS junk.... :|
They seem to not comply too well with OSS standards...

I'm wondering if that SNDCTL_DSP_SYNC is really useful...

damnit, SETFMT shouldnt be set more then once...

Code: Select all

        if (!AudioOpen)          

        if ((fdAudio = open("/dev/dsp",  O_WRONLY, 0)) == -1)
        fprintf(stderr, "Error opening /dev/dsp\n");

        if (!AudioOpen)

        if (ioctl(fdAudio, SNDCTL_DSP_SETFMT, &oss_format) == -1)
        fprintf(stderr, "Could not set DSP SETFMT on device.\n");

        AudioOpen = 1;


Yes, laugh at me, i'm just learning still. :P

Meh, best way to do this would be to reset then close, then reopen the device, and then set the parameters.
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

Alright....

Code: Select all

    printf("Sample: %d\n", oss_samplerate);

        if (fdAudio)
        {
                ioctl(fdAudio, SNDCTL_DSP_RESET, 0);
                close(fdAudio);
        }

        if ((fdAudio = open("/dev/dsp",  O_WRONLY, 0)) == -1)
        fprintf(stderr, "Error opening /dev/dsp\n");

        if (ioctl(fdAudio, SNDCTL_DSP_SETFMT, &oss_format) == -1)
        fprintf(stderr, "Could not set DSP SETFMT on device.\n");

        if (ioctl(fdAudio, SNDCTL_DSP_SETFRAGMENT, "32") == -1)
        fprintf(stderr, "Could not set DSP FRAGMENT on device.\n");

        if (ioctl(fdAudio, SNDCTL_DSP_SPEED, &oss_samplerate) == -1)
        fprintf(stderr, "Could not set DSP SPEED on device.\n");

        if (ioctl(fdAudio, SNDCTL_DSP_CHANNELS, &oss_channels) == -1)
        fprintf(stderr, "Could not set DSP CHANNELS on device.\n");

        if (ioctl(fdAudio, SNDCTL_DSP_SYNC, &blah) == -1)
        fprintf(stderr, "Could not set DSP SYNC on device.\n");

        if (ioctl (fdAudio, SNDCTL_DSP_NONBLOCK, &blah) < 0)
        fprintf(stderr, "Could not set DSP NONBLOCK on device.\n");

  ntschi = SAMPLE_NTSC_HI_SCALE*oss_samplerate;



I know it works for me, I just wish I had some more lesser crappy soundcard to do further testing with. I know OSS a small bit, as I been hacking around the OSS code for Audacious media player alot lately figuring out what what does and managed to get real gapless playback going as well.
Nach
ZSNES Developer
ZSNES Developer
Posts: 3903
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

Spike wrote:EDIT: emu10k1, nm... odd
Difference may be in using plain OSS drivers and that ALSA OSS junk.... :|
They seem to not comply too well with OSS standards...

I do use OSS.

BTW thanks for your help, using your suggestions, I got it working perfectly for me :D

Code: Select all

int fdAudio = 0;
int oss_format = AFMT_S16_LE;
int InitSound(void)
{
  const int freqtab[7] = { 8000, 11025, 22050, 44100, 16000, 32000, 48000 };
  int oss_channels = 2;
  int oss_samplerate = freqtab[SoundQuality];
  int blah = 1;


  printf("Sample: %d\n", oss_samplerate);

  if (fdAudio)
  {
    ioctl(fdAudio, SNDCTL_DSP_RESET, 0);
    close(fdAudio);
  }

  if ((fdAudio = open("/dev/dsp",  O_WRONLY, 0)) == -1)
  fprintf(stderr, "Error opening /dev/dsp\n");

  if (ioctl(fdAudio, SNDCTL_DSP_SETFMT, &oss_format) == -1)
  fprintf(stderr, "Could not set DSP SETFMT on device.\n");

  if (ioctl(fdAudio, SNDCTL_DSP_SETFRAGMENT, "32") == -1)
  fprintf(stderr, "Could not set DSP FRAGMENT on device.\n");

  if (ioctl(fdAudio, SNDCTL_DSP_SPEED, &oss_samplerate) == -1)
  fprintf(stderr, "Could not set DSP SPEED on device.\n");

  if (ioctl(fdAudio, SNDCTL_DSP_CHANNELS, &oss_channels) == -1)
  fprintf(stderr, "Could not set DSP CHANNELS on device.\n");

  if (ioctl(fdAudio, SNDCTL_DSP_SYNC, &blah) == -1)
  fprintf(stderr, "Could not set DSP SYNC on device.\n");

  if (ioctl (fdAudio, SNDCTL_DSP_NONBLOCK, &blah) < 0)
  fprintf(stderr, "Could not set DSP NONBLOCK on device.\n");

  ntschi = SAMPLE_NTSC_HI_SCALE*oss_samplerate;
  ntsclo = SAMPLE_NTSC_LO;
  ntscbalance = ntschi;

  if (!SoundEnabled)
  {
      return FALSE;
  }

  PrevSoundQuality = SoundQuality;
  PrevStereoSound = StereoSound;

  if (SoundQuality > 6)
      SoundQuality = 1;

    return TRUE;
}

No more crackling or popping during ToP :D

Although I notice the emulators slows down at some parts where it can't get the audio out.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

Yup, I'm almost sure thats related to the 100% cpu gremlin I was talking about.

I'm not sure if its related to the OSS code or something recently changed in CVS however. As it only happens during emulation, and the OSS stuff happens upon load, where the issue isnt existant.

Glad it worked for you however!
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

AND YES, NO MORE DARN CRACKLING! :D
pagefault
ZSNES Developer
ZSNES Developer
Posts: 812
Joined: Tue Aug 17, 2004 5:24 am
Location: In your garden

Post by pagefault »

Ah nice, I get back and everything is done :P

Thanks for your help :)

These changes work very well so far for everyone who has tested them. I guess what is left is to add support for PAL roms and probably do ALSA support. Also I guess I have to implement the ReInitSound function so you don't have to keep restarting the client.

The CPU usage is a result of removal of the semaphore code, it will go back in again. I just took it out for debugging.
Nach
ZSNES Developer
ZSNES Developer
Posts: 3903
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

http://nsrt.edgeemu.com/sdllink.c

Now supports all rates, PAL, and mono sound too.
Sound reinit seems to work good too :D

I also cleaned up some of the code and made it get the audio out faster, no more slow downs for me :)
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

Looking great, and sounds great too.

Minor issue of disable sound tickbox not working yet though, for the picky.

Not that I ever use the disable sound feature. :-)

EDIT: nm, dont seem like the code there to look from cfgsoundon exists yet. WIP!

Heh, I tried but seems how it is if I even change SoundEnabled=1 to 0, i get the dreaded FP exception.

I did manage to get the actual config part read however, but that only needs an extern BYTE variable for cfgsoundon set and a way for it to reassign SoundEnabled.

Oh well, FP exceptions are a little over my head at this point in time.
Nach
ZSNES Developer
ZSNES Developer
Posts: 3903
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

I know the problem, I'll fix it later, basically just need to skip sound output if sound is off.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

Nach wrote:I know the problem, I'll fix it later, basically just need to skip sound output if sound is off.


You the man!

Cheers.
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

Finally Super Mario World no longer sounds like SH*T!
pagefault
ZSNES Developer
ZSNES Developer
Posts: 812
Joined: Tue Aug 17, 2004 5:24 am
Location: In your garden

Post by pagefault »

Updates:

No longer uses 100% CPU
Now syncs video to audio.
Checks to see if your card supports reporting the sound output delay.
Minor code cleanups.

http://zsnes.game-host.org/~pagefault/sdllink.c

Update #2

http://zsnes.game-host.org/~pagefault/synctest.c

Try this as well, this does a lot better job syncing the sound but also uses more CPU. May be an option later on.
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

Testing them now, heh.

First one works great, second one hangs at 100% cpu at the start of emulation.
Nach
ZSNES Developer
ZSNES Developer
Posts: 3903
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

First one is still desynced for me, and seems to have slower fast foward.

Second is synced but brings it all to a crawl, and fast foward is just dead.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
pagefault
ZSNES Developer
ZSNES Developer
Posts: 812
Joined: Tue Aug 17, 2004 5:24 am
Location: In your garden

Post by pagefault »

The high CPU usage is normal for the second one. It tries to sync as accurately as possible while the first one does an "alright" job syncing. There will probably be an option for the more aggressive syncing later on for people who want it, although it shouldn't lock up your system. I will check into that.
Spike
Rookie
Posts: 21
Joined: Mon Oct 10, 2005 12:02 pm

Post by Spike »

It doesn't lockup my system at all, but zsnes becomes frozen in a 100% cpu coma until I killall -9 it.
dexter

Post by dexter »

Hello

What must we do with the file sdllink.c ? how install it ?

Thanks !

PS : Excuse my english !

I'm on Ubuntu dapper with Zsnes ver. 1.420-0.1ubuntu1 (also 1.42)
Max_Fire
New Member
Posts: 4
Joined: Thu Mar 30, 2006 10:20 pm

Post by Max_Fire »

I am using the ZSNESW_0329 and perceived that he has a problem in the audio, some type of noise intermittent in back sound. I have a Audigy ZS2.
Jipcy
Veteran
Posts: 768
Joined: Thu Feb 03, 2005 8:18 pm
Contact:

Post by Jipcy »

Max_Fire wrote:I am using the ZSNESW_0329 and perceived that he has a problem in the audio, some type of noise intermittent in back sound. I have a Audigy ZS2.

Please do not post about the same thing in two different places. If we know the answer to the problem, we will tell you. Posting more times about the same thing does not increase your chances of getting an answer.
pagefault
ZSNES Developer
ZSNES Developer
Posts: 812
Joined: Tue Aug 17, 2004 5:24 am
Location: In your garden

Post by pagefault »

This is not related to the SDL port at all either.
12th&saturn
Rookie
Posts: 11
Joined: Tue Apr 25, 2006 4:30 am

Post by 12th&saturn »

This is a great idea! If this is still in progress libao would be a good reference as it's extremely small and fairly clean. People say good things about OpenAL too. Most anything is better than the high latencies and poor quality of SDL sound. I voted ALSA - please code an mmap() mode too!
Z_God
New Member
Posts: 3
Joined: Tue Apr 25, 2006 11:34 am
Location: Netherlands, Enschede
Contact:

Post by Z_God »

I tested it with my ENS1371. I was able to get it to work with aoss for one session. It worked extemely well. It somehow now doesn't work anymore through aoss though.
When I use the kernel OSS emulation, the emulated devices seem to miss several needed features.

I'm really looking forward to a native ALSA version :)
Herbchef
New Member
Posts: 5
Joined: Wed May 03, 2006 12:14 am

Post by Herbchef »

pagefault wrote:Updates:

No longer uses 100% CPU
Now syncs video to audio.
Checks to see if your card supports reporting the sound output delay.
Minor code cleanups.

http://zsnes.game-host.org/~pagefault/sdllink.c

Update #2

http://zsnes.game-host.org/~pagefault/synctest.c

Try this as well, this does a lot better job syncing the sound but also uses more CPU. May be an option later on.
My roommate and I just found out that the third roommate in our group has never played Secret of Mana. (*shock!*) So I'm going to be re-installing ZSNES today and starting up a game.

I just recently moved to Linux after kicking my Warcraft habit, so I'm wondering if there is anything I need to do to get ALSA goodness working when installing ZSNES. Are these updates included in ZSNES 1.42? Or do I need to download the c files from pagefault's web site and override the originals when compiling?

Just wondering. Thanks!
Post Reply