linux - Alsalib mmap direct write -


i messing around alsa library , can't figure out how playback direct write. using access type mmap interleave. trying write square wave.

i created buffer of shorts hold square wave. have tested snd_pcm_writei , works.

i call snd_pcm_begin , use pointers given area write device:

  while(1){  int msg;  frames_available = snd_pcm_avail_update(handle);  snd_pcm_mmap_begin(handle,&areas,&offset,&limit_frames);  frames_to_write = frames;//frames size of buffer in frames  if(frames_to_write > limit_frames)   frames_to_write = 0;  int offset_frames = (areas[0].first + offset*areas[0].step)/16; short* write_ptr = (short*)areas[0].addr + offset_frames;  //fill buffer stuff for(int =0; < frames_to_write;i++){    write_ptr[i] = buffer[i];  }  msg = snd_pcm_mmap_commit(handle,offset,frames_to_write); 

}

the sound produced choppy , gets cut off after. gets cut off because limit_frame reaches 0. notice limit_frames stays @ 0 if there frames_available.

edit: used memcpy() instead of loop , solved choppiness. still gets cut off though. i'm curious why memcpy() solves choppiness. shouldn't loop , memcpy , loop copy on memory contiguously?

using mmap not make sense if you're doing copying samples buffer; that's same snd_pcm_writei() does.

anyway, before calling snd_pcm_mmap_begin(), must set last parameter number of frames intend write, , when returns smaller number, should write number, instead of 0.

when have more 1 channel, frame larger 1 sample.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -