Final Year Progress Report – Jamie Sheridan - WordPress.com

kingfishblacksmithMobile - Wireless

Dec 14, 2013 (3 years and 10 months ago)

123 views

Department of Electronic and Computer Engineering





Final Year
Progress Report


Title:

Design and realization of wireless

speakers for an android device


Student:

Jamie Sheridan

08592853


Discipline:

Electronic and Computer
Engineering



Project Supervisor:

Dr. Peter Corcoran









Department of Electronic and Computer Engineering




Abstract


For the last few decades, the PC was the target platform for developers to design software
and the area in which programmers focused their expertise. In December 2011, Android
announced
that the number of total apps downloaded on the Android Market had reached a staggering 10
billion and that 200 million devices worldwide were now running the operating system which had
only been launched in 2007.

Of these 10 billion downloaded a
pps, apps categorized under “Music
and Audio” and “Media” possess 8% of market share.

Smart Phones have quickly become the central
computer and communication device in modern life, and the primary platform for software
development for the next decade and b
eyond.

With the advent of the Smart Phone, the technology behind real
-
time audio streaming is
changing as these phon
es are equipped with Wi
-
Fi and 3G

capabilities. Media Streaming requires a
network of connected devices and allows for the capability of da
ta being played while still being
transferred. One device hosts the media and streams it across the network and another device
processes the stream and outputs the audio.

In the not too distant future, all stereos will come equipped with smart phone funct
ionality.
These advancements will allow for sharing of your music library on your pho
ne wirelessly to other
devices















Department of Electronic and Computer Engineering




Table of Contents


Abstract

................................
................................
................................
................................
..................

ii

Table of Contents

................................
................................
................................
................................
.

iii

Chapter 1
-

Project Outline

................................
................................
................................
...................

iv

1.1.

Project Title

................................
................................
................................
..........................

iv

1.2.

Project Overview

................................
................................
................................
..................

iv

1.3.

Introduction to Progress report

................................
................................
..........................

iv

Chapter 2
-

Progress to date

................................
................................
................................
..................

v

2.1

Android Operating System

................................
................................
................................
..

v

2.2

Web Page

................................
................................
................................
...............................

v

2.3

Client

................................
................................
................................
................................
.....

vi

2.3.1

MainActivity

................................
................................
................................
.................

vi

2.3.2

TCPConnect

................................
................................
................................
.................

vi

2.3.3

ListSong

................................
................................
................................
........................

vi

2.3.4

TransferSong

................................
................................
................................
...............

vii

2.4

Server

................................
................................
................................
................................
..

viii

2.4.1

VLC & VLCJ

................................
................................
................................
.............

viii

2.5

Methods of Streaming

................................
................................
................................
..........

ix

2.5.1

User Datagram Protocol

................................
................................
..............................

ix

2.5.2

Real
-
time Transport Protocol and Real Time Streaming Protocol

.........................

ix

2.5.3

Transmission Control Protocol

................................
................................
...................

ix

2.6

Audio Compression

................................
................................
................................
...............

x

2.6.1

MP3

................................
................................
................................
................................

x

2.6.2

OGG

................................
................................
................................
..............................

xi

2.6.3

FLAC

................................
................................
................................
.............................

xi

Chapter 3
-

Task List and Project Plan

................................
................................
..............................

xii

3.1

Task List and Important Dates

................................
................................
..........................

xii

3.1.1 Pass

................................
................................
................................
................................
......

xii

3.1.2 Average

................................
................................
................................
...............................

xii

3.1.3 Good

................................
................................
................................
................................
....

xii

3.1.4 Very Good

................................
................................
................................
...........................

xii

3.1.5 Excellent

................................
................................
................................
..............................

xii

3.2

Project Plan

................................
................................
................................
........................

xiii

Chapter 4
-

Summary

................................
................................
................................
..........................

xiii

Chapter 5
-

References

................................
................................
................................
........................

xiv

Chapter 6

-

Glossary

................................
................................
................................
...........................

xiv

Department of Electronic and Computer Engineering




Cha
pter 1
-

Project Outline



1.1.

Project Title


Design and realization of wireless

speakers for an android device


1.2.

Project Overview



The idea behind this project is to design and build a set of wireless speakers which can receive
digital music streamed from a mobile phone. The speakers are most likely conventional speakers
and thus the project will require dealing
with
a number of techn
ical problems in algorithm design
for embedded systems.

The aim of this project is to design and build an embedded hardware unit that can

