All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve deRosier <derosier@pianodisc.com>
To: Lee Revell <rlrevell@joe-job.com>
Cc: Alsa-Devel <alsa-devel@lists.sourceforge.net>
Subject: Re: How to tell how many frames gone to PCM
Date: Tue, 26 Apr 2005 14:45:33 -0700	[thread overview]
Message-ID: <426EB67D.6010809@pianodisc.com> (raw)
In-Reply-To: <1114550230.8431.45.camel@mindpipe>

> 
> One possibility is that you are hitting an ALSA bug.  Some fixes have
> been merged since ALSA 1.0.8 for bugs that could account for the strange
> behavior.  The first thing to do is verify the problem does not appear
> with a newer ALSA.
> 

I'll have to try that.  I think we're running 1.0.4 at the moment.  We hesitate to update at this point due to most things just working (mine is the only alsa using program in the system experiencing this problem) and we have a headache every time we upgrade, but maybe it won't be so hard this time around since the API has solidified more than in earlier upgrade tries.

> Another idea, by default the MIDI timing will be driven by the system
> timer, while the PCM will be driven by the soundcard timer, even if your
> MIDI port is on the same board as your audio.  Although I would expect
> the drift to be very small.
> 
I should (if I did it right) have the pcm and midi timers linked.  I use two different classes for output, one for the PCM (called CDSP) and one for the MIDI (called CMIDIPort).  Usually this makes things simple, but linking the clocks requires pasing info back and forth between the two.  My thread does this:
---
mPCMInfo = mDSP.GetInfo();
if( !mPCMInfo )
  return false;
  
if( !mMIDIPort.LinkPCMTimer( mPCMInfo ) )
  return false;

return true;  
---

calling CDSP::GetInfo():
---
snd_pcm_info_t * CDSP::GetInfo( void )
{
  snd_pcm_info_t * PCMInfo;
  
  snd_pcm_info_malloc( &PCMInfo );
  int err = snd_pcm_info( hPCM, PCMInfo );
  if( err < 0 )
  {
    FreeInfo( PCMInfo );
    return NULL;
  }
    
  return PCMInfo;  
}
---

And to actually link the timers:
---
bool CMIDIPort::LinkPCMTimer( const snd_pcm_info_t * PCMInfo )
{
  if( !PCMInfo )
    return false;
    
  snd_seq_queue_timer_t * QueueTimer;
  snd_timer_id_t * QTID;
    
  // get the info we need
  int Card = snd_pcm_info_get_card( PCMInfo );
  unsigned int Device = snd_pcm_info_get_device( PCMInfo );
  unsigned int SDevice = snd_pcm_info_get_subdevice( PCMInfo );
  SDevice = SDevice << 1;
  // check for bad return
  if( ( Card < 0 ) ) 
    return false;
    
  // build our timers
  snd_seq_queue_timer_alloca( &QueueTimer );
  snd_timer_id_alloca( &QTID );
  
  if( snd_seq_get_queue_timer( hSeq, mQueue, QueueTimer ) < 0 )
    return false;
  
  // setup the data that links us to the PCM
  snd_timer_id_set_class( QTID, SND_TIMER_CLASS_PCM );
  snd_timer_id_set_sclass( QTID, SND_TIMER_SCLASS_NONE );
  snd_timer_id_set_card( QTID, Card );
  snd_timer_id_set_device( QTID, Device );
  snd_timer_id_set_subdevice( QTID, SDevice );


  // setup the actual timer
  snd_seq_queue_timer_set_type( QueueTimer, SND_SEQ_TIMER_ALSA );
  snd_seq_queue_timer_set_id( QueueTimer, QTID );
  snd_seq_set_queue_timer( hSeq, mQueue, QueueTimer );
  
  return true;
}
---

Is that done right?  Is there something I'm forgetting to do?



> As a last resort, you could hack the low level driver to keep track of
> the frames written to the hardware.  Add a counter to the chip structure
> and increment it in the interrupt handler.
> 
Ick.  Last resort definately.  Though I have hacked some of the drivers before, I'd just rather not; you know what I mean?  ;)  

Thanks,
- Steve



-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start!  http://www.idcswdc.com/cgi-bin/survey?id=105hix

  reply	other threads:[~2005-04-26 21:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-26 20:18 How to tell how many frames gone to PCM Steve deRosier
2005-04-26 20:16 ` Lee Revell
2005-04-26 21:07   ` Steve deRosier
2005-04-26 21:17     ` Lee Revell
2005-04-26 21:45       ` Steve deRosier [this message]
2005-04-27 14:36         ` Clemens Ladisch
2005-04-27 16:56           ` Steve deRosier
2005-04-27 17:22             ` Clemens Ladisch
2005-04-27 20:31               ` Steve deRosier
2005-04-28  8:25                 ` Clemens Ladisch
2005-05-02 18:04                   ` Steve deRosier
2005-05-03  8:05                     ` Clemens Ladisch
     [not found] ` <ad2655cb0504270201165f9859@mail.gmail.com>
2005-04-27 16:43   ` Steve deRosier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=426EB67D.6010809@pianodisc.com \
    --to=derosier@pianodisc.com \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=rlrevell@joe-job.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.