SF.net SVN: supercollider: [7679] trunk

View: New views
1 Messages — Rating Filter:   Alert me  

SF.net SVN: supercollider: [7679] trunk

by danstowell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Revision: 7679
          http://supercollider.svn.sourceforge.net/supercollider/?rev=7679&view=rev
Author:   danstowell
Date:     2008-07-12 15:37:18 -0700 (Sat, 12 Jul 2008)

Log Message:
-----------
Patch for scsynth to use separate I/O devices, without Aggregate Devices. Thanks to Axel Balley for this.

Modified Paths:
--------------
    trunk/Source/server/SC_CoreAudio.cpp
    trunk/build/ChangeLog

Modified: trunk/Source/server/SC_CoreAudio.cpp
===================================================================
--- trunk/Source/server/SC_CoreAudio.cpp 2008-07-12 22:30:01 UTC (rev 7678)
+++ trunk/Source/server/SC_CoreAudio.cpp 2008-07-12 22:37:18 UTC (rev 7679)
@@ -816,11 +816,13 @@
  now.mFlags = kAudioTimeStampHostTimeValid;
  now.mHostTime = AudioGetCurrentHostTime();
 
+ /*
  err = AudioDeviceSetProperty(mInputDevice, &now, 0, true, kAudioDevicePropertyRegisterBufferList, count, mInputBufList);
  if (err != kAudioHardwareNoError) {
  scprintf("get kAudioDevicePropertyRegisterBufferList error %4.4s\n", (char*)&err);
  return false;
  }
+ */
  }
 
  *outNumSamplesPerCallback = mHardwareBufferSize / outputStreamDesc.mBytesPerFrame;
@@ -832,16 +834,16 @@
  return true;
 }
 
-// this is the audio processing callback for two separate devices.
+/*
 OSStatus appIOProc2 (AudioDeviceID inDevice, const AudioTimeStamp* inNow,
  const AudioBufferList* inInputData,
  const AudioTimeStamp* inInputTime,
  AudioBufferList* outOutputData,
  const AudioTimeStamp* inOutputTime,
  void* defptr);
-OSStatus appIOProc2 (AudioDeviceID /*inDevice*/, const AudioTimeStamp* inNow,
+OSStatus appIOProc2 (AudioDeviceID inDevice, const AudioTimeStamp* inNow,
  const AudioBufferList* inInputData,
- const AudioTimeStamp* /*inInputTime*/,
+ const AudioTimeStamp* inInputTime,
  AudioBufferList* outOutputData,
  const AudioTimeStamp* inOutputTime,
  void* defptr)
@@ -860,7 +862,9 @@
 
  return kAudioHardwareNoError;
 }
+*/
 
+static const AudioBufferList* lastInputData = 0;
 
 // this is the audio processing callback for one device.
 OSStatus appIOProc (AudioDeviceID inDevice, const AudioTimeStamp* inNow,
@@ -869,7 +873,7 @@
  AudioBufferList* outOutputData,
  const AudioTimeStamp* inOutputTime,
  void* defptr);
-OSStatus appIOProc (AudioDeviceID /*inDevice*/, const AudioTimeStamp* inNow,
+OSStatus appIOProc (AudioDeviceID device, const AudioTimeStamp* inNow,
  const AudioBufferList* inInputData,
  const AudioTimeStamp* inInputTime,
  AudioBufferList* outOutputData,
@@ -877,7 +881,6 @@
  void* defptr)
 {
  SC_CoreAudioDriver* def = (SC_CoreAudioDriver*)defptr;
-
  int64 oscTime = CoreAudioHostTimeToOSC(inOutputTime->mHostTime);
 
  double hostSecs = (double)AudioConvertHostTimeToNanos(inOutputTime->mHostTime) * 1e-9;
@@ -904,9 +907,20 @@
  }
  def->mPrevHostSecs = hostSecs;
  def->mPrevSampleTime = sampleTime;
+
+ if (!def->UseSeparateIO())
+ {
+ def->Run(inInputData, outOutputData, oscTime);
+ return kAudioHardwareNoError;
+ }
+
+ if (device==def->mInputDevice) lastInputData = inInputData;
+ else
+ {
+ def->Run(lastInputData, outOutputData, oscTime);
+ lastInputData = 0;
+ }
 
- def->Run(inInputData, outOutputData, oscTime);
-
  return kAudioHardwareNoError;
 }
 
@@ -981,7 +995,6 @@
  }
  }
  //count++;
-
 
  int64 schedTime;
  int64 nextTime = oscTime + oscInc;
@@ -1034,7 +1047,7 @@
  }
  b += nchan;
  }
