# GNU Radio on Android

**URL:** <https://www.ruby-forum.com/t/gnu-radio-on-android/234566>\
**Category:** GNU Radio\
**Created:** [March 13, 2015, 10:09pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566 "2015-03-13T22:09:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [March 13, 2015, 10:09pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/1 "2015-03-13T22:09:52Z")

</div>

Hi,

Has a patched version of GNU Radio which runs on Android been released?

I’m working on a project where I’m transmitting information over audio  
from a desktop system to an Android device, and since setting up the  
transmitter end with GNU Radio was such a snap I would love to leverage  
the GNU Radio system to build the receiver as well.

Thanks,  
Vijay

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 13, 2015, 10:42pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/2 "2015-03-13T22:42:36Z")

</div>

On Fri, Mar 13, 2015 at 5:04 PM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Vijay

Just yesterday, in fact:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Android](http://gnuradio.org/redmine/projects/gnuradio/wiki/Android)

I’ll try to release some of my apps soon. One of them captures from the  
audio device, even. It’s not too hard since there’s the gr-grand opensl  
audio source block to talk to the audio system.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 13, 2015, 11:22pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/3 "2015-03-13T23:22:47Z")

</div>

Thanks for the quick reply Tom! I’ll start with this right away. Looking  
forward to seeing your apps when you get a chance.

Thanks again,

Vijay

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-13-15 14:41  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Fri, Mar 13, 2015 at 5:04 PM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

Hi,

Has a patched version of GNU Radio which runs on Android been released?

I’m working on a project where I’m transmitting information over audio  
from a desktop system to an Android device, and since setting up the  
transmitter end with GNU Radio was such a snap I would love to leverage  
the GNU Radio system to build the receiver as well.

Thanks,  
Vijay

Just yesterday, in fact:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Android](http://gnuradio.org/redmine/projects/gnuradio/wiki/Android)

I’ll try to release some of my apps soon. One of them captures from the  
audio device, even. It’s not too hard since there’s the gr-grand opensl  
audio source block to talk to the audio system.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 16, 2015, 2:39pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/4 "2015-03-16T14:39:42Z")

</div>

On Mon, Mar 16, 2015 at 3:28 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> the shared library build:
> 
> Any tips appreciated,  
> Vijay

Yep, you have to add all of the libraries into the Android.mk file. I’ve  
updated the wiki:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps](http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps)

You can go there and simply download GrAndroid.mk that does all of this  
for  
you and include it in your Android.mk file. Just follow the  
instructions.

Hope that helps,

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 16, 2015, 8:30am UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/5 "2015-03-16T08:30:46Z")

</div>

Hi Tom,

I have been following your notes on the wiki in an attempt to build a  
test  
app (a dial tone flowgraph.) I’m hitting a snag on the ndk-build step  
though – when I use your example Android.mk listing, the linker isn’t  
finding any of the static libraries we built (gnuradio, grand, boost,  
fftw.)  
Instead I’m getting a pile of undefined reference errors.

I tried editing the example Android.mk file by adding the following  
before  
the shared library build:

include $(CLEAR\_VARS)  
LOCAL\_MODULE := grand\_static\_lib #for example  
LOCAL\_SRC\_FILES := /opt/grandroid/lib/libgnuradio-grand.a  
include $(PREBUILT\_STATIC\_LIBRARY)

However I quickly realised that while there are only a few gnuradio  
libraries to add this way, there are a ton of boost libraries… Is  
there a  
smarter way to add all the prebuilt .a libraries at once? Or am I headed  
in  
the wrong direction entirely?

Any tips appreciated,  
Vijay

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-13-15 14:41  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Fri, Mar 13, 2015 at 5:04 PM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi,

Has a patched version of GNU Radio which runs on Android been released?

I’m working on a project where I’m transmitting information over audio  
from a desktop system to an Android device, and since setting up the  
transmitter end with GNU Radio was such a snap I would love to leverage  
the GNU Radio system to build the receiver as well.

Thanks,  
Vijay

