SoDaRadio-5.0.3-master:8901fb5
Audio_test.cxx
Go to the documentation of this file.
1 #include <math.h>
2 #include "AudioALSA.hxx"
3 #include "AudioPA.hxx"
4 #include <iostream>
5 #include <time.h>
6 int main(int argc, char * argv[])
7 {
8 
9  // SoDa::AudioALSA audio(48000, SoDa::AudioIfc::FLOAT, false);
10  // SoDa::AudioALSA audioI(48000, SoDa::AudioIfc::INT16, false);
11  // SoDa::AudioALSA audioI(48000, SoDa::AudioIfc::FLOAT);
12  SoDa::AudioIfc * audioI = NULL;
13 
14  if(argc < 2) exit(-1);
15  if(argv[1][0] == 'a') {
16  audioI = new SoDa::AudioALSA(48000, SoDa::AudioIfc::FLOAT);
17  }
18  if(argv[1][0] == 'p') {
19  audioI = new SoDa::AudioPA(48000, SoDa::AudioIfc::FLOAT);
20  }
21 
22 
23  float buf[1000];
24 
25 #define CAPSAMPS (48 * 1000 * 5)
26  float capture_buf[CAPSAMPS];
27 
28  float ang = 0.0;
29  float anginc = 2.0 * 3.14159 * 240.0 / 48000.0;
30  float ai[4];
31 
32  int i;
33  for(i = 0; i < 4; i++) {
34  ai[i] = anginc * ((float) (i + 1));
35  }
36 
37  int j, k;
38  float again = 0.0;
39 
40  for(k = 0; k < 16; k++) {
41  again += 0.08;
42  audioI->setOutGain(again);
43  std::cerr << "Gain set to " << again << std::endl;
44  anginc = ai[k % 4];
45  for(j = 0; j < 48; j++) {
46  for(i = 0; i < 1000; i++) {
47  buf[i] = 0.5 * sin(ang);
48  // ibuf[i] = ((short) (32768.0 * buf[i]));
49  ang += anginc;
50  if(ang > M_PI) ang -= (2.0 * M_PI);
51  }
52 
53  audioI->sendBufferReady(1000);
54 
55  audioI->send(buf, 1000);
56  }
57  // audioI->sleepOut();
58 
59  // now read something from the mic
60  audioI->wakeIn();
61  if(!audioI->recvBufferReady(1000)) {
62  std::cerr << "Wow! the recv buffer isn't ready...." << std::endl;
63  }
64  audioI->recv(capture_buf, CAPSAMPS);
65  audioI->sleepIn();
66 
67  //audioI->wakeOut();
68  // and play the mic stuff back.
69  if(!audioI->sendBufferReady(1000)) {
70  std::cerr << "Wow! the send buffer isn't ready...." << std::endl;
71  }
72  audioI->send(capture_buf, CAPSAMPS);
73  }
74 
75 
76 
77 }
virtual void sleepIn()=0
stop the input stream so that we don&#39;t encounter a buffer overflow while the transmitter is inactive...
#define CAPSAMPS
virtual bool setOutGain(float gain)
set the gain for the output device.
Definition: AudioIfc.hxx:116
virtual int send(void *buf, unsigned int len)=0
send – send a buffer to the audio output
the PortAudio interface class
Definition: AudioPA.hxx:60
virtual int recv(void *buf, unsigned int len, bool block=true)=0
recv – get a buffer of data from the audio input
virtual bool recvBufferReady(unsigned int len)=0
recvBufferReady – is there enough space in the audio device recv buffer for a call from recv...
virtual bool sendBufferReady(unsigned int len)=0
sendBufferReady – is there enough space in the audio device send buffer for a call from send...
ALSA audio interface class.
Definition: AudioALSA.hxx:63
Generic Audio Interface Class.
Definition: AudioIfc.hxx:44
int main(int argc, char *argv[])
Definition: Audio_test.cxx:6
virtual void wakeIn()=0
start the input stream