// Copyright (C) 2004 David Griffiths // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "AtomicClock.h" AtomicClock::AtomicClock(float frequency) : m_Time(0), m_Frequency(frequency) { int err; char timername[64]; TimerDesc timer; timer.Class = SND_TIMER_CLASS_GLOBAL; timer.SClass = SND_TIMER_CLASS_NONE; timer.Card = 0; timer.Device = SND_TIMER_GLOBAL_SYSTEM; timer.Subdevice = 0; snd_timer_id_t *id; snd_timer_info_t *info; snd_timer_params_t *params; snd_timer_id_alloca(&id); snd_timer_info_alloca(&info); snd_timer_params_alloca(¶ms); sprintf(timername, "hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i", timer.Class, timer.SClass, timer.Card, timer.Device, timer.Subdevice); if ((err = snd_timer_open(&m_Handle, timername, SND_TIMER_OPEN_NONBLOCK))<0) { fprintf(stderr, "timer open %i (%s)\n", err, snd_strerror(err)); assert(0); } if ((err = snd_timer_info(m_Handle, info)) < 0) { fprintf(stderr, "timer info %i (%s)\n", err, snd_strerror(err)); assert(0); } snd_timer_params_set_auto_start(params, 1); snd_timer_params_set_ticks(params, (int)((1000000000 / snd_timer_info_get_resolution(info)) / frequency)); /* in Hz */ //cerr<