root/branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.h

Revision 312, 5.8 kB (checked in by jwoithe, 16 years ago)

MOTU: fix xrun recovery glitches inadvertantly introduced in r309.
MOTU: preliminary MIDI port support. Rate control still needs to be added so it probably won't work in its current form yet. MIDI has not yet been tested.
MOTU: tweaks to receive/transmit missed cycle detection.
jack driver: during driver shutdown don't try to free NULL ports created for non-audio ports during initialisation to preserve device port index locations.

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  *   Copyright (C) 2006 Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11  *
12  *   This program is free software {} you can redistribute it and/or modify
13  *   it under the terms of the GNU General Public License as published by
14  *   the Free Software Foundation {} either version 2 of the License, or
15  *   (at your option) any later version.
16  *
17  *   This program is distributed in the hope that it will be useful,
18  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *   GNU General Public License for more details.
21  *
22  *   You should have received a copy of the GNU General Public License
23  *   along with this program {} if not, write to the Free Software
24  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  *
26  *
27  *
28  */
29 #ifndef __FREEBOB_MOTUSTREAMPROCESSOR__
30 #define __FREEBOB_MOTUSTREAMPROCESSOR__
31 #include <assert.h>
32
33 #include "../debugmodule/debugmodule.h"
34 #include "StreamProcessor.h"
35
36 #include "../libutil/DelayLockedLoop.h"
37
38 namespace FreebobStreaming {
39
40 class MotuAudioPort;
41
42 /**
43  * This class implements the outgoing stream processing for
44  * motu devices
45  */
46 class MotuTransmitStreamProcessor
47     : public TransmitStreamProcessor
48 {
49 public:
50        
51         MotuTransmitStreamProcessor(int port, int framerate,
52                 unsigned int event_size);
53
54         virtual ~MotuTransmitStreamProcessor();
55
56         enum raw1394_iso_disposition
57                 getPacket(unsigned char *data, unsigned int *length,
58                       unsigned char *tag, unsigned char *sy,
59                       int cycle, unsigned int dropped, unsigned int max_length);
60
61         bool init();
62         bool reset();
63         bool prepare();
64         bool transfer();
65        
66         bool isOnePeriodReady();
67
68         // These two are important to calculate the optimal ISO DMA buffers
69         // size.  An estimate will do.
70         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
71         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
72
73         virtual void setVerboseLevel(int l);
74
75         void setTicksPerFrameDLL(float *dll) {m_ticks_per_frame=dll;};
76
77         virtual bool preparedForStop();
78         virtual bool preparedForStart();
79
80 protected:
81
82         freebob_ringbuffer_t * m_event_buffer;
83         char* m_tmp_event_buffer;
84        
85         /*
86          * An iso packet mostly consists of multiple events.  m_event_size
87          * is the size of a single 'event' in bytes.
88          */
89         unsigned int m_event_size;
90
91         // Keep track of transmission data block count
92         unsigned int m_tx_dbc;
93
94         // Transmission cycle count and cycle offset
95         signed int m_cycle_count;
96         float m_cycle_ofs;
97
98         // Used to detect missed cycles
99         signed int m_next_cycle;
100
101         // Hook to the DLL in the receive stream which provides a
102         // continuously updated estimate of the number of ieee1394 ticks
103         // per audio frame.
104         float *m_ticks_per_frame;
105
106         // Used to keep track of the close-down zeroing of output data
107         signed int m_closedown_count;
108         signed int m_streaming_active;
109
110     bool prefill();
111    
112         bool transferSilence(unsigned int size);
113
114         int transmitBlock(char *data, unsigned int nevents,
115                           unsigned int offset);
116                          
117         bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
118        
119         int transmitSilenceBlock(char *data, unsigned int nevents,
120                           unsigned int offset);
121                          
122         int encodePortToMBLAEvents(MotuAudioPort *p, quadlet_t *data,
123                 unsigned int offset, unsigned int nevents);
124         int encodeSilencePortToMBLAEvents(MotuAudioPort *p, quadlet_t *data,
125                 unsigned int offset, unsigned int nevents);
126
127     DECLARE_DEBUG_MODULE;
128
129 };
130
131 /**
132  * This class implements the incoming stream processing for
133  * motu devices
134  */
135 class MotuReceiveStreamProcessor
136     : public ReceiveStreamProcessor
137 {
138
139 public:
140
141         MotuReceiveStreamProcessor(int port, int framerate, unsigned int event_size);
142         virtual ~MotuReceiveStreamProcessor();
143        
144         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
145                       unsigned char channel, unsigned char tag, unsigned char sy,
146                           unsigned int cycle, unsigned int dropped);
147        
148         bool init();
149         bool reset();
150         bool prepare();
151         bool transfer();
152        
153         bool isOnePeriodReady();
154
155     // these two are important to calculate the optimal
156     // ISO DMA buffers size
157     // an estimate will do
158         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
159         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
160
161         virtual void setVerboseLevel(int l);
162        
163         float *getTicksPerFrameDLL(void) {return &m_ticks_per_frame;};
164         signed int setEventSize(unsigned int size);
165         unsigned int getEventSize(void);
166
167         virtual bool preparedForStop();
168         virtual bool preparedForStart();
169
170 protected:
171
172         int receiveBlock(char *data, unsigned int nevents, unsigned int offset);
173         bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
174         signed int decodeMBLAEventsToPort(MotuAudioPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents);
175
176         freebob_ringbuffer_t * m_event_buffer;
177         char* m_tmp_event_buffer;
178        
179         /*
180          * An iso packet mostly consists of multiple events.  m_event_size
181          * is the size of a single 'event' in bytes.
182          */
183         unsigned int m_event_size;
184
185         // The integrator of a Delay-Locked Loop (DLL) used to provide a
186         // continuously updated estimate of the number of ieee1394 frames
187         // per audio frame at the current sample rate.
188         float m_ticks_per_frame;
189
190         signed int m_last_cycle_ofs;
191         signed int m_next_cycle;
192
193         // Signifies a closedown is in progress, in which case incoming data
194         // is junked.
195         signed int m_closedown_active;
196
197     DECLARE_DEBUG_MODULE;
198
199 };
200
201 } // end of namespace FreebobStreaming
202
203 #endif /* __FREEBOB_MOTUSTREAMPROCESSOR__ */
204
205
Note: See TracBrowser for help on using the browser.