- }
+ }
  oscTime = mOSCbuftime = nextTime;
  }
  } catch (std::exception& exc) {
@@ -1071,16 +1084,35 @@
 
  try {
  if (UseSeparateIO()) {
- err = AudioDeviceAddIOProc(mOutputDevice, appIOProc2, (void *) this); // setup our device with an IO proc
+ err = AudioDeviceAddIOProc(mOutputDevice, appIOProc, (void *) this); // setup Out device with an IO proc
  if (err != kAudioHardwareNoError) {
  scprintf("AudioDeviceAddIOProc failed %s %d\n", &err, (int)err);
  return false;
  }
 
+ err = AudioDeviceAddIOProc(mInputDevice, appIOProc, (void *) this); // setup In device with an IO proc
+ if (err != kAudioHardwareNoError) {
+ scprintf("AudioDeviceAddIOProc failed %s %d\n", &err, (int)err);
+ return false;
+ }
+
+
+ if (mWorld->hw->mInputStreamsEnabled) {
+ err = AudioDeviceGetPropertyInfo(mInputDevice, 0, true, kAudioDevicePropertyIOProcStreamUsage, &propertySize, &writable);
+ AudioHardwareIOProcStreamUsage *su = (AudioHardwareIOProcStreamUsage*)malloc(propertySize);
+ su->mIOProc = (void*)appIOProc;
+ err = AudioDeviceGetProperty(mInputDevice, 0, true, kAudioDevicePropertyIOProcStreamUsage, &propertySize, su);
+ int len = std::min(su->mNumberStreams, strlen(mWorld->hw->mInputStreamsEnabled));
+ for (int i=0; i<len; ++i) {
+ su->mStreamIsOn[i] = mWorld->hw->mInputStreamsEnabled[i] == '1';
+ }
+ err = AudioDeviceSetProperty(mInputDevice, &now, 0, true, kAudioDevicePropertyIOProcStreamUsage, propertySize, su);
+ }
+
  if (mWorld->hw->mOutputStreamsEnabled) {
  err = AudioDeviceGetPropertyInfo(mOutputDevice, 0, false, kAudioDevicePropertyIOProcStreamUsage, &propertySize, &writable);
  AudioHardwareIOProcStreamUsage *su = (AudioHardwareIOProcStreamUsage*)malloc(propertySize);
- su->mIOProc = (void*)appIOProc2;
+ su->mIOProc = (void*)appIOProc;
  err = AudioDeviceGetProperty(mOutputDevice, 0, false, kAudioDevicePropertyIOProcStreamUsage, &propertySize, su);
  int len = std::min(su->mNumberStreams, strlen(mWorld->hw->mOutputStreamsEnabled));
  for (int i=0; i<len; ++i) {
@@ -1089,16 +1121,16 @@
  err = AudioDeviceSetProperty(mOutputDevice, &now, 0, false, kAudioDevicePropertyIOProcStreamUsage, propertySize, su);
  }
 
- err = AudioDeviceStart(mInputDevice, NULL); // start playing sound through the device
+ err = AudioDeviceStart(mInputDevice, appIOProc); // start playing sound through the device
  if (err != kAudioHardwareNoError) {
  scprintf("AudioDeviceStart failed %d\n", (int)err);
  return false;
  }
 
- err = AudioDeviceStart(mOutputDevice, appIOProc2); // start playing sound through the device
+ err = AudioDeviceStart(mOutputDevice, appIOProc); // start playing sound through the device
  if (err != kAudioHardwareNoError) {
  scprintf("AudioDeviceStart failed %d\n", (int)err);
- err = AudioDeviceStop(mInputDevice, NULL); // stop playing sound through the device
+ err = AudioDeviceStop(mInputDevice, appIOProc); // stop playing sound through the device
  return false;
  }
  } else {
@@ -1155,16 +1187,28 @@
  OSStatus err = kAudioHardwareNoError;
 
  if (UseSeparateIO()) {
- err = AudioDeviceStop(mOutputDevice, appIOProc2);
+ err = AudioDeviceStop(mInputDevice, appIOProc);
  if (err != kAudioHardwareNoError) {
  scprintf("AudioDeviceStop A failed %08X\n", err);
  return false;
  }
- err = AudioDeviceRemoveIOProc(mOutputDevice, appIOProc2);
+
+ err = AudioDeviceRemoveIOProc(mInputDevice, appIOProc);
  if (err != kAudioHardwareNoError) {
  scprintf("AudioDeviceRemoveIOProc A failed %08X\n", err);
  return false;
  }
+
+ err = AudioDeviceStop(mOutputDevice, appIOProc);
+ if (err != kAudioHardwareNoError) {
+ scprintf("AudioDeviceStop A failed %08X\n", err);
+ return false;
+ }
+ err = AudioDeviceRemoveIOProc(mOutputDevice, appIOProc);
+ if (err != kAudioHardwareNoError) {
+ scprintf("AudioDeviceRemoveIOProc A failed %08X\n", err);
+ return false;
+ }
  } else {
  err = AudioDeviceStop(mOutputDevice, appIOProc);
  if (err != kAudioHardwareNoError) {

Modified: trunk/build/ChangeLog
===================================================================
--- trunk/build/ChangeLog 2008-07-12 22:30:01 UTC (rev 7678)
+++ trunk/build/ChangeLog 2008-07-12 22:37:18 UTC (rev 7679)
@@ -4,6 +4,7 @@
 
 // HEADLINES:
 * 2008-04-20 improvements to MIDI sysex handling - added sysex parsing directly in source - thanks to charles picasso
+* 2008-07-12 scsynth on Mac can now use separate devices for audio input vs audio output. Thanks to Axel Balley for much of the work on this, also a bit by ds.
 
 // BUGFIXES:
 * 2008-05-20 fix for the special case when 0.2.asFraction beachballs the lang (bug id 1856972) - jr


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

_______________________________________________
sc-dev mailing list

info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/
LightInTheBox - Buy quality products at wholesale price