/[svn]/linuxsampler/trunk/src/engines/common/Event.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/common/Event.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 906 - (hide annotations) (download)
Sun Jul 23 16:44:08 2006 UTC (17 years, 9 months ago) by schoenebeck
File size: 4748 byte(s)
* MIDI driver API extension for MIDI drivers which already supply exact
  time stamps for events (i.e. for offline rendering based MIDI drivers)

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 906 * Copyright (C) 2005, 2006 Christian Schoenebeck *
7 schoenebeck 53 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #include "Event.h"
25    
26     namespace LinuxSampler {
27    
28     /**
29     * Create an EventGenerator.
30     *
31     * @param SampleRate - sample rate of the sampler engine's audio output
32     * signal (in Hz)
33     */
34     EventGenerator::EventGenerator(uint SampleRate) {
35     uiSampleRate = SampleRate;
36     uiSamplesProcessed = 0;
37 schoenebeck 328 FragmentTime.end = RTMath::CreateTimeStamp();
38 schoenebeck 53 }
39    
40     /**
41     * Updates the time stamps for the beginning and end of the current audio
42     * fragment. This is needed to be able to calculate the respective sample
43     * point later to which an event belongs to.
44     *
45     * @param SamplesToProcess - number of sample points to process in this
46     * audio fragment cycle
47     */
48     void EventGenerator::UpdateFragmentTime(uint SamplesToProcess) {
49     // update time stamp for this audio fragment cycle
50     FragmentTime.begin = FragmentTime.end;
51 schoenebeck 328 FragmentTime.end = RTMath::CreateTimeStamp();
52 schoenebeck 53 // recalculate sample ratio for this audio fragment
53     time_stamp_t fragmentDuration = FragmentTime.end - FragmentTime.begin;
54     FragmentTime.sample_ratio = (float) uiSamplesProcessed / (float) fragmentDuration;
55     // store amount of samples to process for the next cycle
56     uiSamplesProcessed = SamplesToProcess;
57     }
58    
59     /**
60     * Create a new event with the current time as time stamp.
61     */
62     Event EventGenerator::CreateEvent() {
63 schoenebeck 328 return Event(this, RTMath::CreateTimeStamp());
64 schoenebeck 53 }
65    
66     /**
67 schoenebeck 906 * Create a new event for the given sample point position in the current
68     * audio fragment.
69     *
70     * @param FragmentPos - actual sample point position in the current
71     * audio fragment to which the new event belongs to
72     */
73     Event EventGenerator::CreateEvent(int32_t FragmentPos) {
74     return Event(this, FragmentPos);
75     }
76    
77     /**
78 schoenebeck 53 * Will be called by an EventGenerator to create a new Event.
79 schoenebeck 906 * This Constructor expects a time stamp. The actual sample point
80     * position to which this event belongs to will be calculated later
81     * when FragmentPos() was called the first time.
82     *
83     * @param pGenerator - creator of this event
84     * @param Time - time stamp on which this event occured
85 schoenebeck 53 */
86     Event::Event(EventGenerator* pGenerator, time_stamp_t Time) {
87     pEventGenerator = pGenerator;
88     TimeStamp = Time;
89     iFragmentPos = -1;
90     }
91    
92 schoenebeck 906 /**
93     * Will be called by an EventGenerator to create a new Event.
94     * This constructor expects the final sample point position to which
95     * this event belongs to.
96     *
97     * @param pGenerator - creator of this event
98     * @param FragmentPos - actual sample point position in the current
99     * audio fragment to which this event belongs to
100     */
101     Event::Event(EventGenerator* pGenerator, int32_t FragmentPos) {
102     pEventGenerator = pGenerator;
103     iFragmentPos = FragmentPos;
104     }
105    
106 schoenebeck 53 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC