sending data to /dev/dsp Solved.

2017-09-02 Thread Martin McCormick
I was using audio samples from a radio and a named pipe
open for reading to get them in to the ring buffer. The ring
buffer code was old code which works but I snatched defeat from
the jaws of victory by using the read command instead of fread.
The read command gets text strings while fread is meant for
binary data which this happens to be as in 16-bit audio samples.
Using the read command against that pipe pretended to work but
seems to actually get nothing at all. It looked like whatever I
initialized the sample variable to stayed there and wasn't
ever changed at all.

So, that was one killer.

Another odd thing appears to be that uninitialized memory
such as that ring buffer is now cleaner than it used to be so
even without initializing it, no noise blasted out of the speaker
as if it is all zeroed out.  Just to be safe, it is probably
better to set the buffer values to silence when starting up.

It all works now.

Martin McCormick



sending data to /dev/dsp

2017-09-02 Thread martin McCormick
I haven't fixed it yet but I discovered that on the
Debian 7 system, a recompile of the working version of the code
now produces a non-working version with the same problem as that
of Debian 8. Everything seems to compile as before but the new
target produces no output on /dev/dsp.

Basically, my question to the list is meaningless so I
will work until I figure it out and post what I found.

I presently have a usb-based sound card on the Debian 7
system which uses the same code and was working perfectly
yesterday so I don't know what is wrong well enough now to
describe it.

Martin McCormick



sending data to /dev/dsp

2017-09-02 Thread Martin McCormick
The system with the problem is running Debian GNU/Linux 8
and I am trying to run a program I wrote that works as it should
in Debian GNU/Linux 7.

The program sends audio to /dev/dsp or /dev/dsp# if the
card is other than card 0 and it works correctly.

On the Debian 8 system literally everything but the
program works. I got /dev/dsp by placing the snd-pcm-oss line in
/etc/modules and I can cat appropriate 8-bit binary data to
/dev/dsp and hear correct sound.

The program which sends sound to the audio output
compiles and appears to run on the Debian 8 system but data sent
to /dev/dsp produce total silence.

I've even got an un-witting form of testing for the
output channel which works as follows:

The program I wrote is a ring buffer to produce an audio
delay between audio received in to the sound card and the output
back to the sound card. It is necessary to seed all the memory in
the ring buffer with the value that represents silence or one
gets blasted with let's say, 10 seconds of utter noise as the
buffer memory is full of binary garbage when the ring runs for
the first time. In other words, you don't even have to have any
signal at the input to test your output. Just set a 5 or
ten-second delay and turn the volume down on your speakers or
especially headphones, and then fire up the delay. When it's
working, you'll hear what sounds like the end of the Earth
starting up for the duration of the delay and then the ring fills
up and you should hear your delayed audio.

On the newer Debian system, there is no sound output from
the program even when it is munching uninitialized RAM so I know
I've got trouble somewhere.

The program uses ioctl calls to initialize /dev/dsp to
look for 16-bit words and do this at 44100 samples per second and
all the ioctl commands run without error.

/dev/dsp opens without error before the ioctl commands so
it all looks ready to speak but it is mute. Anything else I send
it that should make noise does so with no problem.  Tracing
operation with gdb shows it going round and round like it should.

Here is how I setup the output channel which does work in Debian
7

  FILE *fd;   /* sound device file descriptor */
  fd = open("/dev/dsp", O_RDWR);
  if (fd < 0) {
perror("open of /dev/dsp failed");
exit(1);
  }

Here's a write that should make noise.


write(fd, &delaysample, sizeof(delaysample)); /* play  */

That's what just doesn't happen in Debian 8 but there is no error
or stoppage of the program.

Thanks for any ideas.

Martin WB5AGZ