Csound Csound-dev Csound-tekno Search About

Csound Android Qt Channels

Date2016-08-06 01:23
FromTarmo Johannes
SubjectCsound Android Qt Channels

Hi,

 

has anyone experience or can guess what is wrong -

 

I am writing an Csound Android app using C++ and Qt, everything else works fine via the API but SetChannel and GetChannel give wrong results

 

whet I use setChannel("value",0.5)

Csound receives values like -107374184.00000 or 272008302207532160516096.00000

 

and when I use getChannel I get results like -3.105004892455137e+201

 

The setChannel function of my object looks:

 

void CsoundObject::setChannel(QString channel, MYFLT value) {

qDebug()<<"channel: "<<channel << " value: "<<value;

cs.SetChannel(channel.toLocal8Bit(),value);

}

 

 

The qDebug line reports that the function receives the value correctly but it does not reach csound.

 

cs is an object of type AndroidCsound

 

 

I paste the code of the whole object below.

 

 

I am using CsoundFor Android 6.07.0 and Qt 5.5.1 I am testing on an Android phone with 4-core ARM (armeabi-7) processor.

 

I remember that similar things worked before with Qt 4.8 and Csound 5.19.

 

Can anyone guess, what is the reason? Rory, how do you use channel business in Cabbage-Android?

 

The same thing works on desktop. So it is either Android ir Qt-Android issue. Some strange conversion? Or Thread issues?

 

All help or ideas very welcome!

tarmo

 

-----------

/*

Copyright (C) 2016 Tarmo Johannes

trmjhnns@gmail.com

 

This file is part of eClick.

 

eClick is free software; you can redistribute it and/or modify it

under the terms of the GNU GENERAL PUBLIC LICENSE Version 3,

published by Free Software Foundation, Inc. <http://fsf.org/>

 

eClick is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

 

You should have received a copy of the GNU Lesser General Public

License along with eClick; if not, write to the Free Software

Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA

02111-1307 USA

*/

 

#include "csoundobject.h"

#include <QDebug>

#include <QThread>

#include <QCoreApplication>

 

CsoundObject::CsoundObject(QObject *parent) : QObject(parent)

{

stopNow = false;

 

}

 

void CsoundObject::play() {

//cs = new Csound();

 

//#ifdef Q_OS_ADNROID

// cs = AndroidCsound();

//#else

// cs = Csound();

//#endif

 

#ifdef Q_OS_ANDROID

cs.setOpenSlCallbacks(); // for android audio to work

#endif

cs.SetOption("-odac");

cs.SetOption("-d");

qDebug()<<"CsObject thread: " << QThread::currentThreadId();

 

QString orc =R"(

sr = 44100

nchnls = 2

0dbfs = 1

ksmps = 44100

 

chn_k "value",3

 

chnset 0.5,"value"

 

schedule "test",0,0.5

 

instr test

prints "INSTR TEST"

kval chnget "value"

kval = abs(kval)

printk2 kval

kfreq = 300+400*kval

asig vco2 linen(0.5,0.05,p3,0.1), kfreq

asig moogvcf asig, 400+600*(1-kval), 0.3+(1-kval)/2

outs asig, asig

endin

 

schedule "channelTest",0,-1

instr channelTest

kvalue chnget "value"

printk2 kvalue

endin

 

 

)";

 

//int ret = cs.Compile("test.csd");// (csd.toLocal8Bit().data()); // ERROR HANDLING!

int ret = cs.CompileOrc(orc.toLocal8Bit());

if (!ret) {

qDebug()<<"Compiled OK";

cs.Start();

cs.SetChannel("value",0.2);

// CSOUND * csound = cs.GetCsound();

// csoundSetControlChannel(csound, "value", 0.34);

 

while (cs.PerformKsmps()==0 && !stopNow) {

//qDebug()<<"LOOP";

//stopNow=true;

//double value = (MYFLT) (qrand() % 20);

//qDebug()<<value;

//cs.SetChannel("value", value );

// csoundSetControlChannel(csound, "value", value);

QCoreApplication::processEvents(); // probably bad solution but works. otherwise other slots will never be calles

}

 

}

qDebug()<<"Stopping csound";

cs.Stop();

//delete cs;

stopNow = false;

 

}

 

void CsoundObject::stop() {

stopNow = true;

}

 

