From: Steve deRosier <derosier@pianodisc.com>
To: James Courtier-Dutton <james.dutton@gmail.com>
Cc: Alsa-Devel <alsa-devel@lists.sourceforge.net>
Subject: Re: How to tell how many frames gone to PCM
Date: Wed, 27 Apr 2005 09:43:00 -0700 [thread overview]
Message-ID: <426FC114.6000800@pianodisc.com> (raw)
In-Reply-To: <ad2655cb0504270201165f9859@mail.gmail.com>
>
> You might want the "snd_pcm_delay()" function.
> This will return a count of frames in the buffer that have not yet
> reached the ADC.
> E.g.
> snd_pcm_write() <- Write 1024 frames to the buffer.
> snd_pcm_delay() <- If this returns 500, it means that 525 frames have
> already been played out of the speakers.
>
> The snd_pcm_delay() function was introduced into alsa to help
> audio/video application do lip sync. We could therefore calculate that
> if we write a frame to the buffer now, it will reach the speakers in
> exactly snd_pcm_delay() frames time.
>
> Does this help you?
I've got it implemented in my system, but actually it doesn't solve the problem (and actually exasperates it).
See, we calculate the midi times based on the "sample" time that the midi msg arrives at.
So, for example:
Our AlsaSender task receives a right and left audio sample (the two together I suppose is called a frame), and the last MIDI byte of a message. It keeps a counter of how many audio frames are received at this point. It sends the audio frame to alsa (actually the CDSP function buffers up PERIOD_SIZE number of samples before it does the ..._writei() in order to not cause excessive function call overhead). It calculates the MIDI timestamp based on the number of samples it has sent off:
snd_seq_real_time_t time;
unsigned long long int iTime = (((mPlayedSampleCount*10*P_MILLION)/441);
time.tv_sec = iTime/P_BILLION;
time.tv_nsec = iTime%P_BILLION;
snd_seq_ev_set_source(&event, mPort);
snd_seq_ev_set_subs(&event);
snd_seq_ev_schedule_real(&event, mQueue, 0, &time);
snd_seq_event_output(hSeq, &event);
snd_seq_drain_output(hSeq);
Our audio source is CD, so 44100 is the correct speed for the calculation (non-significant zeros canceled off in the calculation).
Anything obviously wrong with my approach?
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
prev parent reply other threads:[~2005-04-27 16:43 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
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 [this message]
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=426FC114.6000800@pianodisc.com \
--to=derosier@pianodisc.com \
--cc=alsa-devel@lists.sourceforge.net \
--cc=james.dutton@gmail.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.