diff options
Diffstat (limited to 'src/test/portaudiotestold.cpp')
-rw-r--r-- | src/test/portaudiotestold.cpp | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/src/test/portaudiotestold.cpp b/src/test/portaudiotestold.cpp new file mode 100644 index 0000000..954c64e --- /dev/null +++ b/src/test/portaudiotestold.cpp | |||
@@ -0,0 +1,157 @@ | |||
1 | using namespace std; | ||
2 | #include <iostream> | ||
3 | #include <portaudio.h> | ||
4 | #include "portaudiotest.h" | ||
5 | #define PA_FRAMESPERBUF 512 | ||
6 | #define __uint32 unsigned long | ||
7 | |||
8 | int HD24UserInterface::portaudio_process( | ||
9 | const void *inputBuffer, | ||
10 | void *outputBuffer, | ||
11 | __uint32 nframes, | ||
12 | const PaStreamCallbackTimeInfo* timeinfo, | ||
13 | PaStreamCallbackFlags, | ||
14 | void *userData) | ||
15 | { | ||
16 | HD24UserInterface* mythis=(HD24UserInterface*)userData; | ||
17 | const PaStreamInfo* streaminfo=Pa_GetStreamInfo(mythis->portaudiostream); | ||
18 | double samplerate=streaminfo->sampleRate; | ||
19 | if (!mythis->havestreamtime) | ||
20 | { | ||
21 | mythis->streamtime=0; | ||
22 | mythis->havestreamtime=true; | ||
23 | } | ||
24 | mythis->streamtime+=nframes; | ||
25 | for (int i=0;i<nframes*2;i++) | ||
26 | { | ||
27 | float sval=(((i%20)/20)-.5); | ||
28 | ((float*)(outputBuffer))[i]=sval; | ||
29 | } | ||
30 | return paContinue; | ||
31 | } | ||
32 | |||
33 | |||
34 | void HD24UserInterface::portaudioinit() | ||
35 | { | ||
36 | cout << "portaudioinit" << endl; | ||
37 | PaError err; | ||
38 | inputParameters=new PaStreamParameters; | ||
39 | outputParameters=new PaStreamParameters; | ||
40 | err=Pa_Initialize(); | ||
41 | if (err!=paNoError) | ||
42 | { | ||
43 | Pa_Terminate(); | ||
44 | return; | ||
45 | } | ||
46 | m_isportaudioinitialized=true; | ||
47 | } | ||
48 | |||
49 | HD24UserInterface::HD24UserInterface() | ||
50 | { | ||
51 | m_isportaudioinitialized=false; | ||
52 | portaudiostream=NULL; | ||
53 | return; | ||
54 | } | ||
55 | |||
56 | bool HD24UserInterface::isportaudioinitialized() | ||
57 | { | ||
58 | return m_isportaudioinitialized; | ||
59 | } | ||
60 | |||
61 | void HD24UserInterface::portaudio_transport_start() | ||
62 | { | ||
63 | |||
64 | cout << "portaudio transport start" << endl; | ||
65 | |||
66 | if (!isportaudioinitialized()) | ||
67 | { | ||
68 | PaError err=Pa_Initialize(); | ||
69 | if (err != paNoError) | ||
70 | { | ||
71 | cout << "Cannot initialize portaudio- exiting." << endl; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | if (isportaudioinitialized() && (portaudiostream!=NULL)) | ||
76 | { | ||
77 | cout << "already have stream- done starting" << endl; | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | PaDeviceIndex indevice=Pa_GetDefaultInputDevice(); | ||
82 | bzero(inputParameters,sizeof(*inputParameters)); | ||
83 | inputParameters->device=indevice; | ||
84 | inputParameters->channelCount=1; | ||
85 | inputParameters->sampleFormat=paFloat32; | ||
86 | inputParameters->suggestedLatency = Pa_GetDeviceInfo( inputParameters->device )->defaultLowInputLatency; | ||
87 | inputParameters->hostApiSpecificStreamInfo = NULL; | ||
88 | |||
89 | cout << "Input params set" << endl; | ||
90 | cout << "Device=" << inputParameters->device << endl; | ||
91 | cout << "Channelcount=" << inputParameters->channelCount << endl; | ||
92 | cout << "sampleFormat=" << inputParameters->sampleFormat << endl; | ||
93 | cout << "suggestedlatency=" << inputParameters->suggestedLatency << endl; | ||
94 | cout << "================================="<<endl; | ||
95 | bzero(outputParameters,sizeof(*outputParameters)); | ||
96 | PaDeviceIndex outdevice=Pa_GetDefaultOutputDevice(); | ||
97 | outputParameters->device=outdevice; | ||
98 | outputParameters->channelCount=1; | ||
99 | outputParameters->sampleFormat=paFloat32; | ||
100 | outputParameters->suggestedLatency = Pa_GetDeviceInfo( outputParameters->device )->defaultLowOutputLatency; | ||
101 | outputParameters->hostApiSpecificStreamInfo = NULL; | ||
102 | |||
103 | cout << "Output params set" << endl; | ||
104 | cout << "Device=" << outputParameters->device << endl; | ||
105 | cout << "Channelcount=" << outputParameters->channelCount << endl; | ||
106 | cout << "sampleFormat=" << outputParameters->sampleFormat << endl; | ||
107 | cout << "suggestedlatency=" << outputParameters->suggestedLatency << endl; | ||
108 | cout << "================================="<<endl; | ||
109 | |||
110 | double samrate=44100; | ||
111 | cout << "trying samerate="<<samrate<<endl; | ||
112 | cout << "framesperbuf=" << PA_FRAMESPERBUF << endl; | ||
113 | |||
114 | PaError err=Pa_OpenStream( | ||
115 | &portaudiostream, | ||
116 | this->inputParameters, | ||
117 | this->outputParameters, | ||
118 | samrate, | ||
119 | PA_FRAMESPERBUF, /* frames per buffer */ | ||
120 | paClipOff | paDitherOff, | ||
121 | portaudio_process, | ||
122 | (void*)this); | ||
123 | this->havestreamtime=false; | ||
124 | |||
125 | if (err!=paNoError) | ||
126 | { | ||
127 | cout << "Error opening stream" << endl; | ||
128 | Pa_Terminate(); | ||
129 | return; | ||
130 | } | ||
131 | |||
132 | cout << "Stream opened, going to start it now..." << endl; | ||
133 | |||
134 | err=Pa_StartStream(portaudiostream); | ||
135 | |||
136 | if (err!=paNoError) | ||
137 | { | ||
138 | cout << "Error starting stream" << endl; | ||
139 | Pa_Terminate(); | ||
140 | return; | ||
141 | } | ||
142 | |||
143 | cout << "Stream started" << endl; | ||
144 | |||
145 | return; | ||
146 | } | ||
147 | |||
148 | int main() | ||
149 | { | ||
150 | HD24UserInterface* ui=new HD24UserInterface(); | ||
151 | ui->portaudioinit(); | ||
152 | ui->portaudio_transport_start(); | ||
153 | int blah; | ||
154 | cin >> blah; | ||
155 | |||
156 | } | ||
157 | |||