(i)

Receive streamed digital data over Wi
-
Fi in real time

(ii)

Detect and decompress, in real time, digital audio and

(iii)

Generate
analogue

audio output from the digital music stream


In addition the system will require software for the Android phone which can select music and
initiate and maintain a streamed network connection to the embedded hardware unit.

Due to the compl
exity of the system the student is encouraged to use COTS hardware modules
and open source software packages where available.





1.3.


Introduction to Progress report


This progress report is divided up into 3 sections:




Work done, progress to date



Proposals for tackling a couple of the main issues of the project



A development plan for the rest of the project


This document will be used as a reference and focus for directing future work, and will
provide a guide for the coming months, as it sets
out realistic goals and deadlines for the rest of
the project.

Department of Electronic and Computer Engineering




Cha
pter 2

-

Progress to date




2.1

Android Operating System


A
ndroid is a powerful

operating sy
s
tem

that was acquired by Google in 2005, it

runs
on mobile devices such as smart phones and tablets. Android is based on the Linux kernel
which allows Android to support device drivers, resource access, power management and
other OS duties.


A
pp
lication
s

that are developed for Android

are written i
n

Java
, the SDK pro
vides
tools and API’s that support
s
for development of mobile applications
.

These java applications
are compiled
into .apk format

which can be exported to android devices.


Android Development Tools (ADT)
is a plugin for th
e Eclipse IDE

that provides the
user with an environment
within
which they can develop their programs

Prior to starting the project I had no previous experi
ence with Android. So
initially
I

familiarised myself with the Android Development API and began work on a number of basic
apps
.




2.2

Web Page

An initial draft of a Web page

describing various aspects of the project was set up on
the 28
th

of October.

The Web Page consists of



Home Page



Introduction page that outlines initial details of the project



List of Milestones which are hoped to be achieved throughout the
project



Preliminary Report of the Project



Project Specification



Contacts


containing details of the student and project supervi
sor


The website can currently be viewed at
http://jsheridanfyp.wordpress.com/




Department of Electronic and Computer Engineering



2.3

Client


This is

where the majority of development has taken place thus far. The four major
classes which have been developed for the Client are



MainActivity



TcpConnect



ListSong



TransferSong



2.3.1

MainActivity


This class can be described as the homepage to the application. The activity is
initialised when the application is launched and a number of buttons are presented to the user.
As the application is still in an early stage of production
the UI is still very

rough.

Android has a media API that
is used to incorporate media files into your applications.

T
o
further my
understanding of this API
,

I enabled the MainActivity to have

the ability to play
music files on the phone and perform basic media operations such

as pause, restart and stop
song.

One class that proved quite helpful was
AudioTrack

which is useful when managing
audio resources.

Other buttons present in the MainActivity are used to launch different
activities in the application for different classes.



2.3.2

TCPConnect


This class displays servers which are currently operating and allows the user to
connect to whichever server he specifies

by clicking on a but
ton that represents that server,
selects it for setting up a stream.



2.3.3

ListSong

This class presents

the user with a listview
, which is a view that displays a scrolling
list

comprised of all the
audio

files present on the sdcard of the phone.

T
he following code
snippet is

a filter searching the SD card for all mp3 files

and appends the filenames to the l
ist
.






Department of Electronic and Computer Engineering












These MP3s are

then presented into a list view t
o the user and the user has the
ability
to click on one of these and the
songs details will be transferred to the TransferSong class
where the user will have the option to stream it to the server.








2.3.4

TransferSong


This class takes the song details which it receives

from ListSong
, and proceeds to
send the audio data to the server. Because TCP is the transfer protocol being used, the class
must utilise sockets to ensure reliable transfer of data. Before sending actual audio data, the
client must send the size of the f
ile so the server will

be able to

know when the file has been
fully transferred.











public

void

updateSongList() {




File home =
new

File(
MEDIA_PATH
);




if

(home.listFiles(
new

Mp3Filter()).
length

> 0) {





for

(File file : home.listFiles(
new

Mp3Filter())) {






songs
.add(file.getName());





}

ArrayAdapter<
String> songList =
new

ArrayAdapter<String>(
this
,R.layout.
song_item
,
songs
);





setListAdapter(songList);




}




}

protected

void

onListItemClick(ListView l, View v,
int

position,
long

id) {



Intent songTransfer =
new

Intent(ListSong.
this
, Tr
ansferSong.
class
);



String fileClicked = (String) getListAdapter().getItem(position);



songTransfer.putExtra(
"file chosen"
,fileClicked);



startActivity(songTransfer);





}

