1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-24 06:10:09 +01:00
Files
autotools
dox2-src
help
images
include
lib-src
FileDialog
expat
ffmpeg
lame
lib-widget-extra
libflac
libid3tag
libmad
libnyquist
autotools
nyquist
cmt
cext.c
cext.h
cleanup.c
cleanup.h
cmdline.c
cmdline.h
cmtcmd.c
cmtcmd.h
cmtio.c
cmtio.h
hash.h
hashrout.h
mem.c
mem.h
mfmidi.h
midibuff.h
midicode.h
midierr.h
midifile.c
midifile.h
midifns.c
midifns.h
midimgr.c
midimgr.h
moxc.c
moxc.h
musiprog.h
pitch.h
record.c
record.h
seq.c
seq.h
seqdecls.h
seqmread.c
seqmread.h
seqmwrite.c
seqmwrite.h
seqread.c
seqread.h
seqwrite.c
seqwrite.h
swlogic.h
tempomap.c
tempomap.h
timebase.c
timebase.h
userio.c
userio.h
ffts
nyqsrc
nyqstk
sys
tran
xlisp
Readme.txt
license.txt
LICENSE.txt
Makefile.am
Makefile.in
README.txt
configure
configure.ac
nyquist.patch
nyx.c
nyx.h
revert-convolve.patch
sound.patch
xlextstart.c
xlisp.patch
libogg
libscorealign
libsndfile
libsoxr
libvamp
libvorbis
lv2
mod-null
mod-nyq-bench
mod-script-pipe
mod-track-panel
portaudio-v19
portburn
portmidi
portmixer
portsmf
sbsms
soundtouch
twolame
Makefile.am
Makefile.in
audacity-patches.txt
dist-libsoxr.mk
dist-libvamp.mk
dist-portaudio.mk
locale
m4
mac
nyquist
plug-ins
presets
qa
scripts
src
tests
win
.gitattributes
.gitignore
.travis.yml
ABOUT-NLS
LICENSE.txt
Makefile.am
Makefile.in
README.txt
appveyor.yml
audacity.dox
branches.txt
configure
configure.ac
todo.txt
audacity/lib-src/libnyquist/nyquist/cmt/tempomap.c
2010-01-24 09:19:39 +00:00

125 lines
3.2 KiB
C

/* tempomap.c -- used by midifile reader to record and lookup time maps */
/*
* This module is designed to provide tempo change list insert and
* lookup facilities. The exact interpretation of beat and tempo are
* defined in one function, elapsed_time, which takes a tempo and a
* number of beats, and returns time.
*/
#include "cext.h"
#include "midifns.h"
#include "timebase.h"
#include "moxc.h"
#include "seq.h"
#include "tempomap.h"
static time_type elapsed_time();
/* tempomap_create -- create a tempomap */
/**/
tempomap_type tempomap_create()
{
tempochange_type tempochange = tempochange_alloc();
tempomap_type tempomap = tempomap_alloc();
tempomap->hint = tempomap->entries = tempochange;
tempochange->beat = 0L;
/* default tempo is 120 (= 50000microsec/beat) and 24 divisions/quarter */
/* this may be overridden by a tempomap_insert */
tempochange->tempo = 500000L / 24;
tempochange->rtime = 0L;
tempochange->next = NULL;
return tempomap;
}
/* tempomap_free -- deallocate storage for tempo map */
/**/
void tempomap_free(tm)
tempomap_type tm;
{
while (tm->entries) {
tempochange_type tc = tm->entries;
tm->entries = tc->next;
tempochange_free(tc);
}
memfree(tm, sizeof(tempomap_node));
}
/* tempomap_insert -- insert a tempo change into the map */
/**/
void tempomap_insert(tempomap, beat, tempo)
tempomap_type tempomap;
long beat; /* beat division number */
long tempo; /* microseconds per beat division */
{
tempochange_type tempochange = tempochange_alloc();
register tempochange_type prev;
register tempochange_type next;
tempochange->tempo = tempo;
tempochange->beat = beat;
if ((!(tempomap->hint->next)) ||
(tempomap->hint->beat > beat))
tempomap->hint = tempomap->entries;
/* find the insert point */
for (prev = tempomap->hint;
(next = prev->next) && (next->beat <= beat);
prev = next);
/* make the insert */
tempochange->next = next;
prev->next = tempochange;
tempomap->hint = prev;
/* update the real time of each change */
for (tempochange = prev;
tempochange->next;
tempochange = tempochange->next) {
tempochange->next->rtime =
tempochange->rtime +
elapsed_time(tempochange->tempo,
tempochange->next->beat - tempochange->beat);
}
}
/* tempomap_lookup -- convert beat to 4us time */
/*
* The returned time is real time in units of 4us.
*/
time_type tempomap_lookup(tempomap, beat)
tempomap_type tempomap;
long beat;
{
register tempochange_type prev;
register tempochange_type next;
if ((!(tempomap->hint->next)) ||
(tempomap->hint->beat > beat))
tempomap->hint = tempomap->entries;
/* find the last inflection point */
for (prev = tempomap->hint;
(next = prev->next) && (next->beat <= beat);
prev = next);
/* interpolate */
return prev->rtime +
elapsed_time(prev->tempo, beat - prev->beat);
}
/* elapsed_time -- compute the real elapsed time at a given tempo */
/*
* the time returned is in units of 4us.
*/
static time_type elapsed_time(tempo, beat)
long tempo;
long beat;
{
return (time_type)((tempo * beat) >> 2);
}