Linux/FreeBSD/Mac OS X etc sound
Moderator: ZSNES Mods
-
- ZSNES Developer
- Posts: 3904
- Joined: Tue Jul 27, 2004 10:54 pm
- Location: Solar powered park bench
- Contact:
I didn'tSpike wrote:I got it working on my emu10k1.

That makes it better for me, but it still sounds terrible.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!
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
_____________
Insane Coding
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;
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.Nach wrote:I didn'tSpike wrote:I got it working on my emu10k1.
That makes it better for me, but it still sounds terrible.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!

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;

Meh, best way to do this would be to reset then close, then reopen the device, and then set the parameters.
Alright....
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.
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;
-
- ZSNES Developer
- Posts: 3904
- Joined: Tue Jul 27, 2004 10:54 pm
- Location: Solar powered park bench
- Contact:
I do use OSS.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...
BTW thanks for your help, using your suggestions, I got it working perfectly for me

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;
}

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
_____________
Insane Coding
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!
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!
Ah nice, I get back and everything is done 
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.

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.
-
- ZSNES Developer
- Posts: 3904
- Joined: Tue Jul 27, 2004 10:54 pm
- Location: Solar powered park bench
- Contact:
http://nsrt.edgeemu.com/sdllink.c
Now supports all rates, PAL, and mono sound too.
Sound reinit seems to work good too
I also cleaned up some of the code and made it get the audio out faster, no more slow downs for me
Now supports all rates, PAL, and mono sound too.
Sound reinit seems to work good too

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
_____________
Insane Coding
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.
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.
-
- ZSNES Developer
- Posts: 3904
- Joined: Tue Jul 27, 2004 10:54 pm
- Location: Solar powered park bench
- Contact:
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
_____________
Insane Coding
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.
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.
-
- ZSNES Developer
- Posts: 3904
- Joined: Tue Jul 27, 2004 10:54 pm
- Location: Solar powered park bench
- Contact:
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.
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
_____________
Insane Coding
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.
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.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.
[url=http://zsnes-docs.sf.net]Official ZSNES Docs[/url] | [url=http://zsnes-docs.sf.net/nsrt]NSRT Guide[/url] | [url=http://endoftransmission.net/phpBB3/viewtopic.php?t=394]Using a Wiimote w/ emulators[/url]
-
- Rookie
- Posts: 11
- Joined: Tue Apr 25, 2006 4:30 am
-
- New Member
- Posts: 3
- Joined: Tue Apr 25, 2006 11:34 am
- Location: Netherlands, Enschede
- Contact:
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 :)
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 :)
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.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.
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!