String audioFilePath = (String)
songSent
.getText();

file =
new

File(audioFilePath);

OutputStream os = socket.getOutputStream();




byte
[] filesize =
new

byte
[(
int
) (file).
length()];

os.write(filesize);


Department of Electronic and Computer Engineering






The audio data is split into chunks and streamed to the server individually until the
file has fully been sent.

















2.4

Server


The hardware that will be running the server

w
ill be a mini
-
ITX system booted with

Ubuntu Linux. The mini
-
PC chosen for the project is the

Zotac Z
BOX Nano”.

This will host
the server which the client will stream to. The program running on the
server will be
developed in java.

The system will have an audio output to allow for
convention
al speakers to
be connected to the system for analogue audio output.



At the time of writing this report a basic server has been
developed

that receives audio
data from the client
and

plays the audio file once it has fully been transferred.

The algorithm
for buffering audio data as it is being received has only been conceptualised yet.
The
server
will buffer received audio data for a short period before

starting to play audio while the rest
of the audio

data loads in the background.
If th
e player reaches t
he end of the
,

buffered audio
,
we transfer any newly downloaded audio to the player and let it start playing again.

The
buffer is assumed to be of a substantial size so that no packets are lost.


2.4.1

VLC &
VLCJ


For the early development of the server VLC has
been used to play the audio files
received from the client.
VLC is a free and open source cross platform multimedia player and
framework that plays most multimedia files.

One major advantage that VLC possesses over
some other multimedia players is that ope
rates as a “packet based multimedia player”
, which
is a benefit when streaming audio files to be played.

try{

int

count;

byte
[] buffer =
new

byte
[(
int
) file.length()];

while

((count = bis.read(buffer)) > 0)

{



os.write(buffer, 0, count);

}

os.close();

songSent
.setText(
"fin"
);

}

Department of Electronic and Computer Engineering




VLCJ is an open source java library framework which allows for basic features of
VLC to be employed in java applications such as play back controls,
volume controls, time
position controls etc.

The VLCJ class
EmbeddedMediaPlayerComponent

allows for VLC to
be easily em
bedded into a java application.



Another advantage at choosing VLC to be the media player is that there are currently
open source Android apps available where the app controls media playback of VLC
by
enabling its HTTP interface which I hope to incorporate into the client side further int
o the
project.


2.5

Methods of Streaming