Just yesterday, in fact:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Android](http://gnuradio.org/redmine/projects/gnuradio/wiki/Android)

I’ll try to release some of my apps soon. One of them captures from the  
audio device, even. It’s not too hard since there’s the gr-grand opensl  
audio source block to talk to the audio system.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 17, 2015, 5:12am UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/6 "2015-03-17T05:12:18Z")

</div>

Thanks Tom, that sorted it out. My audio output is a bit choppy but no  
matter – time to move on to some more complex flowgraphs in my Android  
app.

Thanks again,  
Vijay

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-16-15 06:37  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Mon, Mar 16, 2015 at 3:28 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi Tom,

I have been following your notes on the wiki in an attempt to build a  
test  
app (a dial tone flowgraph.) I’m hitting a snag on the ndk-build step  
though – when I use your example Android.mk listing, the linker isn’t  
finding any of the static libraries we built (gnuradio, grand, boost,  
fftw.)  
Instead I’m getting a pile of undefined reference errors.

I tried editing the example Android.mk file by adding the following  
before  
the shared library build:

include $(CLEAR\_VARS)  
LOCAL\_MODULE := grand\_static\_lib #for example  
LOCAL\_SRC\_FILES := /opt/grandroid/lib/libgnuradio-grand.a  
include $(PREBUILT\_STATIC\_LIBRARY)

However I quickly realised that while there are only a few gnuradio  
libraries to add this way, there are a ton of boost libraries… Is  
there a  
smarter way to add all the prebuilt .a libraries at once? Or am I headed  
in  
the wrong direction entirely?

Any tips appreciated,  
Vijay

Yep, you have to add all of the libraries into the Android.mk file. I’ve  
updated the wiki:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps](http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps)

You can go there and simply download GrAndroid.mk that does all of this  
for  
you and include it in your Android.mk file. Just follow the  
instructions.

Hope that helps,

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-13-15 14:41  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android  
On Fri, Mar 13, 2015 at 5:04 PM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi,

Has a patched version of GNU Radio which runs on Android been released?

I’m working on a project where I’m transmitting information over audio  
from a desktop system to an Android device, and since setting up the  
transmitter end with GNU Radio was such a snap I would love to leverage  
the GNU Radio system to build the receiver as well.

Thanks,  
Vijay

Just yesterday, in fact:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Android](http://gnuradio.org/redmine/projects/gnuradio/wiki/Android)

I’ll try to release some of my apps soon. One of them captures from the  
audio device, even. It’s not too hard since there’s the gr-grand opensl  
audio source block to talk to the audio system.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 17, 2015, 3:38pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/7 "2015-03-17T15:38:09Z")

</div>

On Tue, Mar 17, 2015 at 12:10 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thanks Tom, that sorted it out. My audio output is a bit choppy but no  
> matter – time to move on to some more complex flowgraphs in my Android app.
> 
> Thanks again,  
> Vijay

Yes, the skipping in the audio output is a known bug, and apparently  
known  
to be difficult in Android. It’s going to take some kind of double  
buffering to fix it at this level. I did not experience any problems  
with  
the audio source, though; I just saved it to a file, brought it back to  
my  
computer, and played it there and it sounded fine.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 18, 2015, 6:47am UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/8 "2015-03-18T06:47:58Z")

</div>

Tom,

What kind of sample rate / setup are you using for your opensl\_source?  
I’ve  
set up a flowgraph that is just an opensl\_source (sampling at 48kHz)  
connected to a file sink, and when I play back the file through GRC on  
my  
desktop my audio is coming out pretty garbled, as if samples are being  
dropped. I’ve also tried a couple other sampling rates (44.1kHz, 32kHz,  
16kHz to name a few.) I’m using a Nexus 4 running Android 5.0.1. Pasted  
below is some of my code.

Vijay

