[Csnd] Problems with C++ API and Android
Date | 2017-12-02 20:06 |
From | Hector Centeno |
Subject | [Csnd] Problems with C++ API and Android |
Hello,
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
I'm trying to get Csound working in Unreal Engine and so far I got it to work and generate audio in Windows but not in Android. It seems that I managed to get all the needed libraries to package in the APK and to load properly at runtime but the issue I have is that the audio output is completely silent even though the log shows that Csound is performing normally. I don't get any error messages and the only difference between the logs in Windows and Android is this message, that I get only in Android: "Non-real-time" performance (engineStatus: 9) Unreal Engine is handling the audio device so I'm running Csound just to get the audio buffers. My C++ code setup is done like this: At Initialization (showing only the key parts): csoundSetGlobalEnv("SSDIR", ssdirChar.Get()); csound = csoundCreate(0); csoundSetRTAudioModule(csound, TCHAR_TO_ANSI(*FString("null"))); csoundSetHostImplementedAudioIO(csound, 1, AudioDevice->GetBufferLength() / 2); csoundSetMessageCallback(csound, CsoundMessageCallback); csoundSetOption(csound, TCHAR_TO_ANSI(*FString("-n"))); csoundCompileCsd(csound, TCHAR_TO_ANSI(*csdPath)); csoundStart(csound); Then at each buffer generation call (whole function): void UCsSynthComponent::OnGenerateAudio(float* OutAudio, int32 NumSamples) { if (initialized && !csoundPerformBuffer(csound)) { MYFLT *csBuffer = csoundGetOutputBuffer(csound); for (int32 Sample = 0; Sample < NumSamples; ++Sample) { OutAudio[Sample] = csBuffer[Sample]; } } } As I said, this works perfectly fine in Windows but in Android it seems that csoundPerformBuffer returns true from the beginning even though the logs show that it is still performing (allocating instruments and performing the score). Although once I got it to return false (performing) but still no audio. I can post the Android log here if needed. Thanks! Hector |
Date | 2017-12-02 22:20 |
From | Rory Walsh |
Subject | Re: [Csnd] Problems with C++ API and Android |
Hi Hector. You don't seem to be using the CsoundAndroid class? I'd definitely start there, i.e, #include "AndroidCsound.hpp" ... AndroidCsound* csound; MYFLT *CSspin, *CSspout; int result; ... csound = new AndroidCsound(); csound->setOpenSlCallbacks(); // for android audio to work csound->SetOption((char*)"-n"); csound->SetOption((char*)"-d"); result = csound->CompileCsd(....); CSspout = csound->GetSpout(); CSspin = csound->GetSpin(); You processing function should look pretty similar but you can just call csound->PerformKsmps(). And you don't need to keep calling csound->GetSpout(); On 2 December 2017 at 20:06, Hector Centeno <hcengar@gmail.com> wrote:
|
Date | 2017-12-03 01:51 |
From | hcenteno |
Subject | Re: [Csnd] Problems with C++ API and Android |
Hi Rory, Thank you for your reply. I wasn't aware of AndroidCsound.hpp, it's the fist time I use the C++ Csound API for Android. I tried and now UE is crashing and the logs are not helping. On Windows I found that UE would crash if I try to instantiate Csound using new, which is why I used csoundCreate() instead. I'll keep trying! -- Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2017-12-03 08:50 |
From | Rory Walsh |
Subject | Re: [Csnd] Problems with C++ API and Android |
Have you checked out the Csound API examples on github? That's a good place to look too. On 3 Dec 2017 1:51 a.m., "hcenteno" <hcengar@gmail.com> wrote: Hi Rory, |
Date | 2017-12-03 15:14 |
From | Hector Centeno |
Subject | Re: [Csnd] Problems with C++ API and Android |
Hi Rory, Thanks! Yes, I'm aware of the Csound examples and I've done desktop C++ and Android Java apps before but this is the first time I'm trying to do native C++ for Android and also Csound not doing audio device management but just generating buffers. I don't seem to find examples of this included with the Csound source. Also I wonder if I really need OpenSL if Csound is not using any audio device module. On Dec 3, 2017 3:50 AM, "Rory Walsh" <rorywalsh@ear.ie> wrote:
|
Date | 2017-12-03 15:51 |
From | Michael Gogins |
Subject | Re: [Csnd] Problems with C++ API and Android |
The main thing is whether Csound is calling csoundPerformKsmps to drive performance or whether an audio driver is driving performance and is given a callback that should call csoundPerformKsmps. On Dec 3, 2017 10:15, "Hector Centeno" <hcengar@gmail.com> wrote:
|
Date | 2017-12-03 16:01 |
From | Steven Yi |
Subject | Re: [Csnd] Problems with C++ API and Android |
Hi Hector, I don't think AndroidCsound should be necessary nor OpenSL since you're transferring samples yourself to Unreal's audio graph. Could you post a fuller log? steven On Sun, Dec 3, 2017 at 10:14 AM, Hector Centeno |
Date | 2017-12-03 19:25 |
From | Hector Centeno |
Subject | Re: [Csnd] Problems with C++ API and Android |
Thanks Steven, Here's the log produced when running the app on Android: It looks normal to me, except I'm not sure what the following means, is it referring to realtime as in producing audio realtime or as in the pre parsing of the score (as described in csound.h)? Csound output: "Non-real-time" performance (engineStatus: 9). On Windows I don't get this message. It's also strange because it seems that even though the logs show that it is performing normal, performksmps seems to be returning true all the time. On Dec 3, 2017 11:02 AM, "Steven Yi" <stevenyi@gmail.com> wrote: Hi Hector, |
Date | 2017-12-03 19:45 |
From | Michael Gogins |
Subject | Re: [Csnd] Problems with C++ API and Android |
This is explained at the top of csound.h. On Dec 3, 2017 2:25 PM, "Hector Centeno" <hcengar@gmail.com> wrote:
|
Date | 2017-12-03 19:46 |
From | Rory Walsh |
Subject | Re: [Csnd] Problems with C++ API and Android |
That output looks fine to me but Steven has sharper eyes that I. Have you tried outputting sound directly, without calling Csound? Perhaps you could generate a simple sine wave and see if that works? Maybe Csound isn't the problem? On 3 December 2017 at 19:25, Hector Centeno <hcengar@gmail.com> wrote:
|
Date | 2017-12-03 19:56 |
From | Michael Gogins |
Subject | Re: [Csnd] Problems with C++ API and Android |
I've read your code. Questions. There are 3 potential buffer sizes here, unreal, spout, and the csound output buffer size. How are you correlating these? You log shows audio output .6. What is 0dbfs for unreal? If it is 32767 you will not hear .6. On Dec 2, 2017 3:06 PM, "Hector Centeno" <hcengar@gmail.com> wrote:
|
Date | 2017-12-03 20:14 |
From | Rory Walsh |
Subject | Re: [Csnd] Problems with C++ API and Android |
In relation to the buffer sizes question Mike raised you may wish to see how I use my step through Csound buffer samples, iirespective of Unity's buffer sample index: https://github.com/csound/csound/blob/develop/frontends/csladspa/csladspa.cpp#L137-L160 You may also want to check out the csladspa frontend which does a similar thing: On 3 December 2017 at 19:56, Michael Gogins <michael.gogins@gmail.com> wrote:
|
Date | 2017-12-03 20:23 |
From | Michael Gogins |
Subject | Re: [Csnd] Problems with C++ API and Android |
These 2 code snippets are the same. On Dec 3, 2017 3:15 PM, "Rory Walsh" <rorywalsh@ear.ie> wrote:
|
Date | 2017-12-03 20:47 |
From | Steven Yi |
Subject | Re: [Csnd] Problems with C++ API and Android |
Hi Hector, I'm not sure about that message myself. A few things: 1. Are you using a custom -b or -B setting? On Windows, do you have this set in .csound6rc perhaps? One thing I see in the Android output is: [2017.12.03-19.07.33:101][ 1]LogTemp: Warning: Csound output: audio buffered in 2048 sample-frame blocks Which seems bigger than that 512 ksmps and nchnls 2 by 2. 2. You also mention using performKsmps but the original email you have performBuffer. I think the above two things make me wonder if a -b or -B are set on Windows somewhere but not on Android. However, that's just a guess; if that was the case, you would probably hear something but it would be distorted. Csound does show that 0.6 amplitude is being generated. Some other information that would be good: * What version of Csound on Android? * What device are you using for testing? (In particular, make/model of device, what kind of CPU, what version of Android) Thanks! steven On Sun, Dec 3, 2017 at 2:25 PM, Hector Centeno |
Date | 2017-12-03 21:03 |
From | Hector Centeno |
Subject | Re: [Csnd] Problems with C++ API and Android |
Hi Michael,
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
The exact same code works on Windows, so it seems that unreal uses samples in the -1 to 1 range. Unreal's buffer for both Windows and Android devices is set to 1024. I'm using performksmps, the spout buffer to get the samples, and I'm setting ksmps to 512 (stereo, so the final spout size will be 1024, correct?). Again this works well on Windows but no audio output on Android. Rory, in the same function call were the the csound samples are generated I'm also generating a sine wave for testing and I can hear it on Android. On Dec 3, 2017 2:56 PM, "Michael Gogins" <michael.gogins@gmail.com> wrote:
|
Date | 2017-12-03 21:45 |
From | Hector Centeno |
Subject | Re: [Csnd] Problems with C++ API and Android |
Hi Steven,
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Yes, sorry. I switched to using performksmps to see if that would make it work, which again works on Windows but not Android. I'm not setting -b and I assumed it's not necessary since I'm reading from spout, is that correct? And yes, I would expect to at least get distorted audio with a wrong buffer setup but it's just completely silent, except for my test tone, which is set to the left channel. I'm using Csound 6.09.1 on a Samsung S8. Android version is 7.0 Nougat. On Dec 3, 2017 3:47 PM, "Steven Yi" <stevenyi@gmail.com> wrote: Hi Hector, |
Date | 2017-12-04 18:09 |
From | Hector Centeno |
Subject | Re: [Csnd] Problems with C++ API and Android |
Just to make things easier to followup, here's the current code and CSD file: Thanks! On Sun, Dec 3, 2017 at 4:45 PM Hector Centeno <hcengar@gmail.com> wrote:
|
Date | 2017-12-05 05:07 |
From | Steven Yi |
Subject | Re: [Csnd] Problems with C++ API and Android |
One thing I can think of is that desktop Csound should be compiled for double precision, while Csound Android is compiled for single precision. You should be careful *not* to define USE_DOUBLE for Android to ensure MYFLT is a float there, and be careful not to share the same include folder when compiling on Desktop as on Android as there may be a float-version.h there for desktop that defines USE_DOUBLE. Could you check whether you have USE_DOUBLE defined or have a float-version.h somewhere? On Mon, Dec 4, 2017 at 1:09 PM, Hector Centeno |
Date | 2017-12-06 22:22 |
From | Hector Centeno |
Subject | Re: [Csnd] Problems with C++ API and Android |
Thanks Steven. Indeed, I'm sharing the same include folder for both build targets and there's a float-version.h file that defines USE_DOUBLE. Other than this file, are there any other ones in the include files that I should change/remove for the Android build?
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
On Tue, Dec 5, 2017 at 12:07 AM Steven Yi <stevenyi@gmail.com> wrote: One thing I can think of is that desktop Csound should be compiled for |
Date | 2017-12-06 22:33 |
From | Steven Yi |
Subject | Re: [Csnd] Problems with C++ API and Android |
I think that's the only thing. It looks to me that float-version.h that is used with the Android build is found here: https://github.com/csound/csound/blob/develop/android/CsoundAndroid/jni/float-version.h which just #undefs USE_DOUBLE On Wed, Dec 6, 2017 at 5:22 PM, Hector Centeno |
Date | 2017-12-07 02:35 |
From | Hector Centeno |
Subject | Re: [Csnd] Problems with C++ API and Android |
Ah! Yes! That was it. Thank you very much Steven. It works now! Cheers, Hector On Wed, Dec 6, 2017 at 5:33 PM Steven Yi <stevenyi@gmail.com> wrote: I think that's the only thing. It looks to me that float-version.h |
Date | 2017-12-07 05:19 |
From | Steven Yi |
Subject | Re: [Csnd] Problems with C++ API and Android |
Fantastic, glad that's working. Cheers! Steven
On Wed, Dec 6, 2017, 21:35 Hector Centeno <hcengar@gmail.com> wrote:
|