root/branches/libfreebob-2.0/src/libstreaming/AmdtpPort.cpp

Revision 227, 2.7 kB (checked in by pieterpalmers, 16 years ago)

- another day of good progress comes to and end...
- compiles and runs, only the midi stuff and the xrun handling remain.

I'll also have to rework the C API somewhat.

Line 
1 /* $Id$ */
2
3 /*
4  *   FreeBob Streaming API
5  *   FreeBob = Firewire (pro-)audio for linux
6  *
7  *   http://freebob.sf.net
8  *
9  *   Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net>
10  *
11  *   This program is free software {} you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation {} either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with this program {} if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  *
26  *
27  */
28
29 #include "AmdtpPort.h"
30 #include <assert.h>
31
32 namespace FreebobStreaming {
33
34 AmdtpMidiPort::AmdtpMidiPort(std::string name,
35                            enum E_Direction direction,
36                            int position,
37                            int location,
38                            enum E_Formats format,
39                            int type)
40         : MidiPort(name, direction),
41           AmdtpPortInfo(name, position, location, format, type)
42           , m_countdown(0)
43 {
44         m_ringbuffer=freebob_ringbuffer_create(m_buffersize * getEventSize());
45        
46         if(!m_ringbuffer) {
47                 debugFatal("Could not allocate ringbuffer\n");
48                 m_buffersize=0;
49         }
50        
51 }
52
53 AmdtpMidiPort::~AmdtpMidiPort() {
54         if (m_ringbuffer) freebob_ringbuffer_free(m_ringbuffer);
55        
56 }
57
58 /**
59  * The problem with MIDI ports is that there is no guaranteed availability of data.
60  * This function will return true if:
61  *  (1) there is a byte ready in the buffer
62  *  (2) we are allowed to send a byte
63  *
64  * it will also assume that you actually are sending a byte, and it will reset
65  * the countdown
66  *
67  * note on (2): the midi over 1394 spec limits the speed of sending midi data bytes.
68  *              For every (time muxed) channel, you can send only one midi byte every
69  *              320 microseconds. The packet rate is 8000pkt/sec, or 125us. Therefore
70  *              we wait (at least) two packets before sending another byte. This comes
71  *              down to 375us, so there is a slight limiting of the bandwidth.
72  *
73  * \todo fix the too long delay (375us instead of 320us)
74  *
75  * @return true if you can send a midi byte
76  */
77 bool AmdtpMidiPort::canSend() {
78         bool byte_present_in_buffer;
79         assert(m_ringbuffer);
80        
81         byte_present_in_buffer=(freebob_ringbuffer_read_space(m_ringbuffer)>=sizeof(char));
82        
83         if(byte_present_in_buffer && (m_countdown < 0)) {
84                 m_countdown=2;
85                 return true;
86         }
87         return false;
88 }
89
90 } // end of namespace FreebobStreaming
Note: See TracBrowser for help on using the browser.