void CsoundObject::setChannel(QString channel, MYFLT value) {

qDebug()<<"channel: "<<channel << " value: "<<value;

cs.SetChannel(channel.toLocal8Bit(),value);

}

 

double CsoundObject::getChannel(QString channel)

{

MYFLT value = cs.GetChannel(channel.toLocal8Bit() );

qDebug()<<"Value from "<<channel<<" :"<< value;

return value;

}

 

void CsoundObject::scoreEvent(QString event)

{

qDebug()<<"New event: "<<event;

cs.InputMessage(event.toLocal8Bit());

}

 

 


Date2016-08-06 01:41
FromMichael Gogins
SubjectRe: Csound Android Qt Channels

Check your numeric types. Perhaps you are forcing one size of floating point number to fit in another size.

Regards,
Mike


On Aug 5, 2016 8:23 PM, "Tarmo Johannes" <tarmo.johannes@otsakool.edu.ee> wrote:

Hi,

 

has anyone experience or can guess what is wrong -

 

I am writing an Csound Android app using C++ and Qt, everything else works fine via the API but SetChannel and GetChannel give wrong results

 

whet I use setChannel("value",0.5)

Csound receives values like -107374184.00000 or 272008302207532160516096.00000

 

and when I use getChannel I get results like -3.105004892455137e+201

 

The setChannel function of my object looks:

 

void CsoundObject::setChannel(QString channel, MYFLT value) {

qDebug()<<"channel: "<<channel << " value: "<<value;

cs.SetChannel(channel.toLocal8Bit(),value);

}

 

 

The qDebug line reports that the function receives the value correctly but it does not reach csound.

 

cs is an object of type AndroidCsound

 

 

I paste the code of the whole object below.

 

 

I am using CsoundFor Android 6.07.0 and Qt 5.5.1 I am testing on an Android phone with 4-core ARM (armeabi-7) processor.

 

I remember that similar things worked before with Qt 4.8 and Csound 5.19.

 

Can anyone guess, what is the reason? Rory, how do you use channel business in Cabbage-Android?

 

The same thing works on desktop. So it is either Android ir Qt-Android issue. Some strange conversion? Or Thread issues?

 

All help or ideas very welcome!

tarmo

 

-----------

/*

Copyright (C) 2016 Tarmo Johannes

trmjhnns@gmail.com

 

This file is part of eClick.

 

eClick is free software; you can redistribute it and/or modify it

under the terms of the GNU GENERAL PUBLIC LICENSE Version 3,

published by Free Software Foundation, Inc. <http://fsf.org/>

 

eClick is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

 

You should have received a copy of the GNU Lesser General Public

License along with eClick; if not, write to the Free Software

Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA

02111-1307 USA

*/

 

#include "csoundobject.h"

#include <QDebug>

#include <QThread>

#include <QCoreApplication>

 

CsoundObject::CsoundObject(QObject *parent) : QObject(parent)

{

stopNow = false;

 

}

 

void CsoundObject::play() {

//cs = new Csound();

 

//#ifdef Q_OS_ADNROID

// cs = AndroidCsound();

//#else

// cs = Csound();

//#endif

 

#ifdef Q_OS_ANDROID

cs.setOpenSlCallbacks(); // for android audio to work

#endif

cs.SetOption("-odac");

cs.SetOption("-d");

qDebug()<<"CsObject thread: " << QThread::currentThreadId();

 

QString orc =R"(

sr = 44100

nchnls = 2

0dbfs = 1

ksmps = 44100

 

chn_k "value",3

 

chnset 0.5,"value"

 

schedule "test",0,0.5

 

instr test

prints "INSTR TEST"

kval chnget "value"

kval = abs(kval)

printk2 kval

kfreq = 300+400*kval

asig vco2 linen(0.5,0.05,p3,0.1), kfreq

asig moogvcf asig, 400+600*(1-kval), 0.3+(1-kval)/2

outs asig, asig

endin

 

schedule "channelTest",0,-1

instr channelTest

kvalue chnget "value"

printk2 kvalue

endin

 

 

)";

 

//int ret = cs.Compile("test.csd");// (csd.toLocal8Bit().data()); // ERROR HANDLING!

int ret = cs.CompileOrc(orc.toLocal8Bit());

