@@ -7897,13 +7897,15 @@ void RtApiAlsa :: probeDevices( void )
7897
7897
deviceID_prettyName.push_back ({" default" , " Default ALSA Device" });
7898
7898
defaultDeviceName = deviceID_prettyName[0 ].second ;
7899
7899
snd_ctl_close ( handle );
7900
+ snd_config_update_free_global ();
7900
7901
}
7901
7902
7902
7903
// Add the Pulse interface if available.
7903
7904
result = snd_ctl_open ( &handle, " pulse" , 0 );
7904
7905
if (result == 0 ) {
7905
7906
deviceID_prettyName.push_back ({" pulse" , " PulseAudio Sound Server" });
7906
7907
snd_ctl_close ( handle );
7908
+ snd_config_update_free_global ();
7907
7909
}
7908
7910
7909
7911
// Count cards and devices and get ascii identifiers.
@@ -7966,8 +7968,10 @@ void RtApiAlsa :: probeDevices( void )
7966
7968
defaultDeviceName = name;
7967
7969
}
7968
7970
nextcard:
7969
- if ( handle )
7971
+ if ( handle ) {
7970
7972
snd_ctl_close ( handle );
7973
+ snd_config_update_free_global ();
7974
+ }
7971
7975
snd_card_next ( &card );
7972
7976
}
7973
7977
@@ -8066,6 +8070,7 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8066
8070
result = snd_pcm_hw_params_any ( phandle, params );
8067
8071
if ( result < 0 ) {
8068
8072
snd_pcm_close ( phandle );
8073
+ snd_config_update_free_global ();
8069
8074
errorStream_ << " RtApiAlsa::probeDeviceInfo: snd_pcm_hw_params error for device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8070
8075
errorText_ = errorStream_.str ();
8071
8076
error ( RTAUDIO_WARNING );
@@ -8077,13 +8082,15 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8077
8082
result = snd_pcm_hw_params_get_channels_max ( params, &value );
8078
8083
if ( result < 0 ) {
8079
8084
snd_pcm_close ( phandle );
8085
+ snd_config_update_free_global ();
8080
8086
errorStream_ << " RtApiAlsa::probeDeviceInfo: error getting device (" << name << " ) output channels, " << snd_strerror ( result ) << " ." ;
8081
8087
errorText_ = errorStream_.str ();
8082
8088
error ( RTAUDIO_WARNING );
8083
8089
goto captureProbe;
8084
8090
}
8085
8091
info.outputChannels = value;
8086
8092
snd_pcm_close ( phandle );
8093
+ snd_config_update_free_global ();
8087
8094
8088
8095
captureProbe:
8089
8096
stream = SND_PCM_STREAM_CAPTURE;
@@ -8102,6 +8109,7 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8102
8109
result = snd_pcm_hw_params_any ( phandle, params );
8103
8110
if ( result < 0 ) {
8104
8111
snd_pcm_close ( phandle );
8112
+ snd_config_update_free_global ();
8105
8113
errorStream_ << " RtApiAlsa::probeDeviceInfo: snd_pcm_hw_params error for device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8106
8114
errorText_ = errorStream_.str ();
8107
8115
error ( RTAUDIO_WARNING );
@@ -8112,6 +8120,7 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8112
8120
result = snd_pcm_hw_params_get_channels_max ( params, &value );
8113
8121
if ( result < 0 ) {
8114
8122
snd_pcm_close ( phandle );
8123
+ snd_config_update_free_global ();
8115
8124
errorStream_ << " RtApiAlsa::probeDeviceInfo: error getting device (" << name << " ) input channels, " << snd_strerror ( result ) << " ." ;
8116
8125
errorText_ = errorStream_.str ();
8117
8126
error ( RTAUDIO_WARNING );
@@ -8120,6 +8129,7 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8120
8129
}
8121
8130
info.inputChannels = value;
8122
8131
snd_pcm_close ( phandle );
8132
+ snd_config_update_free_global ();
8123
8133
8124
8134
// If device opens for both playback and capture, we determine the channels.
8125
8135
if ( info.outputChannels > 0 && info.inputChannels > 0 )
@@ -8149,6 +8159,7 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8149
8159
result = snd_pcm_hw_params_any ( phandle, params );
8150
8160
if ( result < 0 ) {
8151
8161
snd_pcm_close ( phandle );
8162
+ snd_config_update_free_global ();
8152
8163
errorStream_ << " RtApiAlsa::probeDeviceInfo: snd_pcm_hw_params error for device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8153
8164
errorText_ = errorStream_.str ();
8154
8165
error ( RTAUDIO_WARNING );
@@ -8167,6 +8178,7 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8167
8178
}
8168
8179
if ( info.sampleRates .size () == 0 ) {
8169
8180
snd_pcm_close ( phandle );
8181
+ snd_config_update_free_global ();
8170
8182
errorStream_ << " RtApiAlsa::probeDeviceInfo: no supported sample rates found for device (" << name << " )." ;
8171
8183
errorText_ = errorStream_.str ();
8172
8184
error ( RTAUDIO_WARNING );
@@ -8198,6 +8210,7 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8198
8210
// Check that we have at least one supported format
8199
8211
if ( info.nativeFormats == 0 ) {
8200
8212
snd_pcm_close ( phandle );
8213
+ snd_config_update_free_global ();
8201
8214
errorStream_ << " RtApiAlsa::probeDeviceInfo: pcm device (" << name << " ) data format not supported by RtAudio." ;
8202
8215
errorText_ = errorStream_.str ();
8203
8216
error ( RTAUDIO_WARNING );
@@ -8206,6 +8219,7 @@ bool RtApiAlsa :: probeDeviceInfo( RtAudio::DeviceInfo& info, std::string name )
8206
8219
8207
8220
// Close the device and return
8208
8221
snd_pcm_close ( phandle );
8222
+ snd_config_update_free_global ();
8209
8223
return true ;
8210
8224
}
8211
8225
@@ -8256,6 +8270,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8256
8270
result = snd_pcm_hw_params_any ( phandle, hw_params );
8257
8271
if ( result < 0 ) {
8258
8272
snd_pcm_close ( phandle );
8273
+ snd_config_update_free_global ();
8259
8274
errorStream_ << " RtApiAlsa::probeDeviceOpen: error getting pcm device (" << name << " ) parameters, " << snd_strerror ( result ) << " ." ;
8260
8275
errorText_ = errorStream_.str ();
8261
8276
return FAILURE;
@@ -8290,6 +8305,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8290
8305
8291
8306
if ( result < 0 ) {
8292
8307
snd_pcm_close ( phandle );
8308
+ snd_config_update_free_global ();
8293
8309
errorStream_ << " RtApiAlsa::probeDeviceOpen: error setting pcm device (" << name << " ) access, " << snd_strerror ( result ) << " ." ;
8294
8310
errorText_ = errorStream_.str ();
8295
8311
return FAILURE;
@@ -8356,6 +8372,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8356
8372
8357
8373
// If we get here, no supported format was found.
8358
8374
snd_pcm_close ( phandle );
8375
+ snd_config_update_free_global ();
8359
8376
errorStream_ << " RtApiAlsa::probeDeviceOpen: pcm device (" << name << " ) data format not supported by RtAudio." ;
8360
8377
errorText_ = errorStream_.str ();
8361
8378
return FAILURE;
@@ -8364,6 +8381,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8364
8381
result = snd_pcm_hw_params_set_format ( phandle, hw_params, deviceFormat );
8365
8382
if ( result < 0 ) {
8366
8383
snd_pcm_close ( phandle );
8384
+ snd_config_update_free_global ();
8367
8385
errorStream_ << " RtApiAlsa::probeDeviceOpen: error setting pcm device (" << name << " ) data format, " << snd_strerror ( result ) << " ." ;
8368
8386
errorText_ = errorStream_.str ();
8369
8387
return FAILURE;
@@ -8377,6 +8395,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8377
8395
stream_.doByteSwap [mode] = true ;
8378
8396
else if (result < 0 ) {
8379
8397
snd_pcm_close ( phandle );
8398
+ snd_config_update_free_global ();
8380
8399
errorStream_ << " RtApiAlsa::probeDeviceOpen: error getting pcm device (" << name << " ) endian-ness, " << snd_strerror ( result ) << " ." ;
8381
8400
errorText_ = errorStream_.str ();
8382
8401
return FAILURE;
@@ -8387,6 +8406,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8387
8406
result = snd_pcm_hw_params_set_rate_near ( phandle, hw_params, (unsigned int *) &sampleRate, 0 );
8388
8407
if ( result < 0 ) {
8389
8408
snd_pcm_close ( phandle );
8409
+ snd_config_update_free_global ();
8390
8410
errorStream_ << " RtApiAlsa::probeDeviceOpen: error setting sample rate on device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8391
8411
errorText_ = errorStream_.str ();
8392
8412
return FAILURE;
@@ -8400,6 +8420,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8400
8420
unsigned int deviceChannels = value;
8401
8421
if ( result < 0 || deviceChannels < channels + firstChannel ) {
8402
8422
snd_pcm_close ( phandle );
8423
+ snd_config_update_free_global ();
8403
8424
errorStream_ << " RtApiAlsa::probeDeviceOpen: requested channel parameters not supported by device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8404
8425
errorText_ = errorStream_.str ();
8405
8426
return FAILURE;
@@ -8408,6 +8429,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8408
8429
result = snd_pcm_hw_params_get_channels_min ( hw_params, &value );
8409
8430
if ( result < 0 ) {
8410
8431
snd_pcm_close ( phandle );
8432
+ snd_config_update_free_global ();
8411
8433
errorStream_ << " RtApiAlsa::probeDeviceOpen: error getting minimum channels for device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8412
8434
errorText_ = errorStream_.str ();
8413
8435
return FAILURE;
@@ -8420,6 +8442,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8420
8442
result = snd_pcm_hw_params_set_channels ( phandle, hw_params, deviceChannels );
8421
8443
if ( result < 0 ) {
8422
8444
snd_pcm_close ( phandle );
8445
+ snd_config_update_free_global ();
8423
8446
errorStream_ << " RtApiAlsa::probeDeviceOpen: error setting channels for device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8424
8447
errorText_ = errorStream_.str ();
8425
8448
return FAILURE;
@@ -8431,6 +8454,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8431
8454
result = snd_pcm_hw_params_set_period_size_near ( phandle, hw_params, &periodSize, &dir );
8432
8455
if ( result < 0 ) {
8433
8456
snd_pcm_close ( phandle );
8457
+ snd_config_update_free_global ();
8434
8458
errorStream_ << " RtApiAlsa::probeDeviceOpen: error setting period size for device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8435
8459
errorText_ = errorStream_.str ();
8436
8460
return FAILURE;
@@ -8445,6 +8469,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8445
8469
result = snd_pcm_hw_params_set_periods_near ( phandle, hw_params, &periods, &dir );
8446
8470
if ( result < 0 ) {
8447
8471
snd_pcm_close ( phandle );
8472
+ snd_config_update_free_global ();
8448
8473
errorStream_ << " RtApiAlsa::probeDeviceOpen: error setting periods for device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8449
8474
errorText_ = errorStream_.str ();
8450
8475
return FAILURE;
@@ -8454,6 +8479,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8454
8479
// MUST be the same in both directions!
8455
8480
if ( stream_.mode == OUTPUT && mode == INPUT && *bufferSize != stream_.bufferSize ) {
8456
8481
snd_pcm_close ( phandle );
8482
+ snd_config_update_free_global ();
8457
8483
errorStream_ << " RtApiAlsa::probeDeviceOpen: system error setting buffer size for duplex stream on device (" << name << " )." ;
8458
8484
errorText_ = errorStream_.str ();
8459
8485
return FAILURE;
@@ -8465,6 +8491,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8465
8491
result = snd_pcm_hw_params ( phandle, hw_params );
8466
8492
if ( result < 0 ) {
8467
8493
snd_pcm_close ( phandle );
8494
+ snd_config_update_free_global ();
8468
8495
errorStream_ << " RtApiAlsa::probeDeviceOpen: error installing hardware configuration on device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8469
8496
errorText_ = errorStream_.str ();
8470
8497
return FAILURE;
@@ -8496,6 +8523,7 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8496
8523
result = snd_pcm_sw_params ( phandle, sw_params );
8497
8524
if ( result < 0 ) {
8498
8525
snd_pcm_close ( phandle );
8526
+ snd_config_update_free_global ();
8499
8527
errorStream_ << " RtApiAlsa::probeDeviceOpen: error installing software configuration on device (" << name << " ), " << snd_strerror ( result ) << " ." ;
8500
8528
errorText_ = errorStream_.str ();
8501
8529
return FAILURE;
@@ -8647,18 +8675,32 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
8647
8675
}
8648
8676
}
8649
8677
8678
+ snd_config_update_free_global ();
8650
8679
return SUCCESS;
8651
8680
8652
8681
error:
8653
8682
if ( apiInfo ) {
8654
8683
pthread_cond_destroy ( &apiInfo->runnable_cv );
8655
- if ( apiInfo->handles [0 ] ) snd_pcm_close ( apiInfo->handles [0 ] );
8656
- if ( apiInfo->handles [1 ] ) snd_pcm_close ( apiInfo->handles [1 ] );
8684
+ bool pcm_closed = false ;
8685
+ if ( apiInfo->handles [0 ] ) {
8686
+ snd_pcm_close ( apiInfo->handles [0 ] );
8687
+ pcm_closed = true ;
8688
+ }
8689
+ if ( apiInfo->handles [1 ] ) {
8690
+ snd_pcm_close ( apiInfo->handles [1 ] );
8691
+ pcm_closed = true ;
8692
+ }
8693
+ if ( pcm_closed ) {
8694
+ snd_config_update_free_global ();
8695
+ }
8657
8696
delete apiInfo;
8658
8697
stream_.apiHandle = 0 ;
8659
8698
}
8660
8699
8661
- if ( phandle) snd_pcm_close ( phandle );
8700
+ if ( phandle) {
8701
+ snd_pcm_close ( phandle );
8702
+ snd_config_update_free_global ();
8703
+ }
8662
8704
8663
8705
for ( int i=0 ; i<2 ; i++ ) {
8664
8706
if ( stream_.userBuffer [i] ) {
@@ -8704,8 +8746,18 @@ void RtApiAlsa :: closeStream()
8704
8746
8705
8747
if ( apiInfo ) {
8706
8748
pthread_cond_destroy ( &apiInfo->runnable_cv );
8707
- if ( apiInfo->handles [0 ] ) snd_pcm_close ( apiInfo->handles [0 ] );
8708
- if ( apiInfo->handles [1 ] ) snd_pcm_close ( apiInfo->handles [1 ] );
8749
+ bool pcm_closed = false ;
8750
+ if ( apiInfo->handles [0 ] ){
8751
+ snd_pcm_close ( apiInfo->handles [0 ] );
8752
+ pcm_closed = true ;
8753
+ }
8754
+ if ( apiInfo->handles [1 ] ){
8755
+ snd_pcm_close ( apiInfo->handles [1 ] );
8756
+ pcm_closed = true ;
8757
+ }
8758
+ if ( pcm_closed ) {
8759
+ snd_config_update_free_global ();
8760
+ }
8709
8761
delete apiInfo;
8710
8762
stream_.apiHandle = 0 ;
8711
8763
}
0 commit comments