Flowgraph code:  
JNIEXPORT void JNICALL  
Java\_com\_example\_grrecordmic\_GrRecordMic\_InitFlowgraph(JNIEnv\* env,  
jobject  
thiz, jstring jsinkfilename)  
{  
int rate = 48000;  
const char \*sinkfilename = env-\>GetStringUTFChars(jsinkfilename, 0);

```
global_tb = gr::make_top_block("Record_Mic");

gr::grand::opensl_source::sptr micSource =

```

gr::grand::opensl\_source::make(rate);  
gr::blocks::file\_sink::sptr fileSink =  
gr::blocks::file\_sink::make(sizeof(float), sinkfilename, false);

```
global_tb->connect(micSource, 0, fileSink, 0);

env->ReleaseStringUTFChars(jsinkfilename, sinkfilename);

```

}

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-17-15 07:37  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Tue, Mar 17, 2015 at 12:10 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Thanks Tom, that sorted it out. My audio output is a bit choppy but no  
matter – time to move on to some more complex flowgraphs in my Android  
app.

Thanks again,  
Vijay

Yes, the skipping in the audio output is a known bug, and apparently  
known  
to be difficult in Android. It’s going to take some kind of double  
buffering  
to fix it at this level. I did not experience any problems with the  
audio  
source, though; I just saved it to a file, brought it back to my  
computer,  
and played it there and it sounded fine.

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-16-15 06:37  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Mon, Mar 16, 2015 at 3:28 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi Tom,

I have been following your notes on the wiki in an attempt to build a  
test  
app (a dial tone flowgraph.) I’m hitting a snag on the ndk-build step  
though – when I use your example Android.mk listing, the linker isn’t  
finding any of the static libraries we built (gnuradio, grand, boost,  
fftw.)  
Instead I’m getting a pile of undefined reference errors.

I tried editing the example Android.mk file by adding the following  
before  
the shared library build:

include $(CLEAR\_VARS)  
LOCAL\_MODULE := grand\_static\_lib #for example  
LOCAL\_SRC\_FILES := /opt/grandroid/lib/libgnuradio-grand.a  
include $(PREBUILT\_STATIC\_LIBRARY)

However I quickly realised that while there are only a few gnuradio  
libraries to add this way, there are a ton of boost libraries… Is  
there a  
smarter way to add all the prebuilt .a libraries at once? Or am I headed  
in  
the wrong direction entirely?

Any tips appreciated,  
Vijay

Yep, you have to add all of the libraries into the Android.mk file. I’ve  
updated the wiki:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps](http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps)

You can go there and simply download GrAndroid.mk that does all of this  
for  
you and include it in your Android.mk file. Just follow the  
instructions.

Hope that helps,

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-13-15 14:41  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android  
On Fri, Mar 13, 2015 at 5:04 PM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi,

Has a patched version of GNU Radio which runs on Android been released?

I’m working on a project where I’m transmitting information over audio  
from a desktop system to an Android device, and since setting up the  
transmitter end with GNU Radio was such a snap I would love to leverage  
the GNU Radio system to build the receiver as well.

Thanks,  
Vijay

Just yesterday, in fact:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Android](http://gnuradio.org/redmine/projects/gnuradio/wiki/Android)

I’ll try to release some of my apps soon. One of them captures from the  
audio device, even. It’s not too hard since there’s the gr-grand opensl  
audio source block to talk to the audio system.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 19, 2015, 3:37pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/9 "2015-03-19T15:37:48Z")

</div>

On Thu, Mar 19, 2015 at 3:28 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> audio  
> will be very choppy (dropped samples?)
> 
> Vijay

Ah, ok, that makes sense. I think I was just playing around with those  
parameters and must have checked them in at that state.

I’ll make those updates to the repo.

Thanks.  
Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 18, 2015, 3:12pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/10 "2015-03-18T15:12:39Z")

</div>

On Wed, Mar 18, 2015 at 1:46 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Vijay
> 
> ```
> gr::grand::opensl_source::sptr micSource =
> 
> ```
> 
> gr::grand::opensl\_source::make(rate);  
> gr::blocks::file\_sink::sptr fileSink =  
> gr::blocks::file\_sink::make(sizeof(float), sinkfilename, false);
> 
> ```
> global_tb->connect(micSource, 0, fileSink, 0);
> 
> env->ReleaseStringUTFChars(jsinkfilename, sinkfilename);
> 
> ```
> 
> }

I believe that I used either 32k and/or 44.1k. I was using a Nexus 7,  
though, and the codec might play a significant role with this between  
the  
two devices.

Perhaps try setting the file sink to unbuffered mode?

```
fileSink->set_unbuffered(true);

```

