Created
December 3, 2009 11:07
-
-
Save dopuskh3/248072 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: ofSoundStream.cpp | |
=================================================================== | |
--- ofSoundStream.cpp (révision 294) | |
+++ ofSoundStream.cpp (copie de travail) | |
@@ -7,31 +7,31 @@ | |
int nInputChannels; | |
int nOutputChannels; | |
ofAudioEventArgs audioEventArgs; | |
-int receiveAudioBufferAndCallSimpleApp(char *buffer, int bufferSize, void *data); | |
+//int receiveAudioBufferAndCallSimpleApp(char *buffer, int bufferSize, void *data); | |
+int receiveAudioBufferAndCallSimpleApp(void *out, void *in, unsigned int bufferSize, double streamTime, RtAudioStreamStatus status, void * data); | |
//------------------------------------------------------------------------------ | |
-int receiveAudioBufferAndCallSimpleApp(char *buffer, int bufferSize, void *data){ | |
+int receiveAudioBufferAndCallSimpleApp(void *out, void *in, unsigned int bufferSize, double streamTime, RtAudioStreamStatus status, void * data){ | |
// rtAudio uses a system by which the audio | |
// can be of different formats | |
// char, float, etc. | |
// we choose float | |
- float * fPtr = (float *)buffer; | |
- | |
// [zach] memset output to zero before output call | |
// this is because of how rtAudio works: duplex w/ one callback | |
// you need to cut in the middle. if the simpleApp | |
// doesn't produce audio, we pass silence instead of duplex... | |
if (nInputChannels > 0){ | |
+ float *fPtr = (float *)in; | |
if(OFSAptr) | |
OFSAptr->audioReceived(fPtr, bufferSize, nInputChannels); | |
- #ifdef OF_USING_POCO | |
+ #ifdef OF_CORE_EVENTS_ENABLED | |
audioEventArgs.buffer = fPtr; | |
audioEventArgs.bufferSize = bufferSize; | |
audioEventArgs.nChannels = nInputChannels; | |
@@ -41,10 +41,11 @@ | |
memset(fPtr, 0, bufferSize * nInputChannels * sizeof(float)); | |
} | |
if (nOutputChannels > 0){ | |
+ float *fPtr = (float *)out; | |
if(OFSAptr) | |
OFSAptr->audioRequested(fPtr, bufferSize, nOutputChannels); | |
- #ifdef OF_USING_POCO | |
+ #ifdef OF_CORE_EVENTS_ENABLED | |
audioEventArgs.buffer = fPtr; | |
audioEventArgs.bufferSize = bufferSize; | |
audioEventArgs.nChannels = nOutputChannels; | |
@@ -73,20 +74,37 @@ | |
nOutputChannels = nOutputs; | |
int device = 0; // default | |
OFSAptr = OFSA; | |
+ struct RtAudio::StreamParameters *inputStreamParams = NULL; | |
+ struct RtAudio::StreamParameters * outputStreamParams = NULL; | |
+ unsigned int bsize = (unsigned int )bufferSize; | |
+ | |
+ if(nOutputs != 0){ | |
+ outputStreamParams = new RtAudio::StreamParameters(); | |
+ outputStreamParams->deviceId = device; | |
+ outputStreamParams->nChannels = nOutputs; | |
+ } | |
+ if(nInputs != 0){ | |
+ inputStreamParams = new RtAudio::StreamParameters(); | |
+ inputStreamParams->deviceId = device; | |
+ inputStreamParams->nChannels = nInputs; | |
+ } | |
+ | |
+ struct RtAudio::StreamOptions *options = new RtAudio::StreamOptions(); | |
+ options->numberOfBuffers = nBuffers; | |
+ | |
bufferSize = ofNextPow2(bufferSize); // must be pow2 | |
try { | |
audio = new RtAudio(); | |
- audio->openStream( device, nOutputs, device, nInputs, RTAUDIO_FLOAT32, | |
- sampleRate, &bufferSize, nBuffers); | |
+ audio->openStream( outputStreamParams, inputStreamParams, RTAUDIO_FLOAT32, | |
+ sampleRate, &bsize, &receiveAudioBufferAndCallSimpleApp, (void *)NULL, options); | |
} catch (RtError &error) { | |
error.printMessage(); | |
//std::exit(EXIT_FAILURE); // need case here | |
} | |
- | |
try { | |
- audio->setStreamCallback(&receiveAudioBufferAndCallSimpleApp, (void *)NULL); | |
+ //audio->setStreamCallback(&receiveAudioBufferAndCallSimpleApp, (void *)NULL); | |
audio->startStream(); | |
} catch (RtError &error) { | |
error.printMessage(); | |
@@ -135,7 +153,7 @@ | |
error.printMessage(); | |
} | |
int devices = audioTemp->getDeviceCount(); | |
- RtAudioDeviceInfo info; | |
+ RtAudio::DeviceInfo info; | |
for (int i=1; i<=devices; i++) { | |
try { | |
info = audioTemp->getDeviceInfo(i); | |
@@ -144,7 +162,8 @@ | |
break; | |
} | |
std::cout << "device = " << i << " (" << info.name << ")\n"; | |
- if (info.isDefault) std::cout << "----* default ----* \n"; | |
+ if (info.isDefaultOutput) std::cout << "----* default output ----* \n"; | |
+ if (info.isDefaultInput) std::cout << "----* default input ----* \n"; | |
std::cout << "maximum output channels = " << info.outputChannels << "\n"; | |
std::cout << "maximum input channels = " << info.inputChannels << "\n"; | |
std::cout << "-----------------------------------------\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment