| 1 | Index: src/hostapi/coreaudio/pa_mac_core_blocking.c |
| 2 | =================================================================== |
| 3 | --- src/hostapi/coreaudio/pa_mac_core_blocking.c (Revision 1843) |
| 4 | +++ src/hostapi/coreaudio/pa_mac_core_blocking.c (Revision 1844) |
| 5 | @@ -359,8 +359,9 @@ |
| 6 | |
| 7 | /* check for underflow */ |
| 8 | if( avail < frameCount * blio->inputSampleSizeActual * blio->inChan ) |
| 9 | + { |
| 10 | OSAtomicOr32( paInputOverflow, &blio->statusFlags ); |
| 11 | - |
| 12 | + } |
| 13 | toRead = MIN( avail, frameCount * blio->inputSampleSizeActual * blio->inChan ); |
| 14 | |
| 15 | /* copy the data */ |
| 16 | Index: src/hostapi/coreaudio/pa_mac_core.c |
| 17 | =================================================================== |
| 18 | --- src/hostapi/coreaudio/pa_mac_core.c (Revision 1843) |
| 19 | +++ src/hostapi/coreaudio/pa_mac_core.c (Revision 1844) |
| 20 | @@ -1774,25 +1774,16 @@ |
| 21 | do is initialize everything so that if we fail, we know what hasn't |
| 22 | been touched. |
| 23 | */ |
| 24 | - |
| 25 | - stream->inputAudioBufferList.mBuffers[0].mData = NULL; |
| 26 | - stream->inputRingBuffer.buffer = NULL; |
| 27 | - bzero( &stream->blio, sizeof( PaMacBlio ) ); |
| 28 | -/* |
| 29 | + bzero( stream, sizeof( PaMacCoreStream ) ); |
| 30 | + |
| 31 | + /* |
| 32 | stream->blio.inputRingBuffer.buffer = NULL; |
| 33 | stream->blio.outputRingBuffer.buffer = NULL; |
| 34 | stream->blio.inputSampleFormat = inputParameters?inputParameters->sampleFormat:0; |
| 35 | stream->blio.inputSampleSize = computeSampleSizeFromFormat(stream->blio.inputSampleFormat); |
| 36 | stream->blio.outputSampleFormat=outputParameters?outputParameters->sampleFormat:0; |
| 37 | stream->blio.outputSampleSize = computeSampleSizeFromFormat(stream->blio.outputSampleFormat); |
| 38 | -*/ |
| 39 | - stream->inputSRConverter = NULL; |
| 40 | - stream->inputUnit = NULL; |
| 41 | - stream->outputUnit = NULL; |
| 42 | - stream->inputFramesPerBuffer = 0; |
| 43 | - stream->outputFramesPerBuffer = 0; |
| 44 | - stream->bufferProcessorIsInitialized = FALSE; |
| 45 | - stream->timingInformationMutexIsInitialized = 0; |
| 46 | + */ |
| 47 | |
| 48 | /* assert( streamCallback ) ; */ /* only callback mode is implemented */ |
| 49 | if( streamCallback ) |
| 50 | @@ -2145,11 +2136,11 @@ |
| 51 | const bool isRender = inBusNumber == OUTPUT_ELEMENT; |
| 52 | int callbackResult = paContinue ; |
| 53 | double hostTimeStampInPaTime = HOST_TIME_TO_PA_TIME(inTimeStamp->mHostTime); |
| 54 | - |
| 55 | + |
| 56 | VVDBUG(("AudioIOProc()\n")); |
| 57 | |
| 58 | PaUtil_BeginCpuLoadMeasurement( &stream->cpuLoadMeasurer ); |
| 59 | - |
| 60 | + |
| 61 | /* -----------------------------------------------------------------*\ |
| 62 | This output may be useful for debugging, |
| 63 | But printing durring the callback is a bad enough idea that |
| 64 | @@ -2250,7 +2241,8 @@ |
| 65 | * |
| 66 | */ |
| 67 | OSStatus err = 0; |
| 68 | - unsigned long frames; |
| 69 | + unsigned long frames; |
| 70 | + long bytesPerFrame = sizeof( float ) * ioData->mBuffers[0].mNumberChannels; |
| 71 | |
| 72 | /* -- start processing -- */ |
| 73 | PaUtil_BeginBufferProcessing( &(stream->bufferProcessor), |
| 74 | @@ -2261,8 +2253,8 @@ |
| 75 | /* -- compute frames. do some checks -- */ |
| 76 | assert( ioData->mNumberBuffers == 1 ); |
| 77 | assert( ioData->mBuffers[0].mNumberChannels == stream->userOutChan ); |
| 78 | - frames = ioData->mBuffers[0].mDataByteSize; |
| 79 | - frames /= sizeof( float ) * ioData->mBuffers[0].mNumberChannels; |
| 80 | + |
| 81 | + frames = ioData->mBuffers[0].mDataByteSize / bytesPerFrame; |
| 82 | /* -- copy and process input data -- */ |
| 83 | err= AudioUnitRender(stream->inputUnit, |
| 84 | ioActionFlags, |
| 85 | @@ -2300,7 +2292,8 @@ |
| 86 | * and into the PA buffer processor. If sample rate conversion |
| 87 | * is required on input, that is done here as well. |
| 88 | */ |
| 89 | - unsigned long frames; |
| 90 | + unsigned long frames; |
| 91 | + long bytesPerFrame = sizeof( float ) * ioData->mBuffers[0].mNumberChannels; |
| 92 | |
| 93 | /* Sometimes, when stopping a duplex stream we get erroneous |
| 94 | xrun flags, so if this is our last run, clear the flags. */ |
| 95 | @@ -2322,8 +2315,7 @@ |
| 96 | |
| 97 | /* -- Copy and process output data -- */ |
| 98 | assert( ioData->mNumberBuffers == 1 ); |
| 99 | - frames = ioData->mBuffers[0].mDataByteSize; |
| 100 | - frames /= sizeof( float ) * ioData->mBuffers[0].mNumberChannels; |
| 101 | + frames = ioData->mBuffers[0].mDataByteSize / bytesPerFrame; |
| 102 | assert( ioData->mBuffers[0].mNumberChannels == stream->userOutChan ); |
| 103 | PaUtil_SetOutputFrameCount( &(stream->bufferProcessor), frames ); |
| 104 | PaUtil_SetInterleavedOutputChannels( &(stream->bufferProcessor), |
| 105 | @@ -2337,6 +2329,8 @@ |
| 106 | /* Here, we read the data out of the ring buffer, through the |
| 107 | audio converter. */ |
| 108 | int inChan = stream->inputAudioBufferList.mBuffers[0].mNumberChannels; |
| 109 | + long bytesPerFrame = flsz * inChan; |
| 110 | + |
| 111 | if( stream->inputSRConverter ) |
| 112 | { |
| 113 | OSStatus err; |
| 114 | @@ -2353,7 +2347,12 @@ |
| 115 | { /*the ring buffer callback underflowed */ |
| 116 | err = 0; |
| 117 | bzero( ((char *)data) + size, sizeof(data)-size ); |
| 118 | - stream->xrunFlags |= paInputUnderflow; |
| 119 | + /* The ring buffer can underflow normally when the stream is stopping. |
| 120 | + * So only report an error if the stream is active. */ |
| 121 | + if( stream->state == ACTIVE ) |
| 122 | + { |
| 123 | + stream->xrunFlags |= paInputUnderflow; |
| 124 | + } |
| 125 | } |
| 126 | ERR( err ); |
| 127 | assert( !err ); |
| 128 | @@ -2374,7 +2373,7 @@ |
| 129 | AudioConverter would otherwise handle for us. */ |
| 130 | void *data1, *data2; |
| 131 | ring_buffer_size_t size1, size2; |
| 132 | - PaUtil_GetRingBufferReadRegions( &stream->inputRingBuffer, |
| 133 | + ring_buffer_size_t framesReadable = PaUtil_GetRingBufferReadRegions( &stream->inputRingBuffer, |
| 134 | frames, |
| 135 | &data1, &size1, |
| 136 | &data2, &size2 ); |
| 137 | @@ -2389,14 +2388,21 @@ |
| 138 | PaUtil_EndBufferProcessing( &(stream->bufferProcessor), |
| 139 | &callbackResult ); |
| 140 | PaUtil_AdvanceRingBufferReadIndex(&stream->inputRingBuffer, size1 ); |
| 141 | - } else if( size1 + size2 < frames ) { |
| 142 | + } else if( framesReadable < frames ) { |
| 143 | + |
| 144 | + long sizeBytes1 = size1 * bytesPerFrame; |
| 145 | + long sizeBytes2 = size2 * bytesPerFrame; |
| 146 | /*we underflowed. take what data we can, zero the rest.*/ |
| 147 | - unsigned char data[frames*inChan*flsz]; |
| 148 | - if( size1 ) |
| 149 | - memcpy( data, data1, size1 ); |
| 150 | - if( size2 ) |
| 151 | - memcpy( data+size1, data2, size2 ); |
| 152 | - bzero( data+size1+size2, frames*flsz*inChan - size1 - size2 ); |
| 153 | + unsigned char data[ frames * bytesPerFrame ]; |
| 154 | + if( size1 > 0 ) |
| 155 | + { |
| 156 | + memcpy( data, data1, sizeBytes1 ); |
| 157 | + } |
| 158 | + if( size2 > 0 ) |
| 159 | + { |
| 160 | + memcpy( data+sizeBytes1, data2, sizeBytes2 ); |
| 161 | + } |
| 162 | + bzero( data+sizeBytes1+sizeBytes2, (frames*bytesPerFrame) - sizeBytes1 - sizeBytes2 ); |
| 163 | |
| 164 | PaUtil_SetInputFrameCount( &(stream->bufferProcessor), frames ); |
| 165 | PaUtil_SetInterleavedInputChannels( &(stream->bufferProcessor), |
| 166 | @@ -2407,7 +2413,7 @@ |
| 167 | PaUtil_EndBufferProcessing( &(stream->bufferProcessor), |
| 168 | &callbackResult ); |
| 169 | PaUtil_AdvanceRingBufferReadIndex( &stream->inputRingBuffer, |
| 170 | - size1+size2 ); |
| 171 | + framesReadable ); |
| 172 | /* flag underflow */ |
| 173 | stream->xrunFlags |= paInputUnderflow; |
| 174 | } else { |
| 175 | @@ -2425,7 +2431,7 @@ |
| 176 | framesProcessed = |
| 177 | PaUtil_EndBufferProcessing( &(stream->bufferProcessor), |
| 178 | &callbackResult ); |
| 179 | - PaUtil_AdvanceRingBufferReadIndex(&stream->inputRingBuffer, size1+size2 ); |
| 180 | + PaUtil_AdvanceRingBufferReadIndex(&stream->inputRingBuffer, framesReadable ); |
| 181 | } |
| 182 | } |
| 183 | } else { |
| 184 | @@ -2463,13 +2469,13 @@ |
| 185 | { |
| 186 | /* If this is duplex or we use a converter, put the data |
| 187 | into the ring buffer. */ |
| 188 | - long bytesIn, bytesOut; |
| 189 | - bytesIn = sizeof( float ) * inNumberFrames * chan; |
| 190 | - bytesOut = PaUtil_WriteRingBuffer( &stream->inputRingBuffer, |
| 191 | + ring_buffer_size_t framesWritten = PaUtil_WriteRingBuffer( &stream->inputRingBuffer, |
| 192 | stream->inputAudioBufferList.mBuffers[0].mData, |
| 193 | inNumberFrames ); |
| 194 | - if( bytesIn != bytesOut ) |
| 195 | - stream->xrunFlags |= paInputOverflow ; |
| 196 | + if( framesWritten != inNumberFrames ) |
| 197 | + { |
| 198 | + stream->xrunFlags |= paInputOverflow ; |
| 199 | + } |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | Index: qa/loopback/src/paqa.c |
| 204 | =================================================================== |
| 205 | --- qa/loopback/src/paqa.c (Revision 1843) |
| 206 | +++ qa/loopback/src/paqa.c (Revision 1844) |
| 207 | @@ -989,8 +989,8 @@ |
| 208 | int framesPerBuffers[] = { 0, 16, 32, 40, 64, 100, 128, 256, 512, 1024 }; |
| 209 | int numBufferSizes = (sizeof(framesPerBuffers)/sizeof(int)); |
| 210 | |
| 211 | - PaSampleFormat sampleFormats[] = { paUInt8, paInt8, paInt16, paInt32 }; |
| 212 | - const char *sampleFormatNames[] = { "paUInt8", "paInt8", "paInt16", "paInt32" }; |
| 213 | + PaSampleFormat sampleFormats[] = { paFloat32, paUInt8, paInt8, paInt16, paInt32 }; |
| 214 | + const char *sampleFormatNames[] = { "paFloat32", "paUInt8", "paInt8", "paInt16", "paInt32" }; |
| 215 | int numSampleFormats = (sizeof(sampleFormats)/sizeof(PaSampleFormat)); |
| 216 | |
| 217 | printf( "=============== Analysing Loopback %d to %d =====================\n", outputDevice, inputDevice ); |
| 218 | Index: qa/loopback/src/audio_analyzer.c |
| 219 | =================================================================== |
| 220 | --- qa/loopback/src/audio_analyzer.c (Revision 1843) |
| 221 | +++ qa/loopback/src/audio_analyzer.c (Revision 1844) |
| 222 | @@ -514,9 +514,15 @@ |
| 223 | |
| 224 | assert( startFrame >= 0 ); |
| 225 | assert( count > 0 ); |
| 226 | - |
| 227 | - for( is=0; is<count; is++ ) |
| 228 | + |
| 229 | + /* Zero out initial part of the recording. */ |
| 230 | + for( is=0; is<startFrame; is++ ) |
| 231 | { |
| 232 | + recording->buffer[ is ] = 0.0f; |
| 233 | + } |
| 234 | + /* Fade in where signal begins. */ |
| 235 | + for( is=0; is<count; is++ ) |
| 236 | + { |
| 237 | double c = cos( phase ); |
| 238 | double w = c * c; |
| 239 | float x = recording->buffer[ is + startFrame ]; |