Frankly, I feel like this is unlikely to help, but it’ll be interesting  
to  
know what happens.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 19, 2015, 8:30am UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/11 "2015-03-19T08:30:16Z")

</div>

Tom,

As you expected, disabling buffering on the file sink did not have any  
effect. I have fixed the issue though by making two changes to  
opensl\_source\_impl.cc:

1. change scale\_factor to 32768 (1/2^14 doesn’t make sense, it causes  
clipping because the volk conversion method divides by scale\_factor.)
2. change buffer size (d\_size) to 8k (2k was too small, tested  
32/44.1/48kHz  
on Nexus 4 and Nexus 7 2012 version.) Without this change the recorded  
audio  
will be very choppy (dropped samples?)

Vijay

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-18-15 07:11  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Wed, Mar 18, 2015 at 1:46 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Tom,

What kind of sample rate / setup are you using for your opensl\_source?  
I’ve  
set up a flowgraph that is just an opensl\_source (sampling at 48kHz)  
connected to a file sink, and when I play back the file through GRC on  
my  
desktop my audio is coming out pretty garbled, as if samples are being  
dropped. I’ve also tried a couple other sampling rates (44.1kHz, 32kHz,  
16kHz to name a few.) I’m using a Nexus 4 running Android 5.0.1. Pasted  
below is some of my code.

Vijay

Flowgraph code:  
JNIEXPORT void JNICALL  
Java\_com\_example\_grrecordmic\_GrRecordMic\_InitFlowgraph(JNIEnv\* env,  
jobject  
thiz, jstring jsinkfilename)  
{  
int rate = 48000;  
const char \*sinkfilename = env-\>GetStringUTFChars(jsinkfilename, 0);

```
global_tb = gr::make_top_block("Record_Mic");

gr::grand::opensl_source::sptr micSource =

```

gr::grand::opensl\_source::make(rate);  
gr::blocks::file\_sink::sptr fileSink =  
gr::blocks::file\_sink::make(sizeof(float), sinkfilename, false);

```
global_tb->connect(micSource, 0, fileSink, 0);

env->ReleaseStringUTFChars(jsinkfilename, sinkfilename);

```

}

I believe that I used either 32k and/or 44.1k. I was using a Nexus 7,  
though, and the codec might play a significant role with this between  
the  
two devices.

Perhaps try setting the file sink to unbuffered mode?

```
fileSink->set_unbuffered(true);

```

Frankly, I feel like this is unlikely to help, but it’ll be interesting  
to  
know what happens.

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-17-15 07:37  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Tue, Mar 17, 2015 at 12:10 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Thanks Tom, that sorted it out. My audio output is a bit choppy but no  
matter – time to move on to some more complex flowgraphs in my Android  
app.

Thanks again,  
Vijay

Yes, the skipping in the audio output is a known bug, and apparently  
known  
to be difficult in Android. It’s going to take some kind of double  
buffering  
to fix it at this level. I did not experience any problems with the  
audio  
source, though; I just saved it to a file, brought it back to my  
computer,  
and played it there and it sounded fine.

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-16-15 06:37  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Mon, Mar 16, 2015 at 3:28 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi Tom,

I have been following your notes on the wiki in an attempt to build a  
test  
app (a dial tone flowgraph.) I’m hitting a snag on the ndk-build step  
though – when I use your example Android.mk listing, the linker isn’t  
finding any of the static libraries we built (gnuradio, grand, boost,  
fftw.)  
Instead I’m getting a pile of undefined reference errors.

I tried editing the example Android.mk file by adding the following  
before  
the shared library build:

include $(CLEAR\_VARS)  
LOCAL\_MODULE := grand\_static\_lib #for example  
LOCAL\_SRC\_FILES := /opt/grandroid/lib/libgnuradio-grand.a  
include $(PREBUILT\_STATIC\_LIBRARY)

However I quickly realised that while there are only a few gnuradio  
libraries to add this way, there are a ton of boost libraries… Is  
there a  
smarter way to add all the prebuilt .a libraries at once? Or am I headed  
in  
the wrong direction entirely?

Any tips appreciated,  
Vijay

