Swift & ObjC UI, C++ JUCE, Getting No Sound?

Hey there All,

I’m new to C++ but have been attempting to get JUCE to use some code exported as C++ from Max/MSP as a processor in an iOS app that I’d design a UI for in Swift. I found how to combine Swift, Objective C and Swift in other people’s code, and have tried to stitch it together with a JUCE project to make this work, but I don’t seem to get any sound at runtime.

What I’ve done looks just like working JUCE projects to me, and I can’t figure out why I’m getting no sound, so I’d appreciate if someone might be able to help me see what I’ve missed or point me in the right direction. Below is a Github repository with the project inside.

Thanks very much,

First about your problem:

  1. Did you test in a debugger? Is getNextAudioBlock() called? and is it called with values you expected?
  2. Did you check your settings? Is the device set to play on an output, where you would hear something? Nice catch e.g. sending to HDMI output and no speakers on the display…
  3. If you are in doubt about 2) add an AudioDeviceSelectorComponent, that lets you set the output and also play a test tone.

And now what looked suspicious, but maybe not linked to your problem:

  1. C74 allows also float operation, if you set the define GENLIB_USE_FLOAT32, see here, you avoid the conversion back and forth
  2. Even if you insist using double, you have a templated version AudioBuffer. You will still have to convert the samples, but you avoid the ugly new float[] calls, that are leaking in your case btw. It makes sense, because AudioBuffer will also ensure aligned memory iirc.
  3. You must not call new in your audio thread, which you do calling assureBufferSize. This has to be done in prepareToPlay. new will eventually not return in time and your audio is stalled. You can rely on the samplesPerBufferExpected. If you are paranoid, Fabian had a good suggestion to wrap your processing in a loop, so you can process fractions without overflowing your buffers.

Your processing could be simplified to:


Good luck debugging

Many thanks, I’ll look into all of this.