diff options
author | David Robillard <d@drobilla.net> | 2007-05-31 21:37:20 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-05-31 21:37:20 +0000 |
commit | 0f2f4d8efc7f3e1144c6f51fd17c1ab309056c3e (patch) | |
tree | 5f3b9c752aafcd9874ae55197d678d4b17bbc442 /libs/ardour/buffer.cc | |
parent | 52a8242a1158426caeed4757bbc3f7f71091e351 (diff) |
Rewrote MidiRingBuffer to more efficiently pack data (flat pack stamps, sizes, and event data into a single buffer).
Eliminate a double-copy on MIDI playback (MidiRingBuffer -> MidiBuffer).
Various MIDI diskstream/source/SMF fixes (only write when appropriate, handle transport locates, etc).
Fix MIDI rec region size/offset problems.
Code cleanups.
git-svn-id: svn://localhost/ardour2/trunk@1934 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/buffer.cc')
-rw-r--r-- | libs/ardour/buffer.cc | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/libs/ardour/buffer.cc b/libs/ardour/buffer.cc index 7635ea2199..0328122940 100644 --- a/libs/ardour/buffer.cc +++ b/libs/ardour/buffer.cc @@ -80,10 +80,10 @@ MidiBuffer::MidiBuffer(size_t capacity) #ifdef NO_POSIX_MEMALIGN _events = (MidiEvent *) malloc(sizeof(MidiEvent) * capacity); - _data = (RawMidi *) malloc(sizeof(RawMidi) * capacity * MAX_EVENT_SIZE); + _data = (Byte *) malloc(sizeof(Byte) * capacity * MAX_EVENT_SIZE); #else posix_memalign((void**)&_events, CPU_CACHE_ALIGN, sizeof(MidiEvent) * capacity); - posix_memalign((void**)&_data, CPU_CACHE_ALIGN, sizeof(RawMidi) * capacity * MAX_EVENT_SIZE); + posix_memalign((void**)&_data, CPU_CACHE_ALIGN, sizeof(Byte) * capacity * MAX_EVENT_SIZE); #endif assert(_data); assert(_events); @@ -138,7 +138,7 @@ MidiBuffer::push_back(const MidiEvent& ev) if (_size == _capacity) return false; - RawMidi* const write_loc = _data + (_size * MAX_EVENT_SIZE); + Byte* const write_loc = _data + (_size * MAX_EVENT_SIZE); memcpy(write_loc, ev.buffer, ev.size); _events[_size] = ev; @@ -153,6 +153,36 @@ MidiBuffer::push_back(const MidiEvent& ev) } +/** Reserve space for a new event in the buffer. + * + * This call is for copying MIDI directly into the buffer, the data location + * (of sufficient size to write \a size bytes) is returned, or NULL on failure. + * This call MUST be immediately followed by a write to the returned data + * location, or the buffer will be corrupted and very nasty things will happen. + */ +Byte* +MidiBuffer::reserve(nframes_t time, size_t size) +{ + assert(size < MAX_EVENT_SIZE); + + if (_size == _capacity) + return NULL; + + Byte* const write_loc = _data + (_size * MAX_EVENT_SIZE); + + _events[_size].time = time; + _events[_size].size = size; + _events[_size].buffer = write_loc; + ++_size; + + //cerr << "MidiBuffer: reserved, size = " << _size << endl; + + _silent = false; + + return write_loc; +} + + void MidiBuffer::silence(nframes_t dur, nframes_t offset) { @@ -161,7 +191,7 @@ MidiBuffer::silence(nframes_t dur, nframes_t offset) //assert(dur == _capacity); memset(_events, 0, sizeof(MidiEvent) * _capacity); - memset(_data, 0, sizeof(RawMidi) * _capacity * MAX_EVENT_SIZE); + memset(_data, 0, sizeof(Byte) * _capacity * MAX_EVENT_SIZE); _size = 0; _silent = true; } |