Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25685/src
Modified Files: Tag: devel_0_38 s_audio_asio.cpp Log Message: better handling of error situations but: C++ exception handling may not be a good idea....
Index: s_audio_asio.cpp =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/s_audio_asio.cpp,v retrieving revision 1.1.4.7 retrieving revision 1.1.4.8 diff -C2 -d -r1.1.4.7 -r1.1.4.8 *** s_audio_asio.cpp 8 Nov 2004 20:18:41 -0000 1.1.4.7 --- s_audio_asio.cpp 9 Nov 2004 15:30:37 -0000 1.1.4.8 *************** *** 117,123 **** /* global storage */ static ASIODriverInfo * asio_driver = NULL; ! static ASIOBufferInfo * asio_bufferinfo; ! static ASIOChannelInfo* asio_channelinfo; ! static AsioTimeInfo * asio_timerinfo; static ASIOCallbacks asio_callbacks; extern AsioDrivers * asioDrivers; /* declared in asiodrivers.cpp */ --- 117,123 ---- /* global storage */ static ASIODriverInfo * asio_driver = NULL; ! static ASIOBufferInfo * asio_bufferinfo = NULL; ! static ASIOChannelInfo* asio_channelinfo = NULL; ! static AsioTimeInfo * asio_timerinfo = NULL; static ASIOCallbacks asio_callbacks; extern AsioDrivers * asioDrivers; /* declared in asiodrivers.cpp */ *************** *** 142,146 ****
/* ringbuffer stuff */ ! static t_sample ** asio_ringbuffer; /* ringbuffers */ static int asio_ringbuffer_inoffset; /* ringbuffer(in) pointer offset for dac */ static int asio_ringbuffer_outoffset; /* ringbuffer(out) pointer offset */ --- 142,146 ----
/* ringbuffer stuff */ ! static t_sample ** asio_ringbuffer = NULL; /* ringbuffers */ static int asio_ringbuffer_inoffset; /* ringbuffer(in) pointer offset for dac */ static int asio_ringbuffer_outoffset; /* ringbuffer(out) pointer offset */ *************** *** 165,169 **** { ASIOError status; ! ASIOBufferInfo * buffers; int i; int channels; --- 165,169 ---- { ASIOError status; ! ASIOBufferInfo * buffers = NULL; int i; int channels; *************** *** 175,195 **** #endif
/* check, if we use the first asio device */ prepare_asio_drivernames(); ! /* load the driver */ if (!asioDrivers) asioDrivers = new AsioDrivers(); - /* check, if the driver is still running */ - if (asio_driver) - asio_close_audio(); - asioDrivers->getDriverNames(asio_drivernames,MAXNDEV);
! asioDrivers->loadDriver(asio_drivernames[*audioindev]); ! !
/* initialize ASIO */ --- 175,198 ---- #endif + /* check, if the driver is still running */ + if(asio_driver) + asio_close_audio();
/* check, if we use the first asio device */ prepare_asio_drivernames(); ! /* load the driver */ if (!asioDrivers) asioDrivers = new AsioDrivers(); asioDrivers->getDriverNames(asio_drivernames,MAXNDEV);
! try { ! asioDrivers->loadDriver(asio_drivernames[*audioindev]); ! } ! catch(...) { ! error("ASIO: Error loading driver"); ! goto bailout; ! }
/* initialize ASIO */ *************** *** 217,233 **** case ASE_NotPresent: error("ASIO: ASE_NotPresent"); ! freebytes(asio_driver, sizeof (ASIODriverInfo)); ! asio_driver = NULL; ! return; case ASE_NoMemory: error("ASIO: ASE_NoMemory"); ! freebytes(asio_driver, sizeof (ASIODriverInfo)); ! asio_driver = NULL; ! return; case ASE_HWMalfunction: error("ASIO: ASE_HWMalfunction"); ! freebytes(asio_driver, sizeof (ASIODriverInfo)); ! asio_driver = NULL; ! return; } #ifdef ASIODEBUG --- 220,230 ---- case ASE_NotPresent: error("ASIO: ASE_NotPresent"); ! goto bailout; case ASE_NoMemory: error("ASIO: ASE_NoMemory"); ! goto bailout; case ASE_HWMalfunction: error("ASIO: ASE_HWMalfunction"); ! goto bailout; } #ifdef ASIODEBUG *************** *** 238,243 **** /* query driver */ status = ASIOGetChannels(&asio_inchannels, &asio_outchannels); #ifdef ASIODEBUG - ASSERT(status == ASE_OK); post ("ASIOGetChannels\tinputs: %d, outputs: %d", asio_inchannels, asio_outchannels); --- 235,245 ---- /* query driver */ status = ASIOGetChannels(&asio_inchannels, &asio_outchannels); + if(status != ASE_OK) + { + error("ASIO: Couldn't get channel count"); + goto bailout; + } + #ifdef ASIODEBUG post ("ASIOGetChannels\tinputs: %d, outputs: %d", asio_inchannels, asio_outchannels); *************** *** 248,257 **** channels = sys_inchannels + sys_outchannels; - status = ASIOGetBufferSize(&asio_minbufsize, &asio_maxbufsize, &asio_prefbufsize, &asio_granularity); #ifdef ASIODEBUG - ASSERT(status == ASE_OK); post ("ASIOGetBufferSize\tmin: %d, max: %d, preferred: %d, granularity: " "%d", asio_minbufsize, asio_maxbufsize, asio_prefbufsize, --- 250,262 ---- channels = sys_inchannels + sys_outchannels; status = ASIOGetBufferSize(&asio_minbufsize, &asio_maxbufsize, &asio_prefbufsize, &asio_granularity); + if(status != ASE_OK) + { + error("ASIO: Couldn't get buffer size"); + goto bailout; + } #ifdef ASIODEBUG post ("ASIOGetBufferSize\tmin: %d, max: %d, preferred: %d, granularity: " "%d", asio_minbufsize, asio_maxbufsize, asio_prefbufsize, *************** *** 299,307 **** { error("ASIO: couldn't allocate buffer or channel info"); ! if (asio_bufferinfo) ! freebytes(asio_bufferinfo, channels * sizeof (ASIOBufferInfo)); ! if (asio_channelinfo) ! freebytes(asio_channelinfo, channels * sizeof (ASIOChannelInfo)); ! return; }
--- 304,308 ---- { error("ASIO: couldn't allocate buffer or channel info"); ! goto bailout; }
*************** *** 321,337 **** } ! if (ASIOCreateBuffers(asio_bufferinfo, sys_inchannels + sys_outchannels, ! asio_bufsize, &asio_callbacks) ! == ASE_OK) ! { ! #ifdef ASIODEBUG ! post("ASIO: buffers allocated"); ! #endif ! } ! else { error("ASIO: couldn't allocate buffers"); ! return; }
asio_converter = (converter_t **)getbytes(channels * sizeof (converter_t *)); --- 322,336 ---- } ! status = ASIOCreateBuffers(asio_bufferinfo, sys_inchannels + sys_outchannels, ! asio_bufsize, &asio_callbacks); ! ! if(status != ASE_OK) { error("ASIO: couldn't allocate buffers"); ! goto bailout; } + #ifdef ASIODEBUG + post("ASIO: buffers allocated"); + #endif
asio_converter = (converter_t **)getbytes(channels * sizeof (converter_t *)); *************** *** 390,398 **** asio_ringbuffer_inoffset = asio_ringbuffer_outoffset = 0;
! if (ASIOStart() == ASE_OK) ! post("ASIO: started"); ! else ! post("ASIO: couldn't start"); }
--- 389,401 ---- asio_ringbuffer_inoffset = asio_ringbuffer_outoffset = 0;
+ if(ASIOStart() != ASE_OK) goto bailout;
! post("ASIO: started"); ! return; ! ! bailout: ! post("ASIO: couldn't start"); ! asio_close_audio(); ! return; }
*************** *** 404,409 **** if (asio_driver) { - post("ASIO: close"); - pthread_cond_broadcast(&asio_ringbuf_cond);
--- 407,410 ---- *************** *** 417,466 **** // -> clear output buffers and notify driver #if 0 ! // slow, blocking method ! for(i = 0; i != sys_outchannels; ++i) ! zerovec_simd(asio_ringbuffer[i], asio_ringbuffer_length); ! // wait for bufferswitch to process silence (twice) ! pthread_cond_wait(&asio_ringbuf_cond, &asio_ringbuf_mutex); ! for(i = 0; i != sys_outchannels; ++i) ! memset(asio_ringbuffer[i], 0, asio_ringbuffer_length * sizeof (t_sample)); ! pthread_cond_wait(&asio_ringbuf_cond, &asio_ringbuf_mutex); #else // direct method - clear both hardware buffers ! for(i = 0; i < sys_outchannels; ++i) { ! long bytes = asio_bufsize*asio_out_samplewidth[i]; ! memset(asio_bufferinfo[i].buffers[0],0,bytes); ! memset(asio_bufferinfo[i].buffers[1],0,bytes); } // notify driver ! ASIOOutputReady(); #endif } - - status = ASIOStop(); - ASSERT(status == ASE_OK);
! for (i = 0; i != channels; i++) ! freealignedbytes(asio_ringbuffer[i], ! asio_ringbuffer_length * sizeof (t_sample)); ! freebytes(asio_ringbuffer, channels * sizeof (t_sample *)); ! freebytes(asio_bufferinfo, channels * sizeof (ASIOBufferInfo)); ! freebytes(asio_channelinfo, channels * sizeof (ASIOChannelInfo)); ! status = ASIODisposeBuffers(); ! ASSERT(status == ASE_OK); ! ! asio_ringbuffer = NULL; ! asio_bufferinfo = NULL; ! asio_channelinfo = NULL; ! if(asio_converter) freebytes(asio_converter, channels * sizeof (converter_t *)); ! asio_converter = NULL;
if(asio_out_samplewidth) freebytes(asio_out_samplewidth, sys_outchannels * sizeof (int)); ! asio_out_samplewidth = NULL; ! ! status = ASIOExit(); ! ASSERT(status == ASE_OK);
freebytes(asio_driver, sizeof (ASIODriverInfo)); --- 418,492 ---- // -> clear output buffers and notify driver #if 0 ! if(asio_ringbuffer) ! { ! // slow, blocking method ! for(i = 0; i != sys_outchannels; ++i) ! zerovec_simd(asio_ringbuffer[i], asio_ringbuffer_length); ! // wait for bufferswitch to process silence (twice) ! pthread_cond_wait(&asio_ringbuf_cond, &asio_ringbuf_mutex); ! for(i = 0; i != sys_outchannels; ++i) ! memset(asio_ringbuffer[i], 0, asio_ringbuffer_length * sizeof (t_sample)); ! pthread_cond_wait(&asio_ringbuf_cond, &asio_ringbuf_mutex); ! } #else // direct method - clear both hardware buffers ! if(asio_bufferinfo && asio_out_samplewidth) ! { ! for(i = 0; i < sys_outchannels; ++i) { ! long bytes = asio_bufsize*asio_out_samplewidth[i]; ! memset(asio_bufferinfo[i].buffers[0],0,bytes); ! memset(asio_bufferinfo[i].buffers[1],0,bytes); ! } } // notify driver ! status = ASIOOutputReady(); #endif }
! status = ASIOStop(); ! if(status == ASE_OK) post("ASIO: stopped"); ! ! status = ASIODisposeBuffers(); ! ! try { ! // ASIOExit can crash if driver not really running ! status = ASIOExit(); ! } ! catch(...) {} ! ! // deallocate all memory ! ! if(asio_ringbuffer) ! { ! for(i = 0; i < channels; i++) ! if(asio_ringbuffer[i]) ! freealignedbytes(asio_ringbuffer[i],asio_ringbuffer_length * sizeof (t_sample)); ! freebytes(asio_ringbuffer, channels * sizeof (t_sample *)); ! asio_ringbuffer = NULL; ! } ! ! if(asio_bufferinfo) ! { ! freebytes(asio_bufferinfo, channels * sizeof (ASIOBufferInfo)); ! asio_bufferinfo = NULL; ! } ! ! if(asio_channelinfo) ! { ! freebytes(asio_channelinfo, channels * sizeof (ASIOChannelInfo)); ! asio_channelinfo = NULL; ! } ! if(asio_converter) + { freebytes(asio_converter, channels * sizeof (converter_t *)); ! asio_converter = NULL; ! }
if(asio_out_samplewidth) + { freebytes(asio_out_samplewidth, sys_outchannels * sizeof (int)); ! asio_out_samplewidth = NULL; ! }
freebytes(asio_driver, sizeof (ASIODriverInfo));