Yep, you have to add all of the libraries into the Android.mk file. I’ve  
updated the wiki:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps](http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps)

You can go there and simply download GrAndroid.mk that does all of this  
for  
you and include it in your Android.mk file. Just follow the  
instructions.

Hope that helps,

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-13-15 14:41  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android  
On Fri, Mar 13, 2015 at 5:04 PM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi,

Has a patched version of GNU Radio which runs on Android been released?

I’m working on a project where I’m transmitting information over audio  
from a desktop system to an Android device, and since setting up the  
transmitter end with GNU Radio was such a snap I would love to leverage  
the GNU Radio system to build the receiver as well.

Thanks,  
Vijay

Just yesterday, in fact:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Android](http://gnuradio.org/redmine/projects/gnuradio/wiki/Android)

I’ll try to release some of my apps soon. One of them captures from the  
audio device, even. It’s not too hard since there’s the gr-grand opensl  
audio source block to talk to the audio system.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 22, 2015, 11:30pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/12 "2015-03-22T23:30:42Z")

</div>

Hi guys,

Still stuck, but some relevant details have changed that may help answer  
my  
question. So I’m trying to implement a sink block for gnuradio-android  
that  
takes integers on its input (not chars as I had erroneously written  
before)  
and stores the last ‘length’ items in a LIFO buffer; the buffer’s  
contents  
are written to an Android TextView object every time the block’s work  
function is called. Following is the constructor I have written in order  
to  
pass this block the JNIEnv and jobject variables it needs in order to  
access  
the methods of my TextView instance:

```
stream_to_tv_sink_impl::stream_to_tv_sink_impl(JNIEnv *env, jobject 

```

jtv,  
int length)  
: gr::sync\_block(“stream\_to\_tv\_sink”,  
gr::io\_signature::make(1, 1, sizeof(int),  
gr::io\_signature::make(0, 0, 0)),  
d\_env(env),  
d\_jtv(jtv),  
d\_length(length)  
{  
d\_buffer = new string[length];  
for(int i = 0; i \< length; i++) {  
d\_buffer[i] = “0”;  
}  
d\_output = “Nothing yet…”;  
jclass d\_cls = env-\>GetObjectClass(jtv);  
jmethodID d\_mid = env-\>GetMethodID(d\_cls, “setText”,  
“(Ljava/lang/CharSequence;)V”);  
}

And here is my work function:

```
int
stream_to_tv_sink_impl::work(int noutput_items,
    gr_vector_const_void_star &input_items,
    gr_vector_void_star &output_items)
{
    const int *in = (const int *) input_items[0];

    // Update LIFO
    for(int i = d_length - 1; i > 0; i--) {
        d_buffer[i] = d_buffer[i-1];
    }
    d_buffer[0] = to_string(in[0]);

    // Construct output string, newest >> oldest (left to right)
    d_output = d_buffer[0];
    for(int i = 1; i < d_length; i++) {
    d_output += " " + d_buffer[i];
    }

    // Display output string -- Invoke setText method
    d_env->CallVoidMethod(d_jtv, d_mid,

```

d\_env-\>NewStringUTF(d\_output.c\_str())); // Might need to do this j times  
for  
j \< noutput\_items

```
    // Tell runtime system how many output items we produced.
    return noutput_items;
}

```

Where I am stuck is I cannot figure out how to come up with the  
appropriate  
makefile (using cmake or otherwise) to build this block into a prebuilt  
static library so that I may use it in my Android flowgraph, as shown  
for  
example in the instructions for building GNU Radio for Android and GRAnd  
at  
[https://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndBuild](https://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndBuild). I don’t  
have  
much experience tinkering with cmake but I’ve been looking over the  
cmake  
files in GRAnd and the android fork of gnuradio and I can’t figure out  
how  
to properly link to the JNI library to build this thing – or if  
statically  
linking to JNI types and methods in this manner is even possible. If it  
isn’t, I’m open to suggestions for alternative methods of displaying the  
flowgraph’s end results in my Android app; at the moment my flowgraph  
terminates in a file sink, and the app reads/displays a few entries from  
the  
file, but this not a good solution for when the flowgraph is running for  
more than 10 or 15 seconds.

Any advice appreciated,  
Vijay

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 23, 2015, 6:44pm UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/13 "2015-03-23T18:44:52Z")

