AudioNet / node-core-audio

Bindings for PortAudio giving JavaScript access to sound card samples (mostly unmaintained)
MIT License
330 stars 66 forks source link

Segfault on Mac when the audio system is turned off #29

Open geraintluff opened 10 years ago

geraintluff commented 10 years ago

Firstly, I'd like to say thanks for the module. :)

Now the issue: when no audio is played on a Mac for a while, it seems to turn off the audio system or something.

When I attempt to use node-core-audio after this happens (so I'd expect it to turn on again), it segfaults. Here's the stack trace I got from lldb:

* thread #7: tid = 0x51acf6, 0x00007fff98dd21ec libsystem_platform.dylib`_platform_memmove$VARIANT$Nehalem + 524, name = 'com.apple.audio.IOThread.client', stop reason = EXC_BAD_ACCESS (code=1, address=0x1037ffff0)
  * frame #0: 0x00007fff98dd21ec libsystem_platform.dylib`_platform_memmove$VARIANT$Nehalem + 524
    frame #1: 0x0000000100cb341b NodeCoreAudio.node`PaUtil_WriteRingBuffer + 235
    frame #2: 0x0000000100cb2df0 NodeCoreAudio.node`BlioCallback + 144
    frame #3: 0x0000000100cace23 NodeCoreAudio.node`AdaptingProcess + 851
    frame #4: 0x0000000100cac3ea NodeCoreAudio.node`PaUtil_EndBufferProcessing + 442
    frame #5: 0x0000000100cb14e4 NodeCoreAudio.node`AudioIOProc + 1060
    frame #6: 0x0000000104809599 CoreAudio`AUInputElement::PullInput(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) + 177
    frame #7: 0x0000000104808e4f CoreAudio`AUInputFormatConverter2::InputProc(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*) + 193
    frame #8: 0x00007fff963215e3 AudioToolbox`AudioConverterChain::CallInputProc(unsigned int) + 417
    frame #9: 0x00007fff9632132f AudioToolbox`AudioConverterChain::FillBufferFromInputProc(unsigned int*, CABufferList*) + 125
    frame #10: 0x00007fff96300349 AudioToolbox`BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CABufferList const*&) + 179
    frame #11: 0x00007fff962df0ca AudioToolbox`CBRConverter::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) + 104
    frame #12: 0x00007fff963001d0 AudioToolbox`BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) + 286
    frame #13: 0x00007fff96321147 AudioToolbox`AudioConverterChain::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) + 99
    frame #14: 0x00007fff963001d0 AudioToolbox`BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) + 286
    frame #15: 0x00007fff962de91e AudioToolbox`AudioConverterFillComplexBuffer + 292
    frame #16: 0x0000000104808d06 CoreAudio`AUInputFormatConverter2::PullAndConvertInput(AudioTimeStamp const&, unsigned int&, AudioBufferList&, AudioStreamPacketDescription*, bool&) + 98
    frame #17: 0x00000001048085ea CoreAudio`AUConverterBase::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) + 188
    frame #18: 0x00000001048061c1 CoreAudio`AUBase::DoRenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, AUOutputElement*, unsigned int, AudioBufferList&) + 153
    frame #19: 0x0000000104804a75 CoreAudio`AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) + 423
    frame #20: 0x000000010480bdd8 CoreAudio`AUHAL::AUIOProc(unsigned int, AudioTimeStamp const*, AudioBufferList const*, AudioTimeStamp const*, AudioBufferList*, AudioTimeStamp const*, void*) + 2076
    frame #21: 0x00007fff8e789acb CoreAudio`HALC_ProxyIOContext::IOWorkLoop() + 3667
    frame #22: 0x00007fff8e788bcd CoreAudio`HALC_ProxyIOContext::IOThreadEntry(void*) + 97
    frame #23: 0x00007fff8e788a8d CoreAudio`HALB_IOThread::Entry(void*) + 75
    frame #24: 0x00007fff9266a899 libsystem_pthread.dylib`_pthread_body + 138
    frame #25: 0x00007fff9266a72a libsystem_pthread.dylib`_pthread_start + 137
ZECTBynmo commented 10 years ago

Oh interesting! I haven't seen this issue before. I'm not sure when I'll get a chance to work, but I bet the audio engine needs to be restarted

geraintluff commented 10 years ago

I might well have mis-diagnosed the cause - turning off the D2A might be coincidental.

However, it seems to consistently have problems the first time I run it in a while, but work fine second time I run the same thing.

ZECTBynmo commented 10 years ago

I'm sorry, I just started a new job so I have 0 time to actually dig into this issue, but I'm happy to help direct your debugging. Are you starting the script fresh after waiting for a while, or is the same audio engine still instantiated from a while ago? What happens if you just create a new audio engine instance (restarting everything) when you try to run after a break?

geraintluff commented 10 years ago

This is starting the script fresh after waiting for a while. I'm afraid I'm not quite sure what you mean by your last sentence.