if (!ret) {

qDebug()<<"Compiled OK";

cs.Start();

cs.SetChannel("value",0.2);

// CSOUND * csound = cs.GetCsound();

// csoundSetControlChannel(csound, "value", 0.34);

 

while (cs.PerformKsmps()==0 && !stopNow) {

//qDebug()<<"LOOP";

//stopNow=true;

//double value = (MYFLT) (qrand() % 20);

//qDebug()<<value;

//cs.SetChannel("value", value );

// csoundSetControlChannel(csound, "value", value);

QCoreApplication::processEvents(); // probably bad solution but works. otherwise other slots will never be calles

}

 

}

qDebug()<<"Stopping csound";

cs.Stop();

//delete cs;

stopNow = false;

 

}

 

void CsoundObject::stop() {

stopNow = true;

}

 

void CsoundObject::setChannel(QString channel, MYFLT value) {

qDebug()<<"channel: "<<channel << " value: "<<value;

cs.SetChannel(channel.toLocal8Bit(),value);

}

 

double CsoundObject::getChannel(QString channel)

{

MYFLT value = cs.GetChannel(channel.toLocal8Bit() );

qDebug()<<"Value from "<<channel<<" :"<< value;

return value;

}

 

void CsoundObject::scoreEvent(QString event)

{

qDebug()<<"New event: "<<event;

cs.InputMessage(event.toLocal8Bit());

}

 

 

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
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

Date2016-08-06 02:23
FromTarmo Johannes
SubjectRe: Csound Android Qt Channels

I think I made some progress,

 

it is connected to threads and android seems to be very strict with it (and maybe Qt adds another layer) and wheter objects are allocated in heap (with new() ) or stack (just CsoundObject cs; )

 

I keeo investigeting but at least setChannel is now working.

 

On Friday, August 05, 2016 08:41:53 PM you wrote:

> Check your numeric types. Perhaps you are forcing one size of floating

> point number to fit in another size.

>

> Regards,

> Mike

>

> On Aug 5, 2016 8:23 PM, "Tarmo Johannes" <tarmo.johannes@otsakool.edu.ee>

>

> wrote:

> > Hi,

> >

> >

> >

> > has anyone experience or can guess what is wrong -

> >

> >

> >

> > I am writing an Csound Android app using C++ and Qt, everything else works

> > fine via the API but SetChannel and GetChannel give wrong results

> >

> >

> >

> > whet I use setChannel("value",0.5)

> >

> > Csound receives values like -107374184.00000 or

> > 272008302207532160516096.00000

> >

> >

> >

> > and when I use getChannel I get results like -3.105004892455137e+201

> >

> >

> >

> > The setChannel function of my object looks:

> >

> >

> >

> > void CsoundObject::setChannel(QString channel, MYFLT value) {

> >

> > qDebug()<<"channel: "<<channel << " value: "<<value;

> >

> > cs.SetChannel(channel.toLocal8Bit(),value);

> >

> > }

> >

> >

> >

> >

> >

> > The qDebug line reports that the function receives the value correctly but

> > it does not reach csound.

> >

> >

> >

> > cs is an object of type AndroidCsound

> >

> >

> >

> >

> >

> > I paste the code of the whole object below.

> >

> >

> >

> >

> >

> > I am using CsoundFor Android 6.07.0 and Qt 5.5.1 I am testing on an

> > Android phone with 4-core ARM (armeabi-7) processor.

> >

> >

> >

> > I remember that similar things worked before with Qt 4.8 and Csound 5.19.

> >

> >

> >

> > Can anyone guess, what is the reason? Rory, how do you use channel

> > business in Cabbage-Android?

> >

> >

> >

> > The same thing works on desktop. So it is either Android ir Qt-Android

> > issue. Some strange conversion? Or Thread issues?

> >

> >

> >

> > All help or ideas very welcome!

> >

> > tarmo

> >

> >

> >

> > -----------

> >

> > /*

> >

> > Copyright (C) 2016 Tarmo Johannes

> >

> > trmjhnns@gmail.com

> >

> >

> >

> > This file is part of eClick.

> >

> >

> >

> > eClick is free software; you can redistribute it and/or modify it

> >

> > under the terms of the GNU GENERAL PUBLIC LICENSE Version 3,

> >

> > published by Free Software Foundation, Inc. <http://fsf.org/>

> >

> >

> >

> > eClick is distributed in the hope that it will be useful,

> >

> > but WITHOUT ANY WARRANTY; without even the implied warranty of

> >

> > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

> >

> > GNU General Public License for more details.

> >

> >

> >

> > You should have received a copy of the GNU Lesser General Public

> >

> > License along with eClick; if not, write to the Free Software

> >

> > Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA

> >

> > 02111-1307 USA

> >

> > */