`

F
or the project it was necessary

to pick a transfer protocol which would be most
suited towards

media streaming.
The following
protocols were taken into consideration

2.5.1

User Datagram Protocol

UDP is considered to be one of the core
transport

protocols.

UDP is considered to be
a low reliability as it is “connectionless”, meaning that when a datagram is sent, the sender
cannot be sure if it will be received at the other end. The client that is se
nding the packets will
continue to send datagrams and this will cause a noticeable glitch in the audio quality being
played. No ordering of the packets takes place.

2.5.2

Real
-
time Transport Protocol

and Real Time
Streaming Protocol


Similar to UDP,
RTSP strongly emphasizes continuous streaming over reliability.

UDP and RTSP place a high priority on continuous streaming rather than on absolute
security.

While RTP is highly suited to VOIP for real time conversation, it presents problems
for music as t
he ear is more sensitive

than your eye

and the user will notice dropped packets
in the audio quality
.


2.5.3

Transmission Control Protocol

TCP is classed as a “connection orientated” protocol; this is due to a technique known
as retransmission and acknowledgment
. This technique ensures a highly reliable and ordered
stream of packets. Problems such dropped

packets
, out of order

packets

or duplicated packets
are n
ot considered an issue with TCP

For the project I decided that TCP would be the most suited protocol to

ensure reliable high
quality streaming of audio

Reasons why TCP was chosen

Department of Electronic and Computer Engineering





Ordered data transfer



No need to worry about out of order packets



Retransmission of lost packets



Ensure no drop in audio quality



Error free data transfer



Flow control



Congestio
n control


2.6

Audio C
ompression


Even with advances
in

transmission protocols, the possibility of streaming audio at a
high scale would be near impossible without the technological advancements that have taken
place in
A
udio Compression
. These techniques are

heavily relied upon due to the sheer size
of uncompressed audio files.

These algorithms are known as audio codecs.

The size of the files is reduced by encoding the information present and using a
smaller number of bits.

This reduction in the number of bit
s will reduce traffic on a network
preventing network congestion and reducing the bandwidth required for transmission.

There are two
dedicated

audio compression algorithm
s, Lossy and L
ossless.

Lossless is an algorithm that allows for an identical replica
of the original audio
information to be rebuilt after compression takes place, in contrast

to Lossy where permanent
alter
ations occur to the audio data.

Lossy is capable of compressing audio files to a greater scale than Lossless by
discarding irrelevant audio data that cannot be heard by the human ear. Lossy is more
common in the compression of multimedia files while Lossless is used more so in
compressin
g of text documents.

The

server will be developed so as to capable of decompressing three different types
of audio formats



2.6.1

MP3

Mos
t prevalent audio format used worldwide. Developed in 1993 by Moving Pictures
Experts Group (MPEG), uses Lossy data
compression to take advantage of a concept known
as auditory masking. By using “
Psychoacoustics

models


to determine frequency levels
that
are outside of auditory perception,
the codec removes

these signals to reduce number of bits
present.

Decoding of MP3

on the server side will be implemented using JLayer Libraries
which provide the capability to decode the MP3 in real
-
time


Department of Electronic and Computer Engineering



2.6.2

OGG

Similar to MP3
,

in that it utilises Lossy to reduce file size. Newer than MP3 and
considered to provide a better sound quality, but unable to attain same worldwide status as
MP3. Designed to implement efficient streaming of audio.
Open source & patent free
.

LibOgg is an
open source java API that provides the functionality required to convert
Ogg bitstream and decode to raw PCM.


2.6.3

FLAC

Considered to be the most supported Lossless audio format. Due to the fact that
FLAC is lossless, no drop in quality occurs during compressi
on.

JFLAC

is an open source

library for java

that allows for use of FLAC with java
programs.


















Department of Electronic and Computer Engineering



Cha
pter 3
-

Task List and Project Plan


The project can be split into a set of principle tasks representing a progression towards
the end goal of

a working client
-
server, real
-
time audio infrastructure. The successful
completion of each task will contribute towards the student’s final grade.


3.1

Task List and Important Dates


3.1.1

Pass

Become familiar with the basics of Linux and Android; install Lin
ux on a
desktop PC; install the Android development kit and learn basic programming;
demonstrate streaming and playback of audio on an Android device simulator
or equivalent test environment.


Prepare technical specifications for the hardware unit; review
some available
COTS solutions and chose one suitable to meet the requirements


3.1.2
Average

Program the selected hardware unit to decompress at least one digital audio
format and demonstrate playback in real
-
time

Implement/program at least one additional
compressed audio format, or
configure and use a suitable open
-
source library which supports multiple
formats

3.1.3
Good

Implement and program a server appliance which can accept a network
connection from an audio streaming client and investigate the requir
ements for
real
-
time audio and synchronization of multiple
streams;

pay particular
attention to the compromises between reliable data transfer using TCP/IP,
real
-
time data transfer using RTP/RTCP

3.1.4
Very Good

Design and implement a real
-
time audio strea
m receiver


3.1.5
Excellent

Program an audio streaming client, and demonstrate full system functionality
including a mechanism to handle stream
-
switching, ideally minimizing the
time taken

Department of Electronic and Computer Engineering






3.2

Project Plan


The following is a graphical representation
outlining the tasks list and allocating a
dedicated time period to each task so as to maximize efficiency.





Cha
pter 4

-

Summary


Based on the progress made so far with both the server and the client aspects of the project,
a functional prototype that
demonstrates full system functionality is a very realistic goal.


Department of Electronic and Computer Engineering



Cha
pter 5
-

References




Most of the research for this project has been possible due to information available at the following
locations:

http://www.javazoom.net/javalayer/javalayer.html

http://www.xiph.org/ogg/doc/libogg/overview.html

http://jflac.sourceforge.net/

http://code.google.com/p/vlcj/

http://www.videolan.org/vlc/

http://source.android.com/


Chapter 6

-

Glossary


VLC


VideoLan Client

COTS


Commercial off the shelf

API


Application Programming Interface

SDK
-

Software Development Kit

IDE


Integrated Development Environment

ADT


Android Development Tools


UI


User Interface

UDP



User Datagram Protocol

TCP



Trans
mission Control Protocol

RTP



Real
-
Time Transport Protocol

RTCP



Real
-
Time Transport Control Protocol

FLAC


Free Lossless Audio Codec

PCM


Pulse Code Modulation