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

Revision 305, 5.5 kB (checked in by jwoithe, 18 years ago)

MotuStreamProcessor?.h: remove class name in erroneously included in the definition of two transmit stream methods. Thanks to Francois Ernoult for the bug report.

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
79 protected:
80
81         freebob_ringbuffer_t * m_event_buffer;
82         char* m_tmp_event_buffer;
83        
84         /*
85          * An iso packet mostly consists of multiple events.  m_event_size
86          * is the size of a single 'event' in bytes.
87          */
88         unsigned int m_event_size;
89
90         // Keep track of transmission data block count
91         unsigned int m_tx_dbc;
92
93         // Transmission cycle count and cycle offset
94         signed int m_cycle_count;
95         float m_cycle_ofs;
96
97         // Used to detect missed cycles
98         signed int m_next_cycle;
99
100         // Hook to the DLL in the receive stream which provides a
101         // continuously updated estimate of the number of ieee1394 ticks
102         // per audio frame.
103         float *m_ticks_per_frame;
104
105         // Used to keep track of the close-down zeroing of output data
106         signed int m_closedown_count;
107         signed int m_streaming_active;
108
109     bool prefill();
110    
111         bool transferSilence(unsigned int size);
112
113         int transmitBlock(char *data, unsigned int nevents,
114                           unsigned int offset);
115                          
116         bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
117        
118         int transmitSilenceBlock(char *data, unsigned int nevents,
119                           unsigned int offset);
120                          
121         int encodePortToMBLAEvents(MotuAudioPort *p, quadlet_t *data,
122                 unsigned int offset, unsigned int nevents);
123         int encodeSilencePortToMBLAEvents(MotuAudioPort *p, quadlet_t *data,
124                 unsigned int offset, unsigned int nevents);
125
126     DECLARE_DEBUG_MODULE;
127
128 };
129
130 /**
131  * This class implements the incoming stream processing for
132  * motu devices
133  */
134 class MotuReceiveStreamProcessor
135     : public ReceiveStreamProcessor
136 {
137
138 public:
139
140         MotuReceiveStreamProcessor(int port, int framerate, unsigned int event_size);
141         virtual ~MotuReceiveStreamProcessor();
142        
143         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
144                       unsigned char channel, unsigned char tag, unsigned char sy,
145                           unsigned int cycle, unsigned int dropped);
146        
147         bool init();
148         bool reset();
149         bool prepare();
150         bool transfer();
151        
152         bool isOnePeriodReady();
153
154     // these two are important to calculate the optimal
155     // ISO DMA buffers size
156     // an estimate will do
157         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
158         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
159
160         virtual void setVerboseLevel(int l);
161        
162         float *getTicksPerFrameDLL(void) {return &m_ticks_per_frame;};
163         signed int setEventSize(unsigned int size);
164         unsigned int getEventSize(void);
165
166 protected:
167
168         int receiveBlock(char *data, unsigned int nevents, unsigned int offset);
169         bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
170         signed int decodeMBLAEventsToPort(MotuAudioPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents);
171
172         freebob_ringbuffer_t * m_event_buffer;
173         char* m_tmp_event_buffer;
174        
175         /*
176          * An iso packet mostly consists of multiple events.  m_event_size
177          * is the size of a single 'event' in bytes.
178          */
179         unsigned int m_event_size;
180
181         // The integrator of a Delay-Locked Loop (DLL) used to provide a
182         // continuously updated estimate of the number of ieee1394 frames
183         // per audio frame at the current sample rate.
184         float m_ticks_per_frame;
185
186         signed int m_last_cycle_ofs;
187         signed int m_next_cycle;
188
189     DECLARE_DEBUG_MODULE;
190
191 };
192
193 } // end of namespace FreebobStreaming
194
195 #endif /* __FREEBOB_MOTUSTREAMPROCESSOR__ */
196
197
Note: See TracBrowser for help on using the browser.