> >

> >

> >

> > #include "csoundobject.h"

> >

> > #include <QDebug>

> >

> > #include <QThread>

> >

> > #include <QCoreApplication>

> >

> >

> >

> > CsoundObject::CsoundObject(QObject *parent) : QObject(parent)

> >

> > {

> >

> > stopNow = false;

> >

> >

> >

> > }

> >

> >

> >

> > void CsoundObject::play() {

> >

> > //cs = new Csound();

> >

> >

> >

> > //#ifdef Q_OS_ADNROID

> >

> > // cs = AndroidCsound();

> >

> > //#else

> >

> > // cs = Csound();

> >

> > //#endif

> >

> >

> >

> > #ifdef Q_OS_ANDROID

> >

> > cs.setOpenSlCallbacks(); // for android audio to work

> >

> > #endif

> >

> > cs.SetOption("-odac");

> >

> > cs.SetOption("-d");

> >

> > qDebug()<<"CsObject thread: " << QThread::currentThreadId();

> >

> >

> >

> > QString orc =R"(

> >

> > sr = 44100

> >

> > nchnls = 2

> >

> > 0dbfs = 1

> >

> > ksmps = 44100

> >

> >

> >

> > chn_k "value",3

> >

> >

> >

> > chnset 0.5,"value"

> >

> >

> >

> > schedule "test",0,0.5

> >

> >

> >

> > instr test

> >

> > prints "INSTR TEST"

> >

> > kval chnget "value"

> >

> > kval = abs(kval)

> >

> > printk2 kval

> >

> > kfreq = 300+400*kval

> >

> > asig vco2 linen(0.5,0.05,p3,0.1), kfreq

> >

> > asig moogvcf asig, 400+600*(1-kval), 0.3+(1-kval)/2

> >

> > outs asig, asig

> >

> > endin

> >

> >

> >

> > schedule "channelTest",0,-1

> >

> > instr channelTest

> >

> > kvalue chnget "value"

> >

> > printk2 kvalue

> >

> > endin

> >

> >

> >

> >

> >

> > )";

> >

> >

> >

> > //int ret = cs.Compile("test.csd");// (csd.toLocal8Bit().data()); // ERROR

> > HANDLING!

> >

> > int ret = cs.CompileOrc(orc.toLocal8Bit());

> >

> > if (!ret) {

> >

> > qDebug()<<"Compiled OK";

> >

> > cs.Start();

> >

> > cs.SetChannel("value",0.2);

> >

> > // CSOUND * csound = cs.GetCsound();

> >

> > // csoundSetControlChannel(csound, "value", 0.34);

> >

> >

> >

> > while (cs.PerformKsmps()==0 && !stopNow) {

> >

> > //qDebug()<<"LOOP";

> >

> > //stopNow=true;

> >

> > //double value = (MYFLT) (qrand() % 20);

> >

> > //qDebug()<<value;

> >

> > //cs.SetChannel("value", value );

> >

> > // csoundSetControlChannel(csound, "value", value);

> >

> > QCoreApplication::processEvents(); // probably bad solution but works.

> > otherwise other slots will never be calles

> >

> > }

> >

> >

> >

> > }

> >

> > qDebug()<<"Stopping csound";

> >

> > cs.Stop();

> >

> > //delete cs;

> >

> > stopNow = false;

> >

> >

> >

> > }

> >

> >

> >

> > void CsoundObject::stop() {

> >

> > stopNow = true;

> >

> > }

> >

> >

> >

> > void CsoundObject::setChannel(QString channel, MYFLT value) {

> >

> > qDebug()<<"channel: "<<channel << " value: "<<value;

> >

> > cs.SetChannel(channel.toLocal8Bit(),value);

> >

> > }

> >

> >

> >

> > double CsoundObject::getChannel(QString channel)

> >

> > {

> >

> > MYFLT value = cs.GetChannel(channel.toLocal8Bit() );

> >

> > qDebug()<<"Value from "<<channel<<" :"<< value;

> >

> > return value;

> >

> > }

> >

> >

> >

> > void CsoundObject::scoreEvent(QString event)

> >

> > {

> >

> > qDebug()<<"New event: "<<event;

> >

> > cs.InputMessage(event.toLocal8Bit());

> >

> > }

> >

> >

> >

> >

> > 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

>

> 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