Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27101
Modified Files: Tag: devel_0_38 s_audio_asio.cpp Log Message: experimental ringbuffer reading
Index: s_audio_asio.cpp =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/s_audio_asio.cpp,v retrieving revision 1.1.4.3 retrieving revision 1.1.4.4 diff -C2 -d -r1.1.4.3 -r1.1.4.4 *** s_audio_asio.cpp 7 Nov 2004 11:11:54 -0000 1.1.4.3 --- s_audio_asio.cpp 7 Nov 2004 13:47:05 -0000 1.1.4.4 *************** *** 46,49 **** --- 46,51 ---- #endif
+ #define ASIODEBUG + /* public function prototypes */ extern "C" void asio_open_audio(int naudioindev, int *audioindev, int nchindev, *************** *** 99,104 ****
/* that's the sample width in bytes (per output channel) - ! it's only for silence when stopping the driver.... (please find a better solution) ! */ static int *asio_out_samplewidth = NULL;
--- 101,106 ----
/* that's the sample width in bytes (per output channel) - ! * it's only for silence when stopping the driver.... (please find a better solution) ! */ static int *asio_out_samplewidth = NULL;
*************** *** 146,149 **** --- 148,154 ---- static pthread_cond_t asio_ringbuf_cond = PTHREAD_COND_INITIALIZER;
+ /* some global definitions: */ + #define ASIOVERSION 2 /* i hope we are compatible with asio 2 */ + /* definitions from s_audio.c ... it should be save to use them */ #define DEVDESCSIZE 80 *************** *** 187,191 **** /* initialize ASIO */ asio_driver = (ASIODriverInfo*) getbytes (sizeof(ASIODriverInfo)); ! asio_driver->asioVersion = 2; /* i hope we are compatible with asio 2 */ #ifdef MSW --- 192,196 ---- /* initialize ASIO */ asio_driver = (ASIODriverInfo*) getbytes (sizeof(ASIODriverInfo)); ! asio_driver->asioVersion = ASIOVERSION; #ifdef MSW *************** *** 223,248 **** return; } post("ASIO initialized successfully"); !
/* query driver */ status = ASIOGetChannels(&asio_inchannels, &asio_outchannels); ASSERT(status == ASE_OK); post ("ASIOGetChannels\tinputs: %d, outputs: %d", asio_inchannels, asio_outchannels);
- /* tb: todo: channel count hardcoded to asio hardware */ sys_inchannels = *chindev <= asio_inchannels ? *chindev : asio_inchannels; sys_outchannels = *choutdev <= asio_outchannels ? *choutdev : asio_outchannels; channels = sys_inchannels + sys_outchannels; ! status = ASIOGetBufferSize(&asio_minbufsize, &asio_maxbufsize, &asio_prefbufsize, &asio_granularity); ASSERT(status == ASE_OK); post ("ASIOGetBufferSize\tmin: %d, max: %d, preferred: %d, granularity: " "%d", asio_minbufsize, asio_maxbufsize, asio_prefbufsize, asio_granularity);
/* todo: buffer size hardcoded to asio hardware */ --- 228,258 ---- return; } + #ifdef ASIODEBUG post("ASIO initialized successfully"); ! #endif
/* query driver */ status = ASIOGetChannels(&asio_inchannels, &asio_outchannels); + #ifdef ASIODEBUG ASSERT(status == ASE_OK); post ("ASIOGetChannels\tinputs: %d, outputs: %d", asio_inchannels, asio_outchannels); + #endif
sys_inchannels = *chindev <= asio_inchannels ? *chindev : asio_inchannels; sys_outchannels = *choutdev <= asio_outchannels ? *choutdev : asio_outchannels; 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, asio_granularity); + #endif
/* todo: buffer size hardcoded to asio hardware */ *************** *** 279,284 ****
/* prepare, create and set up buffers */ ! asio_bufferinfo = (ASIOBufferInfo*) getbytes (channels * sizeof (ASIOBufferInfo)); ! asio_channelinfo = (ASIOChannelInfo*) getbytes(channels * sizeof (ASIOChannelInfo)); if (!(asio_bufferinfo && asio_channelinfo)) { --- 289,296 ----
/* prepare, create and set up buffers */ ! asio_bufferinfo = (ASIOBufferInfo*) getbytes (channels * ! sizeof (ASIOBufferInfo)); ! asio_channelinfo = (ASIOChannelInfo*) getbytes(channels * ! sizeof (ASIOChannelInfo)); if (!(asio_bufferinfo && asio_channelinfo)) { *************** *** 310,314 **** --- 322,328 ---- == ASE_OK) { + #ifdef ASIODEBUG post("ASIO: buffers allocated"); + #endif } else *************** *** 391,395 **** int i;
! // pthread_cond_broadcast(&asio_ringbuf_cond);
if(asio_useoutputready) --- 405,409 ---- int i;
! pthread_cond_broadcast(&asio_ringbuf_cond);
if(asio_useoutputready) *************** *** 418,421 **** --- 432,437 ---- }
+ post("ASIO: close"); + status = ASIOStop(); ASSERT(status == ASE_OK); *************** *** 423,428 **** if (asio_driver) { for (i = 0; i != channels; i++) ! freebytes(asio_ringbuffer[i], asio_ringbuffer_length * sizeof (t_sample)); freebytes(asio_ringbuffer, channels * sizeof (t_sample *)); freebytes(asio_bufferinfo, channels * sizeof (ASIOBufferInfo)); --- 439,447 ---- if (asio_driver) { + ASIOStop(); + for (i = 0; i != channels; i++) ! freebytes(asio_ringbuffer[i], ! asio_ringbuffer_length * sizeof (t_sample)); freebytes(asio_ringbuffer, channels * sizeof (t_sample *)); freebytes(asio_bufferinfo, channels * sizeof (ASIOBufferInfo)); *************** *** 435,441 **** 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;
--- 454,463 ---- 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;
*************** *** 487,492 **** #endif
- - /* send sound to ringbuffer */ sp = sys_soundout; --- 509,512 ---- *************** *** 503,509 **** for (j = 0; j < sys_inchannels; j++) { memcpy(sp, asio_ringbuffer[i+j] + asio_ringbuffer_inoffset, DEFDACBLKSIZE*sizeof(t_sample)); ! sp+=DEFDACBLKSIZE; } --- 523,544 ---- for (j = 0; j < sys_inchannels; j++) { + /* we should be able to read from the ringbuffer on a different position + * to reduce latency for asio buffer sizes that aren't multiples of 64... + * rethink this: */ + #if 0 + int offset = 2 * asio_bufsize; + if (asio_ringbuffer_inoffset <= offset ) + memcpy(sp, asio_ringbuffer[i+j] + asio_ringbuffer_length + + asio_ringbuffer_inoffset - offset , + DEFDACBLKSIZE*sizeof(t_sample)); + else + memcpy(sp, asio_ringbuffer[i+j] + asio_ringbuffer_inoffset - offset, + DEFDACBLKSIZE*sizeof(t_sample)); + #else /* working but higer latency */ memcpy(sp, asio_ringbuffer[i+j] + asio_ringbuffer_inoffset, DEFDACBLKSIZE*sizeof(t_sample)); ! ! #endif ! sp+=DEFDACBLKSIZE; } *************** *** 552,556 **** static long asio_messages(long selector, long value, void* message, double* opt) { ! /* todo */ return 0L; } --- 587,613 ---- static long asio_messages(long selector, long value, void* message, double* opt) { ! switch (selector) ! { ! case kAsioSelectorSupported: ! return 1L; ! case kAsioEngineVersion: ! return ASIOVERSION; ! case kAsioResetRequest: ! /* how to handle this without changing the dsp scheduler? */ ! return 1L; ! case kAsioBufferSizeChange: ! /* todo */ ! return 0L; /* should be 1 */ ! case kAsioResyncRequest: ! return 0L; ! case kAsioLatenciesChanged: ! /* we are not handling the latencies atm */ ! return 0L; ! case kAsioSupportsTimeInfo: ! return 1L; ! case kAsioSupportsTimeCode: ! /* we don't support that atm */ ! return 0L; ! } return 0L; } *************** *** 638,647 **** case ASIOSTInt32MSB: return float32toInt32_S; - case ASIOSTFloat32LSB: // IEEE 754 32 bit float, as found on Intel x86 architecture return float32tofloat32; case ASIOSTFloat32MSB: return float32tofloat32_S; - case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture return float32tofloat64; --- 695,702 ---- *************** *** 689,698 **** case ASIOSTInt32MSB: return Int32tofloat32_S; ! case ASIOSTFloat32LSB: // IEEE 754 32 bit float, as found on Intel x86 architecture return float32tofloat32; - case ASIOSTFloat32MSB: - return float32tofloat32_S; - case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture return float64tofloat32; --- 744,751 ---- case ASIOSTInt32MSB: return Int32tofloat32_S; ! case ASIOSTFloat32MSB: // IEEE 754 32 bit float, as found on Intel x86 architecture ! float32tofloat32_S; case ASIOSTFloat32LSB: // IEEE 754 32 bit float, as found on Intel x86 architecture return float32tofloat32; case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture return float64tofloat32; *************** *** 714,718 **** case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment default: ! post("Input sample Type %d not supported, yet!!!",format); return NULL; } --- 767,771 ---- case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment default: ! post("Input sample Type %d not supported, yet!!!",format); return NULL; } *************** *** 798,802 **** static void float32tofloat32(void* inbuffer, void* outbuffer, long frames) { ! memcpy (outbuffer, inbuffer, frames* sizeof (float)); /* check */ }
--- 851,855 ---- static void float32tofloat32(void* inbuffer, void* outbuffer, long frames) { ! memcpy (outbuffer, inbuffer, frames* sizeof (float)); }