@@ -212,10 +212,7 @@ class TCoreAudioRenderer
212
212
213
213
int fPhysicalInputs ;
214
214
int fPhysicalOutputs ;
215
-
216
- int fDefaultPhysicalInputs ;
217
- int fDefaultPhysicalOutputs ;
218
-
215
+
219
216
float ** fInChannel ;
220
217
float ** fOutChannel ;
221
218
@@ -233,9 +230,10 @@ class TCoreAudioRenderer
233
230
AudioDeviceID fDeviceID ;
234
231
AudioUnit fAUHAL ;
235
232
bool fState ;
236
-
233
+
237
234
OSStatus GetDefaultDeviceAndSampleRate (int inChan, int outChan, int & sample_rate, AudioDeviceID* device)
238
235
{
236
+
239
237
UInt32 theSize = sizeof (UInt32 );
240
238
AudioDeviceID inDefault;
241
239
AudioDeviceID outDefault;
@@ -310,41 +308,10 @@ class TCoreAudioRenderer
310
308
// Otherwise force the one we want...
311
309
SetupSampleRateAux (*device, sample_rate);
312
310
}
311
+ // printf("samplerate %d\n", sample_rate);
313
312
fSampleRate = sample_rate;
314
-
315
- // Get default input total channels
316
- GetTotalChannels (inDefault, fDefaultPhysicalInputs , true );
317
-
318
- // Get default output total channels
319
- GetTotalChannels (outDefault, fDefaultPhysicalOutputs , false );
320
-
321
313
return noErr ;
322
314
}
323
-
324
- OSStatus GetTotalChannels (AudioDeviceID device, int & channelCount, bool isInput)
325
- {
326
- OSStatus err = noErr ;
327
- UInt32 outSize;
328
- Boolean outWritable;
329
-
330
- channelCount = 0 ;
331
- err = AudioDeviceGetPropertyInfo (device, 0 , isInput, kAudioDevicePropertyStreamConfiguration , &outSize, &outWritable);
332
- if (err == noErr ) {
333
- int stream_count = outSize / sizeof (AudioBufferList);
334
- // printf("GetTotalChannels stream_count = %d\n", stream_count);
335
- AudioBufferList* bufferList = new AudioBufferList (); // stack allocation sometimes crashes...
336
- err = AudioDeviceGetProperty (device, 0 , isInput, kAudioDevicePropertyStreamConfiguration , &outSize, bufferList);
337
- if (err == noErr ) {
338
- for (uint i = 0 ; i < bufferList->mNumberBuffers ; i++) {
339
- channelCount += bufferList->mBuffers [i].mNumberChannels ;
340
- // printf("GetTotalChannels stream = %d channels = %d\n", i, bufferList->mBuffers[i].mNumberChannels);
341
- }
342
- }
343
- delete bufferList;
344
- }
345
- // printf("GetTotalChannels channelCount = %d\n", channelCount);
346
- return err;
347
- }
348
315
349
316
OSStatus CreateAggregateDevice (AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, int & sample_rate)
350
317
{
@@ -1011,7 +978,6 @@ class TCoreAudioRenderer
1011
978
:fAggregateDeviceID (-1 ),fAggregatePluginID (-1 ),
1012
979
fDevNumInChans (0 ),fDevNumOutChans(0 ),
1013
980
fPhysicalInputs(0 ), fPhysicalOutputs(0 ),
1014
- fDefaultPhysicalInputs(0 ), fDefaultPhysicalOutputs(0 ),
1015
981
fInChannel(0 ),fOutChannel(0 ),
1016
982
fBufferSize(0 ),fSampleRate(0 ),
1017
983
fIsInJackDevice(false ),
@@ -1028,7 +994,7 @@ class TCoreAudioRenderer
1028
994
1029
995
int GetBufferSize () {return fBufferSize ;}
1030
996
int GetSampleRate () {return fSampleRate ;}
1031
-
997
+
1032
998
static OSStatus RestartProc (AudioObjectID objectID, UInt32 numberAddresses,
1033
999
const AudioObjectPropertyAddress inAddresses[],
1034
1000
void *clientData)
@@ -1227,13 +1193,14 @@ class TCoreAudioRenderer
1227
1193
goto error;
1228
1194
}
1229
1195
}
1230
-
1196
+
1231
1197
err = AudioUnitGetPropertyInfo (fAUHAL , kAudioOutputUnitProperty_ChannelMap , kAudioUnitScope_Input , 1 , &outSize, &isWritable);
1232
1198
if (err != noErr ) {
1233
1199
// printf("Error calling AudioUnitGetPropertyInfo - kAudioOutputUnitProperty_ChannelMap 1\n");
1234
1200
// printError(err);
1235
1201
} else {
1236
1202
fPhysicalInputs = outSize / sizeof (SInt32 );
1203
+ // printf("fPhysicalInputs = %ld\n", fPhysicalInputs);
1237
1204
}
1238
1205
1239
1206
err = AudioUnitGetPropertyInfo (fAUHAL , kAudioOutputUnitProperty_ChannelMap , kAudioUnitScope_Output , 0 , &outSize, &isWritable);
@@ -1242,58 +1209,52 @@ class TCoreAudioRenderer
1242
1209
// printError(err);
1243
1210
} else {
1244
1211
fPhysicalOutputs = outSize / sizeof (SInt32 );
1212
+ // printf("fPhysicalOutputs = %ld\n", fPhysicalOutputs);
1245
1213
}
1246
1214
1247
- {
1215
+ /*
1216
+ Just ignore this case : seems to work without any further change...
1217
+
1218
+ if (outChan > fPhysicalOutputs) {
1219
+ printf("This device hasn't required output channels\n");
1220
+ goto error;
1221
+ }
1222
+ if (inChan > fPhysicalInputs) {
1223
+ printf("This device hasn't required input channels\n");
1224
+ goto error;
1225
+ }
1226
+ */
1227
+
1228
+ if (inChan < fPhysicalInputs ) {
1248
1229
SInt32 chanArr[fPhysicalInputs ];
1249
1230
for (int i = 0 ; i < fPhysicalInputs ; i++) {
1250
1231
chanArr[i] = -1 ;
1251
1232
}
1252
-
1253
- // printf("fDefaultPhysicalInputs %d fPhysicalInputs %d\n", fDefaultPhysicalInputs, fPhysicalInputs);
1254
-
1255
- /*
1256
- If aggregated device, default physical inputs to activate are placed at the begining of the channel list
1257
- The DSP channels will be accessed from 0
1258
- */
1259
- int offset = 0 ;
1260
1233
for (int i = 0 ; i < inChan; i++) {
1261
- chanArr[offset++ ] = i;
1234
+ chanArr[i ] = i;
1262
1235
}
1263
-
1264
1236
AudioUnitSetProperty (fAUHAL , kAudioOutputUnitProperty_ChannelMap , kAudioUnitScope_Input , 1 , chanArr, sizeof (SInt32 ) * fPhysicalInputs );
1265
1237
if (err != noErr ) {
1266
1238
printf (" Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 1\n " );
1267
1239
printError (err);
1268
- goto error;
1269
1240
}
1270
1241
}
1271
-
1272
- {
1242
+
1243
+ if (outChan < fPhysicalOutputs ) {
1273
1244
SInt32 chanArr[fPhysicalOutputs ];
1274
1245
for (int i = 0 ; i < fPhysicalOutputs ; i++) {
1275
1246
chanArr[i] = -1 ;
1276
1247
}
1277
-
1278
- // printf("fDefaultPhysicalOutputs %d fPhysicalOutputs %d\n", fDefaultPhysicalOutputs, fPhysicalOutputs);
1279
-
1280
- /*
1281
- If aggregated device, default physical outputs to activate are placed at the end of the channel list
1282
- The DSP channels will be accessed from offset
1283
- */
1284
- int offset = fPhysicalOutputs - fDefaultPhysicalOutputs ;
1285
1248
for (int i = 0 ; i < outChan; i++) {
1286
- chanArr[offset++ ] = i;
1249
+ chanArr[i ] = i;
1287
1250
}
1288
-
1289
1251
err = AudioUnitSetProperty (fAUHAL , kAudioOutputUnitProperty_ChannelMap , kAudioUnitScope_Output , 0 , chanArr, sizeof (SInt32 ) * fPhysicalOutputs );
1290
1252
if (err != noErr ) {
1291
1253
printf (" Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 0\n " );
1292
1254
printError (err);
1293
- goto error;
1294
1255
}
1295
1256
}
1296
-
1257
+
1297
1258
if (inChan > 0 ) {
1298
1259
outSize = sizeof (AudioStreamBasicDescription);
1299
1260
err = AudioUnitGetProperty (fAUHAL , kAudioUnitProperty_StreamFormat , kAudioUnitScope_Output , 1 , &srcFormat, &outSize);
@@ -1484,8 +1445,8 @@ class TCoreAudioRenderer
1484
1445
fDSP = DSP;
1485
1446
}
1486
1447
1487
- int GetNumInputs () { return fDefaultPhysicalInputs ; }
1488
- int GetNumOutputs () { return fDefaultPhysicalOutputs ; }
1448
+ int GetNumInputs () { return fPhysicalInputs ; }
1449
+ int GetNumOutputs () { return fPhysicalOutputs ; }
1489
1450
1490
1451
};
1491
1452
@@ -1506,7 +1467,7 @@ class coreaudio : public audio {
1506
1467
public:
1507
1468
1508
1469
coreaudio (int srate, int bsize) : fAudioDevice (this ), fSampleRate (srate), fBufferSize (bsize) {}
1509
- coreaudio (int bsize) : fAudioDevice (this ), fSampleRate (-1 ), fBufferSize (bsize) {}
1470
+ coreaudio (int bsize) : fAudioDevice (this ), fSampleRate (-1 ), fBufferSize (bsize) {}
1510
1471
virtual ~coreaudio () { fAudioDevice .Close (); }
1511
1472
1512
1473
virtual bool init (const char * /* name*/ , dsp* DSP)
@@ -1529,12 +1490,12 @@ class coreaudio : public audio {
1529
1490
}
1530
1491
return true ;
1531
1492
}
1532
-
1533
- virtual void stop ()
1493
+
1494
+ virtual void stop ()
1534
1495
{
1535
1496
fAudioDevice .Stop ();
1536
1497
}
1537
-
1498
+
1538
1499
virtual int getBufferSize () { return fAudioDevice .GetBufferSize (); }
1539
1500
virtual int getSampleRate () { return fAudioDevice .GetSampleRate (); }
1540
1501
0 commit comments