| 200 | |
---|
| 201 | /** |
---|
| 202 | * \brief enable/disable ratecontrol |
---|
| 203 | * |
---|
| 204 | * Rate control is nescessary for some types of ports (most notably |
---|
| 205 | * midi). The StreamProcessor that handles the port should call canRead() |
---|
| 206 | * everytime a 'slot' that could be filled with an event passes. The canRead |
---|
| 207 | * function will return true if |
---|
| 208 | * (1) there is an event ready in the buffer |
---|
| 209 | * (2) we are allowed to send an event in this slot |
---|
| 210 | * |
---|
| 211 | * Setting the rate works is done with the slot_interval and the event_interval |
---|
| 212 | * parameters. On every call to canRead(), a counter is decremented with |
---|
| 213 | * slot_interval. If the counter drops below 0, canRead() returns true and resets |
---|
| 214 | * the counter to event_interval. |
---|
| 215 | * |
---|
| 216 | * e.g. for AMDTP midi, we are only allowed to send a midi byte every 320us |
---|
| 217 | * if the SYT interval is 8, there is exactly one midi slot every packet. |
---|
| 218 | * therefore the slot_interval is 1/8000s (=125us), and the event_interval |
---|
| 219 | * is 320us. |
---|
| 220 | * |
---|
| 221 | * Note that the interval parameters are unitless, so you can adapt them |
---|
| 222 | * to your needs. In the AMDTP case for example, when the SYT interval is 32 |
---|
| 223 | * (when the samplerate is 192kHz for example) there are 4 midi slots in |
---|
| 224 | * each packet, making the slot time interval 125us/4 = 31.25us. |
---|
| 225 | * The event time interval stays the same (320us). We can however set the |
---|
| 226 | * slot_interval to 3125 and the event_interval to 32000, as we can choose |
---|
| 227 | * the unit of the counter time step (chosen to be 10ns in this case). |
---|
| 228 | * |
---|
| 229 | * The average argument deserves some attention too. If average is true, we use |
---|
| 230 | * average rate control. This means that on average there will be a delay of |
---|
| 231 | * event_interval between two events, but that sometimes there can be a smaller |
---|
| 232 | * delay. This mode fixes the average rate of the stream. |
---|
| 233 | * If average is false, there will always be a minimal delay of event_interval |
---|
| 234 | * between two events. This means that the maximum rate of the stream is fixed, |
---|
| 235 | * and that the average rate will be lower than (or at max equal to) the rate in |
---|
| 236 | * average mode. |
---|
| 237 | * |
---|
| 238 | * |
---|
| 239 | * \note only works for the E_RingBuffer ports |
---|
| 240 | * \note use before calling init() |
---|
| 241 | * |
---|
| 242 | * @param use set this to true to use rate control |
---|
| 243 | * @param slot_interval the interval between slots |
---|
| 244 | * @param event_interval the interval between events |
---|
| 245 | * @param average use average rate control |
---|
| 246 | * @return true if rate control was enabled/disabled successfully |
---|
| 247 | */ |
---|
| 248 | virtual bool useRateControl(bool use, unsigned int slot_interval, |
---|
| 249 | unsigned int event_interval, bool average); |
---|
| 250 | |
---|
| 251 | bool usingRateControl() { return m_do_ratecontrol;}; ///< are we using rate control? |
---|
| 252 | |
---|
| 253 | /** |
---|
| 254 | * Can we send an event in this slot. subject to rate control and |
---|
| 255 | * byte availability. |
---|
| 256 | * @return true if we can send an event on this slot |
---|
| 257 | */ |
---|
| 258 | bool canRead(); |
---|
| 259 | |
---|