gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
I2SEndianTest.C
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 
18 /*
19 Author: Matt Flax <flatmax@flatmax.org>
20 Date: 2013.08.05
21 */
22 
23 #include "JackClient.H"
24 #include <iostream>
25 using namespace std;
26 
27 #include <math.h>
28 #include <unistd.h> // for sleep, find something different on Microsoft
29 
30 // following definitions from Jack
31 #define NORMALIZED_FLOAT_MIN -1.0f
32 #define NORMALIZED_FLOAT_MAX 1.0f
33 #define SAMPLE_16BIT_SCALING 32767.0f
34 #define SAMPLE_16BIT_MAX 32767
35 #define SAMPLE_16BIT_MIN -32767
36 #define SAMPLE_16BIT_MAX_F 32767.0f
37 #define SAMPLE_16BIT_MIN_F -32767.0f
38 
39 #define f_round(f) lrintf(f)
40 
41 #define float_16(s, d)\
42  if ((s) <= NORMALIZED_FLOAT_MIN) {\
43  (d) = SAMPLE_16BIT_MIN;\
44  } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
45  (d) = SAMPLE_16BIT_MAX;\
46  } else {\
47  (d) = f_round ((s) * SAMPLE_16BIT_SCALING);\
48  }
49 
50 
51 
54 class TestJackClient : public JackClient {
55  int processAudio(jack_nframes_t nframes) {
56  short dataS[4]={(short)0xaaaa, (short)0xff, (short)0x5555, (short)0xff0};
57  float dataF[4]={(float)dataS[0]/SAMPLE_16BIT_SCALING, (float)dataS[1]/SAMPLE_16BIT_SCALING, (float)dataS[2]/SAMPLE_16BIT_SCALING, (float)dataS[3]/SAMPLE_16BIT_SCALING};
58  // put output data into the buffers
59  for (uint i=0; i<outputPorts.size(); i++) {
60  jack_default_audio_sample_t *out = ( jack_default_audio_sample_t* ) jack_port_get_buffer ( outputPorts[i], nframes );
61  for (int j=0; j<nframes; j++){
62  int index=i+(int)fmod((float)j*2.,4.);
63  out[j]=dataF[index];
64  }
65  }
66 
67 // // do something with the input data
68 // for (uint i=0; i<inputPorts.size(); i++) {
69 // jack_default_audio_sample_t *in = ( jack_default_audio_sample_t* ) jack_port_get_buffer ( inputPorts[i], nframes );
70 // for (uint j=0; j<nframes; j++)
71 // rms+=in[j]*in[j];
72 // }
73  return 0;
74  }
75 };
76 
77 int main(int argc, char *argv[]) {
78 
79 #if __BYTE_ORDER == __LITTLE_ENDIAN
80  cout<<"This system is little endian."<<endl;
81 #elif __BYTE_ORDER == __BIG_ENDIAN
82  cout<<"This system is big endian."<<endl;
83 #endif
84 
85  TestJackClient jackClient; // init the jack client
86 
87  // connect to the jack server
88  int res=jackClient.connect("jack test client");
89  if (res!=0)
90  return JackDebug().evaluateError(res);
91 
92  cout<<"Jack : sample rate set to : "<<jackClient.getSampleRate()<<" Hz"<<endl;
93  cout<<"Jack : block size set to : "<<jackClient.getBlockSize()<<" samples"<<endl;
94 
95  res=jackClient.createPorts("in ", 2, "out ", 2);
96  if (res!=0)
97  return JackDebug().evaluateError(res);
98 
99  // start the client
100  res=jackClient.startClient(2, 2, true);
101  if (res!=0)
102  return JackDebug().evaluateError(res);
103 
104  sleep(60); // sleep for 10 seconds ... Microsoft users may have to use a different sleep function
105  return 0;
106 }
107 
virtual int createPorts(string inName, int inCnt, string outName, int outCnt)
Definition: JackBase.H:277
virtual int getBlockSize()
Definition: JackClient.H:140
virtual int evaluateError(int errorNum)
Definition: Debug.H:132
STL namespace.
int processAudio(jack_nframes_t nframes)
Definition: I2SEndianTest.C:55
virtual int startClient()
Definition: JackClient.H:159
unsigned int uint
Definition: Box.H:28
#define SAMPLE_16BIT_SCALING
Definition: I2SEndianTest.C:33
int main(int argc, char *argv[])
Definition: I2SEndianTest.C:77
int getSampleRate(void) const
Definition: JackBase.H:266
virtual int connect(string clientName_)
Definition: JackClient.H:115
gtkIOStream: /tmp/gtkiostream/applications/I2SEndianTest.C Source File
GTK+ IOStream  Beta