</div>

On Sun, Mar 22, 2015 at 6:29 PM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> the methods of my TextView instance:  
> {  
> And here is my work function:  
> d\_buffer[i] = d\_buffer[i-1];  
> d\_env-\>CallVoidMethod(d\_jtv, d\_mid,  
> static library so that I may use it in my Android flowgraph, as shown for  
> the  
> file, but this not a good solution for when the flowgraph is running for  
> more than 10 or 15 seconds.
> 
> Any advice appreciated,  
> Vijay

Hi Vijay,

So at this point I think you might be the person with the second most  
experience with GNU Radio on Android and therefore the second most  
qualified to answer the question 🙂

I’m sitting in Android sessions at ELC right now, though, so I can’t go  
into details really here. All I’ll say is to look closer at gr-grand.  
Specifically, look at the float\_array block that I wrote. It uses  
jfloatArray and JNIEnv in creating this block, very much like how you  
want  
to handle your block. I might suggest adding your block (using  
gr\_modtool  
add in your checkout of gr-grand) directly to gr-grand and try and build  
it  
there, since that CMake handles the necessary includes/libs/etc that you  
need to get the linking to work. That might at least get you to a  
buildable  
block for your purposes. It might then help you understand what you need  
to  
do with your own OOT projects CMake files.

Tom

---

<div class="post-metadata">

**Author:** ![vijaygupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c2a13f/32.png) [@vijaygupta](https://www.ruby-forum.com/u/vijaygupta)\
**Post date:** [March 21, 2015, 8:52am UTC](https://www.ruby-forum.com/t/gnu-radio-on-android/234566/14 "2015-03-21T08:52:51Z")

</div>

Hi guys,

I am attempting to write an OOT module to be implemented on Android and  
am  
finding myself out of my depth here.

As a first step I was able to make and execute my flowgraph on my  
android  
device following the instructions on the wiki, using a file sink to  
store my  
end result (demodulated string.)

Now I would like to create my own sink which takes char inputs and  
updates a  
TextView object as they are ‘spat out’ by the flowgraph. I followed the  
general instructions on the wiki for coding an OOT module/object, so  
gr\_modtool generated all the boiler plate code and I have modified it  
accordingly.

Where I am hitting an issue is that I must pass JNIEnv\* and jobject  
arguments to my make (hence impl) functions in order to interact with  
the  
TextView object in my work function… but when I try to build the module  
I  
get the following error for example: “error: ‘JNIEnv’ has not been  
declared”,  
and similarly for all the jobject, jclass, and jmethodID occurrences. It  
would seem make doesn’t know how to find the JNI libraries (and I’m  
guessing  
volk is missing too,) and I’m unsure how to tell it where to look. Any  
thoughts? Or is there a smarter / less roundabout way altogether to  
display  
my flowgraph output in my Android activity?

Thanks,  
Vijay

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-19-15 07:36  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Thu, Mar 19, 2015 at 3:28 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Tom,

As you expected, disabling buffering on the file sink did not have any  
effect. I have fixed the issue though by making two changes to  
opensl\_source\_impl.cc:

1. change scale\_factor to 32768 (1/2^14 doesn’t make sense, it causes  
clipping because the volk conversion method divides by scale\_factor.)
2. change buffer size (d\_size) to 8k (2k was too small, tested  
32/44.1/48kHz  
on Nexus 4 and Nexus 7 2012 version.) Without this change the recorded  
audio  
will be very choppy (dropped samples?)

Vijay

Ah, ok, that makes sense. I think I was just playing around with those  
parameters and must have checked them in at that state.

I’ll make those updates to the repo.

Thanks.  
Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-18-15 07:11  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Wed, Mar 18, 2015 at 1:46 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Tom,

What kind of sample rate / setup are you using for your opensl\_source?  
I’ve  
set up a flowgraph that is just an opensl\_source (sampling at 48kHz)  
connected to a file sink, and when I play back the file through GRC on  
my  
desktop my audio is coming out pretty garbled, as if samples are being  
dropped. I’ve also tried a couple other sampling rates (44.1kHz, 32kHz,  
16kHz to name a few.) I’m using a Nexus 4 running Android 5.0.1. Pasted  
below is some of my code.

Vijay

Flowgraph code:  
JNIEXPORT void JNICALL  
Java\_com\_example\_grrecordmic\_GrRecordMic\_InitFlowgraph(JNIEnv\* env,  
jobject  
thiz, jstring jsinkfilename)  
{  
int rate = 48000;  
const char \*sinkfilename = env-\>GetStringUTFChars(jsinkfilename, 0);

```
global_tb = gr::make_top_block("Record_Mic");

gr::grand::opensl_source::sptr micSource =

```

gr::grand::opensl\_source::make(rate);  
gr::blocks::file\_sink::sptr fileSink =  
gr::blocks::file\_sink::make(sizeof(float), sinkfilename, false);

```
global_tb->connect(micSource, 0, fileSink, 0);

env->ReleaseStringUTFChars(jsinkfilename, sinkfilename);

```

}

I believe that I used either 32k and/or 44.1k. I was using a Nexus 7,  
though, and the codec might play a significant role with this between  
the  
two devices.

Perhaps try setting the file sink to unbuffered mode?

```
fileSink->set_unbuffered(true);

```

Frankly, I feel like this is unlikely to help, but it’ll be interesting  
to  
know what happens.

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-17-15 07:37  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Tue, Mar 17, 2015 at 12:10 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Thanks Tom, that sorted it out. My audio output is a bit choppy but no  
matter – time to move on to some more complex flowgraphs in my Android  
app.

Thanks again,  
Vijay

Yes, the skipping in the audio output is a known bug, and apparently  
known  
to be difficult in Android. It’s going to take some kind of double  
buffering  
to fix it at this level. I did not experience any problems with the  
audio  
source, though; I just saved it to a file, brought it back to my  
computer,  
and played it there and it sounded fine.

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-16-15 06:37  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android

On Mon, Mar 16, 2015 at 3:28 AM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi Tom,

I have been following your notes on the wiki in an attempt to build a  
test  
app (a dial tone flowgraph.) I’m hitting a snag on the ndk-build step  
though – when I use your example Android.mk listing, the linker isn’t  
finding any of the static libraries we built (gnuradio, grand, boost,  
fftw.)  
Instead I’m getting a pile of undefined reference errors.

I tried editing the example Android.mk file by adding the following  
before  
the shared library build:

include $(CLEAR\_VARS)  
LOCAL\_MODULE := grand\_static\_lib #for example  
LOCAL\_SRC\_FILES := /opt/grandroid/lib/libgnuradio-grand.a  
include $(PREBUILT\_STATIC\_LIBRARY)

However I quickly realised that while there are only a few gnuradio  
libraries to add this way, there are a ton of boost libraries… Is  
there a  
smarter way to add all the prebuilt .a libraries at once? Or am I headed  
in  
the wrong direction entirely?

Any tips appreciated,  
Vijay

Yep, you have to add all of the libraries into the Android.mk file. I’ve  
updated the wiki:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps](http://gnuradio.org/redmine/projects/gnuradio/wiki/GRAndApps)

You can go there and simply download GrAndroid.mk that does all of this  
for  
you and include it in your Android.mk file. Just follow the  
instructions.

Hope that helps,

Tom

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Tom  
Rondeau  
Sent: March-13-15 14:41  
To: Vijay G.  
Cc: GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] GNU Radio on Android  
On Fri, Mar 13, 2015 at 5:04 PM, Vijay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
Hi,

Has a patched version of GNU Radio which runs on Android been released?

I’m working on a project where I’m transmitting information over audio  
from a desktop system to an Android device, and since setting up the  
transmitter end with GNU Radio was such a snap I would love to leverage  
the GNU Radio system to build the receiver as well.

Thanks,  
Vijay

Just yesterday, in fact:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Android](http://gnuradio.org/redmine/projects/gnuradio/wiki/Android)

I’ll try to release some of my apps soon. One of them captures from the  
audio device, even. It’s not too hard since there’s the gr-grand opensl  
audio source block to talk to the audio system.

Tom
