tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Audio volume setting: not working - sometimes?
9.1, amd64. Audio hardware is
[ 1.047133] hdaudio0 at pci0 dev 31 function 3: HD Audio Controller
[ 1.047133] hdaudio0: interrupting at msi5 vec 0
[ 1.047133] hdafg0 at hdaudio0: vendor 10ec product 0269
[ 1.047133] hdafg0: DAC00 2ch: HP Out [Jack]
[ 1.047133] hdafg0: DAC01 2ch: Speaker [Built-In]
[ 1.047133] hdafg0: ADC02 2ch: Mic In [Jack]
[ 1.047133] hdafg0: 2ch/2ch 32000Hz 44100Hz 48000Hz 88200Hz 96000Hz 192000Hz PCM16 PCM20 PCM24 AC3
[ 1.047133] audio0 at hdafg0: playback, capture, full duplex, independent
[ 1.047133] audio0: slinear_le:16 2ch 48000Hz, blk 1920 bytes (10ms) for playback
[ 1.047133] audio0: slinear_le:16 2ch 48000Hz, blk 1920 bytes (10ms) for recording
[ 1.047133] spkr0 at audio0: PC Speaker (synthesized)
[ 1.047133] wsbell at spkr0 not configured
[ 1.047133] hdafg1 at hdaudio0: vendor 8086 product 280b
[ 1.047133] hdafg1: DP00 8ch: Digital Out [Jack]
[ 1.047133] hdafg1: 8ch/0ch 48000Hz PCM16*
Userland does
fd = open("/dev/audio0",O_RDWR,0);
...
setup_audio();
static void setup_audio(void)
{
struct audio_info oai;
struct audio_info ai;
fprintf(stderr,"%s\n",__func__);
if (ioctl(fd,AUDIO_GETBUFINFO,&oai) < 0)
{ fprintf(stderr,"AUDIO_GETBUFINFO: %s\n",strerror(errno));
exit(1);
}
AUDIO_INITINFO(&ai);
ai.play.sample_rate = 8000;
ai.play.channels = 1;
ai.play.precision = 16;
ai.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
ai.play.gain = AUDIO_MAX_GAIN;
ai.play.port = oai.play.avail_ports;
ai.play.pause = 0;
ai.play.balance = AUDIO_MID_BALANCE;
ai.monitor_gain = AUDIO_MAX_GAIN;
ai.mode = AUMODE_PLAY | AUMODE_PLAY_ALL;
if (ioctl(fd,AUDIO_SETINFO,&ai) < 0)
{ fprintf(stderr,"AUDIO_SETINFO: %s\n",strerror(errno));
exit(1);
}
}
and then, 8000 times a second, does
unsigned char sample[2];
...
sample[0] = v;
sample[1] = v;
write(fd,&sample[0],2);
(v coming in to that code is 8-bit unsigned linear).
This works fine, in that I get sound. But it looks as though the
setting of ai.play.gain is being ignored: audioctl play.gain reports
the last value set with audioctl -w play.gain=..., even if I restart
the code I quoted above (and the printfs appear); the volume of the
sound driven out the jack matches what audioctl reports. But I know
the AUDIO_SETINFO isn't simply being ignored, because the sample rate,
channel count, and precision change to 8000/1/16 even if they were (as
reported by audioctl -a) set differently before.
So, my question is, why is play.gain being ignored? What am I doing
wrong? I'm sure it's something that'll be obvious once I see it, but
I'm having trouble seeing it.
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse%rodents-montreal.org@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Home |
Main Index |
Thread Index |
Old Index