jamlink.h 2.52 KB
Newer Older
jcaceres's avatar
jcaceres committed
1
2
3
// Written by Juan-Pablo Caceres
// Soundwire Group, 2008

4
5
6
7
8
#ifndef	_JAMLINK_H
#define	_JAMLINK_H

#include <iostream>

jcaceres's avatar
jcaceres committed
9
10
11
12
13
14
15
16
17
18
//JamLink UDP Header:
/************************************************************************/
/* values for the UDP stream type                                       */
/* streamType is a 16-bit value at the head of each UDP stream          */
/* Its bit map is as follows:  (b15-msb)                                */
/* B15:reserved, B14:extended header, B13 Stereo, B12 not 16-bit        */
/* B11-B9: 0-48 Khz, 1-44 Khz, 2-32 Khz, 3-24 Khz,                      */
/*         4-22 Khz, 5-16 Khz, 6-11 Khz, 7-8 Khz                        */      
/* B8-0: Samples in packet                                              */
/************************************************************************/
jcaceres's avatar
jcaceres committed
19
20
21
22
23
const unsigned short ETX_RSVD = (0<<15);
const unsigned short ETX_XTND = (1<<14);
const unsigned short ETX_STEREO = (1<<13);
const unsigned short ETX_MONO = (0<<13);
const unsigned short ETX_16BIT = (0<<12);
jcaceres's avatar
more    
jcaceres committed
24
inline unsigned short ETX_RATE_MASK(const unsigned short a) { a&(0x7<<9); }
jcaceres's avatar
jcaceres committed
25
26
27
28
29
30
31
32
const unsigned short ETX_48KHZ = (0<<9);
const unsigned short ETX_44KHZ = (1<<9);
const unsigned short ETX_32KHZ = (2<<9);
const unsigned short ETX_24KHZ = (3<<9);
const unsigned short ETX_22KHZ = (4<<9);
const unsigned short ETX_16KHZ = (5<<9);
const unsigned short ETX_11KHZ = (6<<9);
const unsigned short ETX_8KHZ  = (7<<9);
jcaceres's avatar
more    
jcaceres committed
33
inline unsigned short  ETX_SPP(const unsigned short a) { (a&0x01FF); } //able to express up to 512 SPP
jcaceres's avatar
jcaceres committed
34
35

/*
jcaceres's avatar
jcaceres committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#define ETX_RSVD (0<<15)
#define ETX_XTND (1<<14)
#define ETX_STEREO (1<<13)
#define ETX_MONO (0<<13)
#define ETX_16BIT (0<<12)
#define ETX_RATE_MASK(a) (a&(0x7<<9))
#define ETX_48KHZ (0<<9)
#define ETX_44KHZ (1<<9)
#define ETX_32KHZ (2<<9)
#define ETX_24KHZ (3<<9)
#define ETX_22KHZ (4<<9)
#define ETX_16KHZ (5<<9)
#define ETX_11KHZ (6<<9)
#define ETX_8KHZ  (7<<9)
jcaceres's avatar
jcaceres committed
50
51
52
#define ETX_SPP(a) (a&0x01FF) // able to express up to 512 SPP
*/

jcaceres's avatar
jcaceres committed
53
54
55
56
57
58
59
60
61

/* Note that the extended header is likely to have 6 more bytes: */
/* 2 for the sequence number, and 4 for a timestamp */

//Instpired on Thinking in C++
//http://www.linuxtopia.org/online_books/programming_books/thinking_in_c++/Chapter03_045.html

// Display a unsigned short (2 bytes) in binary
void printBinary(const unsigned short val);
jcaceres's avatar
jcaceres committed
62
void printBinaryChar(const char* val);
jcaceres's avatar
jcaceres committed
63
64
65
66

#define PR(STR, EXPR) \
  cout << STR; printBinary(EXPR); cout << endl;

jcaceres's avatar
jcaceres committed
67
68
69
#define PRC(STR, EXPR) \
  cout << STR; printBinaryChar(EXPR); cout << endl;

70
71
72
73
//Char byteswaping function
void byteSwap(char* bswp, int len);


74
#endif