libalsa - How to get instantaneous volume or played-time with ALSA in Linux -




i'm writing "play sound" program on reapberry pi alsa.

i called snd_pcm_writei every 1280 samples.

i wish add small led, , let "lighter while sound louder, , darker while sound quieter."

my plane is, if there's callback every short time period(ex: 100ms), , can instantaneous volume in callback, can control led in it.

in android, there's audiotrack.setpositionnotificationperiod. however, i've no idea how under linux alsa.

could give me advise?

the playback function looks this:

// nleftframesize: total sample number. // hdevice: play device handle (initialized beforehand). // lpbybuffer: sample buffer.  while(nleftframesize > 0){     nres = (int)snd_pcm_writei(( snd_pcm_t*)hdevice, lpbybuffer, 1280);     nleftframesize -= 1280; } 

i've tried calculate rms in while loop before snd_pcm_writei(), set led brightness, , sleep, make sure led can light while these 1280 samples playing. cause sound discontinuous.

so i'd create thread led control, , can sleep in thread without bothering playback.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -