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

Revision 274, 4.3 kB (checked in by jwoithe, 18 years ago)

Fix buffer type configuration in teststreaming{2,3}.c.
Audio data can now be streamed in from a MOTU to teststreaming2.c.

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 #ifndef __FREEBOB_MOTUSTREAMPROCESSOR__
29 #define __FREEBOB_MOTUSTREAMPROCESSOR__
30 #include <assert.h>
31
32 #include "../debugmodule/debugmodule.h"
33 #include "StreamProcessor.h"
34
35 namespace FreebobStreaming {
36
37 class MotuAudioPort;
38
39 /**
40  * This class implements the outgoing stream processing for
41  * motu devices
42  */
43 class MotuTransmitStreamProcessor
44     : public TransmitStreamProcessor
45 {
46 public:
47        
48         MotuTransmitStreamProcessor(int port, int framerate,
49                 unsigned int event_size);
50
51         virtual ~MotuTransmitStreamProcessor();
52
53         enum raw1394_iso_disposition
54                 getPacket(unsigned char *data, unsigned int *length,
55                       unsigned char *tag, unsigned char *sy,
56                       int cycle, unsigned int dropped, unsigned int max_length);
57
58         bool init();
59         bool reset();
60         bool prepare();
61         bool transfer();
62        
63         bool isOnePeriodReady();
64
65         // These two are important to calculate the optimal ISO DMA buffers
66         // size.  An estimate will do.
67         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
68         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
69
70         virtual void setVerboseLevel(int l);
71
72 protected:
73
74         freebob_ringbuffer_t * m_event_buffer;
75         char* m_tmp_event_buffer;
76        
77         /*
78          * An iso packet mostly consists of multiple events.  m_event_size
79          * is the size of a single 'event' in bytes.
80          */
81         unsigned int m_event_size;
82        
83     bool prefill();
84    
85         bool transferSilence(unsigned int size);
86
87         int transmitBlock(char *data, unsigned int nevents,
88                           unsigned int offset);
89                          
90         bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
91        
92         int transmitSilenceBlock(char *data, unsigned int nevents,
93                           unsigned int offset);
94                          
95
96
97     DECLARE_DEBUG_MODULE;
98
99 };
100
101 /**
102  * This class implements the incoming stream processing for
103  * motu devices
104  */
105 class MotuReceiveStreamProcessor
106     : public ReceiveStreamProcessor
107 {
108
109 public:
110
111         MotuReceiveStreamProcessor(int port, int framerate, unsigned int event_size);
112         virtual ~MotuReceiveStreamProcessor();
113        
114         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
115                       unsigned char channel, unsigned char tag, unsigned char sy,
116                           unsigned int cycle, unsigned int dropped);
117        
118         bool init();
119         bool reset();
120         bool prepare();
121         bool transfer();
122        
123         bool isOnePeriodReady();
124
125     // these two are important to calculate the optimal
126     // ISO DMA buffers size
127     // an estimate will do
128         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
129         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
130
131         virtual void setVerboseLevel(int l);
132        
133         signed int setEventSize(unsigned int size);
134         unsigned int getEventSize(void);
135
136 protected:
137
138         int receiveBlock(char *data, unsigned int nevents, unsigned int offset);
139         bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
140         signed int decodeMBLAEventsToPort(MotuAudioPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents);
141
142         freebob_ringbuffer_t * m_event_buffer;
143         char* m_tmp_event_buffer;
144        
145         /*
146          * An iso packet mostly consists of multiple events.  m_event_size
147          * is the size of a single 'event' in bytes.
148          */
149         unsigned int m_event_size;
150
151     DECLARE_DEBUG_MODULE;
152
153 };
154
155 } // end of namespace FreebobStreaming
156
157 #endif /* __FREEBOB_MOTUSTREAMPROCESSOR__ */
158
159
Note: See TracBrowser for help on using the browser.