How to get clear sound from /dev/dsp(/dev/audio)

How to get clear sound from /dev/dsp(/dev/audio)

Post by Bomshik Ki » Sun, 13 Aug 2000 04:00:00



Hello

I want to know "How to get clear sound from /dev/dsp".
I use the ioctl function in order to get 16bit signed
integer, 8KHz sampled sound.

But the sound(voice) gotten from /dev/dsp (by opening /dev/dsp and
 reading that file_descriptor(fd) ) is not clear. There is some noise
(or scratch sound) in voice.(I think that it is not
 a problem of sound-card/microphone)

I tried to open /dev/dsp with O_RDONLY and read the fd
for some seconds to get voice, saved the voice data in memory.
After that, I closed the fd, reopen /dev/dsp with
O_WRONLY, and write the saved voice data to a new file-descriptor.
In this manner, I didn't hear scratch-sound.

But opening /dev/dsp with O_RDWR, and read/write voice data make
 some scratch sound.

open O_RDONLY -> read sound -> close ->
open O_WDONLY -> write sound -> close -> open O_RDONLY -> ...
It means that a sound-block read from sound_card
(not voice data of some duration) is played back as soon as possible
Repeating this sequence also makes scratch sound which is the bigger
scratch sound than the sound of O_RDWR mode.

I want to open /dev/dsp O_RDWR, set up the file descriptor
to full duplex mode, and read/write the fd without scrath sound.

Is it impossible to reduce scratch sound in opening /dev/dsp
withO_RDWR mode ?

Thank you for reading...
BS Kim

 
 
 

How to get clear sound from /dev/dsp(/dev/audio)

Post by Moritz Franosc » Sun, 13 Aug 2000 04:00:00



> I want to know "How to get clear sound from /dev/dsp".
> I use the ioctl function in order to get 16bit signed
> integer, 8KHz sampled sound.
> I tried to open /dev/dsp with O_RDONLY and read the fd
> for some seconds to get voice, saved the voice data in memory.
> After that, I closed the fd, reopen /dev/dsp with
> O_WRONLY, and write the saved voice data to a new file-descriptor.
> In this manner, I didn't hear scratch-sound.

Sound was ok, so your audio hardware is ok.

Quote:> But opening /dev/dsp with O_RDWR, and read/write voice data make
>  some scratch sound.

Possibly you have done it like this
1. write a block
2. read a block
3. write a block
...

When the whole block is read in 2., there is no sound left to play
from 1. This causes a sound buffer underflow which can make a click.

You have to do it like this
1. write a block
2. write a block (take care that this is possible without blocking, so
   if you have 4 frames of size framesize your block size schould be
   2*framesize)
3. read a block
4. write a block
...
n-1. read a block
n. read a block

So the sound buffer is always about half full.

Quote:> open O_RDONLY -> read sound -> close ->
> open O_WDONLY -> write sound -> close -> open O_RDONLY -> ...
> It means that a sound-block read from sound_card
> (not voice data of some duration) is played back as soon as possible
> Repeating this sequence also makes scratch sound which is the bigger
> scratch sound than the sound of O_RDWR mode.

This is clear because closing and opening the audio device causes
clicks.

Quote:> I want to open /dev/dsp O_RDWR, set up the file descriptor
> to full duplex mode, and read/write the fd without scrath sound.

You can email me for a small sample application that does exactly
that.

Moritz

 
 
 

How to get clear sound from /dev/dsp(/dev/audio)

Post by Dave Bla » Sun, 13 Aug 2000 04:00:00



> But opening /dev/dsp with O_RDWR, and read/write voice data make
>  some scratch sound.

> open O_RDONLY -> read sound -> close ->
> open O_WDONLY -> write sound -> close -> open O_RDONLY -> ...
> It means that a sound-block read from sound_card
> (not voice data of some duration) is played back as soon as possible
> Repeating this sequence also makes scratch sound which is the bigger
> scratch sound than the sound of O_RDWR mode.

Use ioctls to verify entire blocks are available for
reading or writing.

        audio_buf_info* info;
        fd_set handle;
        // Open handle as /dev/dsp
        int c;
        ioctl(handle, SNDCTL_DSP_GETOSPACE, info); // Check dsp device
        if (info->fragments >0){                   // dsp is ready to
                                                   // write
                //Write another fragment to handle
        }
        ioctl(handle, SNDCTL_DSP_GETISPACE, info); // Check dsp device
        if (info->fragments >0){                   // dsp is ready to
                                                   // write
                //Read another fragment from handle
        }

Use SNDCTL_DSP_GETISPACE as the argument to ioctl to
check that there are fragments to read.

Make fragments longer than 10 milliseconds for best results.

Reference
http://www.opensound.com/pguide/oss.pdf

--
Dave Blake

 
 
 

1. How to get clear sound from /dev/dsp(/dev/audio)

Hello~

I want to know "How to get clear sound from /dev/dsp".
I use the ioctl function in order to get 16bit signed
integer, 8KHz sampled sound.

But the sound(voice) gotten from /dev/dsp (by opening /dev/dsp and
 reading that file_descriptor(fd) ) is not clear. There is some noise
(or scratch sound) in voice.(I think that it is not
 a problem of sound-card/microphone)

I tried to open /dev/dsp with O_RDONLY and read the fd
for some seconds to get voice, saved the voice data in memory.
After that, I closed the fd, reopen /dev/dsp with
O_WRONLY, and write the saved voice data to a new file-descriptor.
In this manner, I didn't hear scratch-sound.

But opening /dev/dsp with O_RDWR, and read/write voice data make
 some scratch sound.

open O_RDONLY -> read sound -> close ->
open O_WDONLY -> write sound -> close -> open O_RDONLY -> ...
It means that a sound-block read from sound_card
(not voice data of some duration) is played back as soon as possible
Repeating this sequence also makes scratch sound which is the bigger
scratch sound than the sound of O_RDWR mode.

I want to open /dev/dsp O_RDWR, set up the file descriptor
to full duplex mode, and read/write the fd without scrath sound.

Is it impossible to reduce scratch sound in opening /dev/dsp
withO_RDWR mode ?

Thank you for reading...

BS Kim

2. Please help with remote booting. PROMs and OS boot file..!

3. /dev/dsp, /dev/audio, /dev/midi., /dev/sndsta

4. help with dld (gnus dynamic link library)...

5. Sound config: /dev/audio vs /dev/dsp

6. file table vs. inode table

7. /dev/dsp and /dev/audio in OSS sound engine

8. Help! How to set up SMTP on OS5?

9. 2.2.1 and /dev/dsp and /dev/audio

10. /dev/dsp and /dev/audio in kernel 2.2.6?

11. /dev/dsp and /dev/audio

12. problem linking support for /dev/audio and /dev/dsp

13. Using /dev/audio and /dev/dsp