This is only a preview of the July 2013 issue of Silicon Chip. You can view 19 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "DIY Wireless Audio Streaming":
Items relevant to "Li'l Pulser Model Train Controller, Mk.2":
Items relevant to "Add A UHF Link To A Universal Remote Control":
Items relevant to "Build A USB Port Voltage Checker":
Purchase a printed copy of this issue for $10.00. |
DIY
Wireless Audio
Streaming
By NICHOLAS VINEN
Our CLASSiC DAC (February-May 2013) has a USB socket and can
be connected to a PC, so you can play audio files on the computer
through a hifi system with top-notch sound quality. But what if your
hifi system isn’t in the same room as your computer? The answer
is that you can use a small and cheap router to wirelessly stream
audio between rooms. Here’s how.
A
FEW MONTHS AGO, we showed how to program a
tiny, cheap router with some open source software so
that it can act as a web server, control relays and do various other things (“Hacking a Mini Wireless Web Server”,
November and December 2012). In this article, we will take
a similar approach, configuring a slightly different router to
stream CD-quality audio over WiFi to a USB audio device
such as our CLASSiC DAC.
There are several reasons why you would want to do
this. First, if you’re listening to music with a reasonable
dynamic range, you don’t want a computer with a fan or
fans running in the same room; you will hear them during
the quieter passages.
Second, it’s much more convenient to select files to play
from a hard disk than it is to dig through a collection of
CDs, DVDs or other discs to find the one you want to play.
And if you’ve bought music from iTunes or a similar service, you may not have physical media at all. In fact, just
about anything you can play on your PC can be streamed
to a remote sound system.
24 Silicon Chip
If you have multiple computers in your home, they can
be set up so that any one of them can stream audio to the
hifi system using this approach. By the way, the unit we
describe here is also suitable for streaming audio over
wired Ethernet networks, if you already have the wiring
and sockets in place.
Commercial options
There are products you can buy to do this job but they
are generally not cheap and often have integrated amplifiers
and speakers with mediocre sound quality. The aim of this
article is to describe how to build your own network streaming solution and get the best possible audio quality but
there are off-the-shelf solutions which will do the job too.
If you would prefer to buy a commercial network
audio player, one option is to get one with a digital output
(TOSLINK or S/PDIF) and then you can connect it to the
CLASSiC DAC to ensure the best sound quality.
For Apple users, the easiest solution is to get a set of
wireless speakers supporting the “Airplay” protocol.
siliconchip.com.au
Fig.2: setting a PC’s Ethernet interface for a static IP address
in Windows 7. Change it back once you are finished.
Fig.1: various Australian online shops sell the D-Link DIR412 router for less than $20. These are also available from
overseas sellers via ebay or similar sites.
Other options (with varying operating system support)
include the Logitech Squeezebox, Netgear MP101, Marantz
NA7004 with external Ethernet/WiFi bridge and the Sonos
product range.
Many of these cost over $200 though and while they will
generally have more features than what we are describing here, we spent less than $20 on our router. In making
that comparison, we’re assuming you’ve already built the
CLASSiC DAC.
Wireless performance
To stream CD quality audio, you need a network link
with a throughput of at least 1.5Mbps and it has to be
pretty reliable – if the connection is dropping in and out
regularly, the audio will break up. Modern WiFi products
advertise speeds of 54Mbps, 108Mbps, 150Mbps and more.
So it would seem like this is a lay-down misère.
But there are various reasons why WiFi performance
often falls well short of the advertised speeds and in
some situations, it may be difficult to achieve the required
speed. The two main reasons are spectrum congestion (ie,
interference) and obstacles in the path of the microwaves.
Congestion will depend on how many other people with
WiFi networks and 2.4GHz cordless phones live in close
proximity to you. If you are in a large apartment block
or dense urban area, you will likely find dozens of WiFi
networks when scanning with your computer. In this case,
you should check that you can reach the required speed (eg,
by copying a file to a laptop near your hifi system) before
going ahead. 1.5Mbps is equivalent to roughly 200KB/s.
If you are near a lot of WiFi networks, you may be able
to improve the speed and reliability of the connection by
changing the channel(s) your WiFi router operates on, to
one of the less occupied channels. Changing the position
of its external antenna(s) (if present) may also help.
If buying a cordless telephone to use in a home with a
WiFi network, it’s best to pick one that doesn’t operate at
siliconchip.com.au
Fig.3: the DIR412’s recovery
page, accessed
by holding in the
reset button at
power-up, lets
you re-flash the
unit via this web
interface.
Fig.4: after uploading a new
image to the
device, it takes
about 90 seconds
to reconfigure
and reboot before
you can connect
to it.
2.4GHz. But note that WiFi networks can also operate at
5.17-5.825GHz (802.11a/n) so a 5.8GHz cordless phone
isn’t necessarily the answer either!
As for obstacles, walls and furniture are the most common and there isn’t much you can do about that but if the
connection is marginal, you may find that slight changes
in the position and orientation of the router(s) will make
the difference. This is likely due to a combination of the
antenna design (these days, often fractal) and standing
waves caused by reflections off walls and other internal
obstacles. Elevating the router may help, too.
We tested streaming in two environments. The first was
in a small office building with two other WiFi signals in
range, with the main router inside a steel rack cabinet (near
the top). The distance was about 10m with one plasterboard wall in the way. In this case, we got a reliable and
July 2013 25
Fig.5: once OpenWRT has been loaded on the router, the
next step is to set a root password via its web interface.
it’s fine for transmitting audio over Ethernet as long as you
disable its WiFi altogether.
As a result, we bought a D-Link DIR-412 instead, in the
hope that its slightly different hardware would not have the
same bug. Getting it up and running is a bit more difficult
since it isn’t as popular as the WR-703N and thus OpenWrt
has no official support for it. But we did eventually get it
working and were relieved to find its audio output is clean,
even when streaming over WiFi.
The steps required to set up a DIR-412 for WiFi audio
streaming are listed below. This unit is available from local
and overseas retailers at a similar price to the WR-703N.
At the time of writing, it was available from five different
Australian online retailers for less than $20 (not including
postage) – see Fig.1.
One of the great things about the DIR-412 is that it has a
reset button which can be used to activate an emergency
recovery mode, allowing you to re-flash it even if you have
accidentally “bricked” it.
In theory, any wireless router with USB ports and OpenWrt support can be used for this project – see http://wiki.
openwrt.org/toh/start But the DIR-412 is the model that we
know will work so we’re going to stick with it.
Problems with OpenWrt
Some readers who re-flashed a router using the steps
outlined in our previous articles (mentioned earlier) ran
into problems. We believe these are sorted out now. Check
the panel later in this article for details on what went wrong
and for the solutions.
Preparing the router
Here are the steps to set up the DIR-412 for wireless
audio streaming.
(1) Download the two required OpenWrt images. These are
available from http://downloads.openwrt.org/attitude_adjustment/12.09/ramips/rt305x/ and have the following file
names:
openwrt-ramips-rt305x-dir-615-d-squashfs-factory.bin
openwrt-ramips-rt305x-wr512-3gn-4M-squashfs-sysupgrade.bin
Fig.6: enter the device’s IP address, the user name “root”
and the password you have set into a Secure Copy (SCP)
program to copy the WiFi firmware off the device.
consistent connection of around 20Mbps, giving flawless
audio streaming.
The second environment was a medium-sized apartment
building with about 10 WiFi networks in range and a brick
wall between the two routers. The main router used was
an older model with a single external antenna and was
placed on a desk. In this case, speed was not an issue but
we had to play with the position of the receiving unit to
get a reliable connection with no drop-outs.
Our approach
We first tried setting up audio streaming via the TPLink WR-703N that we featured in our earlier articles on
router “hacking”. It did work but not reliably. With this
unit, when WiFi is enabled, USB audio has intermittent
clicks and pops, suggesting USB data packet corruption.
That rules that unit out for wireless streaming although
26 Silicon Chip
(2) Connect power to the DIR-412 while holding down
the recessed reset button at the rear, eg, with a paper clip.
Release it after about 10 seconds and the power LED should
be flashing orange.
(3) Temporarily disconnect your LAN cable (if present)
and connect the DIR-412’s Ethernet port to your PC; you
can use the supplied cable.
(4) Set your computer to use a static IP address of
192.168.0.2. In Windows 7, this can be done by going to
the Network and Sharing Centre (accessible via the Control
Panel), clicking “Change adapter settings”, double clicking
your Ethernet adaptor, clicking Properties, then doubleclicking on the TCP/IPv4 entry – see Fig.2.
Select “Use the following IP address” and enter
192.168.0.2 with a subnet mask of 255.255.255.0, then click
“OK” several times to close the remaining dialogs. Other
versions of Windows use a similar procedure.
(5) Point a web browser to http://192.168.0.1 (ie, type that
in the address bar) and you should get a screen like Fig.3.
siliconchip.com.au
Fig.7: after connecting to the DIR412 using WinSCP, navigate to the
firmware directory (at right) and
copy the RT305X.eeprom file to a
temporary location on your PC (left).
This is necessary as there is no official
OpenWRT image available for the
DIR-412 and doing so allows us to get
USB and WiFi both working at the
same time.
If not, check that the DIR-412 is in emergency recovery
mode (ie, flashing orange power LED) and check that the IP
is set correctly (eg, run “ipconfig” in a command prompt)
and the Ethernet cable is plugged in correctly at both ends.
(6) Click the “Select” button and then browse to the first
file you downloaded earlier, for the DIR-615 router.
(7) Click the “Proceed” button and you should then get a
screen similar to Fig.4. Don’t touch any of the cables to
the DIR-412 during the 90-second countdown as the unit
is re-flashed.
(8) Change your computer’s IP address to 192.168.1.2 using
the same procedure as in step 4.
(9) Point your browser at http://192.168.1.1 and you should
get the LuCI login screen (Fig.5). Click the “login” button.
(10) Click the link at the top of the screen to set a password,
then enter your chosen password in both boxes and click
the “Save & Apply” button in the bottom corner.
(11) Use an SCP program such as WinSCP to log into the
router with the user name “root”, your chosen password
and an IP address of 192.168.1.1 (Fig.6). When you get a
warning about the server’s host key not being found, click
“Yes” to proceed. You may also get a message “Error getting
name of current remote directory”; click OK to ignore it.
Copy the file /overlay/lib/firmware/RT305X.eeprom to your PC.
To find this, you may need to double-click the “..” entry
first – see Fig.7.
(12) Go back to the web interface, click the “System” tab
at the top, then the “Backup / Flash Firmware” tab that
appears below it. Near the bottom of the screen, under
“Flash new firmware image”, click on the Browse button
and choose the second OpenWrt file you downloaded, for
the WR512-3GN router (Fig.8). Click the “Flash Image”
button and it will verify that the file is valid (Fig.9); click
the button to proceed with re-flashing.
siliconchip.com.au
(13) Wait about 90 seconds and the web interface should
automatically re-load; if not, re-enter http://192.168.1.1 in
your browser address bar. You will need to log back in.
(14) Use SCP to copy the RT305X.eeprom file back onto the reflashed router, over the top of the file in /overlay/lib/firmware.
If asked whether to overwrite the existing file, select “Yes”.
(15) Go to the System tab on the web interface, then click
on the Reboot sub-tab under it at right and then click the
“Perform reboot” link.
(16) Once it has rebooted, log back into the web interface.
Click on the Network tab, then the WiFi sub-tab. Enable
WiFi using the button labelled as such and the wireless
LED on the router should turn green. Click “Scan”. You
should get a list of nearby wireless networks (Fig.10).
Click the appropriate “Join Network” button and enter
the password and other details required to access your
network. Select the “lan” firewall zone (green), click the
“Submit” button and then “Save & Apply” at the bottom.
(17) Wait about 20 seconds, then click on the Interfaces
sub-tab near the top of the screen and check that “WWAN”
is shown with a green background. If you have DHCP on
your network (most people do), the unit should have picked
up an IP address which will be shown to the right, under
IPv4 and it will normally start with “192.168”. Make a note
of this IP. Also go to the “Status” tab and write down the
Netmask, Gateway and DNS addresses under “Network”.
(18) Under Interfaces, click on the button to edit this
WWAN interface (at right) and then change “DHCP client” to “Static address”. Click “Switch protocol”, and in
the “IPv4 address” box which appears, enter the address
you want to assign to the router. It should be the same as
the address you noted in the last step except for the final
number.
You need to choose this number carefully so that it can’t
conflict with another device which has its IP address allocated automatically by the main router via DHCP. That
July 2013 27
(19a) Click on the Interface sub-tab again. What you do next
depends on whether you will be connecting the router to
Ethernet or just using wireless.
(19b) Wireless only: compare the IPv4 addresses for LAN
and WWAN. If they have the same first three digits (eg,
both start with 192.168.1) then you will need to change
the LAN IP address or else wireless will not work with the
Ethernet cable unplugged.
Click on the Edit button to the right of the LAN interface,
change the second-last digit in its address, then click the
Save & Apply button. Make a note of this new address since
if you lose access to the wireless network, you will need
to use this address to access the router; if all else fails, you
can always use the emergency recovery mode.
(19c) Wired and wireless: pick another address similar to
what you assigned to the wireless interface but not the same
(eg, 192.168.0.201) and assign this to the LAN interface,
using a similar procedure as in step 19b. Note that in this
case, if the unit is not connected to an Ethernet network,
the WiFi interface will be inoperative.
Fig.8: use the Flash operations tab to replace the current
firmware image with one that has USB support.
router will assign DHCP addresses with a range of numbers,
typically ending in a number between 10 and 100. Higher
numbers are generally safe, eg, between 200 and 250. If in
doubt, check your main router configuration.
Also enter the Netmask, Gateway and DNS addresses
that you noted earlier, then save and apply the changes.
Fig.9: after uploading the new image, you’re asked to verify
that it is correct and you want to proceed. If you use the file
we specified, your checksum should match ours.
28 Silicon Chip
(20) Unplug the Ethernet cable from the D-Link DIR-412
router and your PC, then re-connect your PC to its usual
network (if a cable was plugged in before). If you will be
using the DIR-412 with a wired connection, connect the
Ethernet cable.
(21) On your PC, point a browser at the IP address you
have assigned to the wireless network of the DIR-412, eg,
http://192.168.0.200 You should then be able to log into
the web interface as before. This confirms that the wireless
interface is working properly.
Fig.10: once the new WiFi firmware is in place, you can
perform a Wireless Scan and then find and connect to your
WiFi network.
siliconchip.com.au
Fig.11: this is the greeting screen after connecting to OpenWRT with a Secure Shell (SSH) program. You can then
install extra software and set it up using text commands.
(22) Use an SSH program such as PuTTY (Windows) or
OpenSSH (Linux/Mac) to login as root at this same IP address, using the same password as for the LuCI web interface. Again, we described how to do this in the November
2012 issue but if you install and run PuTTY, it should be
pretty easy to figure out. You should then get a text greeting screen as shown in Fig.11.
(23) Type the command “opkg update” and press enter.
It will then download the list of available packages from
the internet with the message “Updated list of available
packages ...”. If you get an error message instead, that suggests the gateway and/or DNS addresses entered earlier are
wrong; correct them via the web interface and try again.
(24) Once this list has updated, type opkg install netcat
kmod-usb-audio and press enter. This installs the USB audio
driver and a program to stream data over a TCP/IP network.
(25) To check that USB audio is working, plug the CLASS
iC DAC or a USB audio dongle into the port on the top of
the router and then type cat /proc/asound/cards. You should
get a result something like this:
Fig.12 (above): VLC is
a media player that’s
available for multiple
operating systems,
including Windows. It
can play audio to a file
on disk which we then
stream over the wireless
network.
Fig.13 (left): a shortcut
like this can then be
used to launch the software and start streaming audio at any time.
0 [CODEC ]: USB-Audio – USB Audio CODEC
Burr-Brown from TI USB Audio CODEC at usb-dwc_otg.0-1, full speed
Check that it is installed correctly by typing aplay -h – you
should get a long help text. Otherwise, one of the above
files may not have been copied correctly.
(26) Now for the audio playback software. This comes in
packages with other software we don’t want and which
won’t fit in flash. So we install them to a temporary location
in RAM and then copy just the required files into flash.
To do this, type opkg install -d ram alsa-utils and press Enter.
Several packages will be downloaded and installed. Then,
type the following series of commands:
(27) By default, audio played will be resampled to 48kHz.
But if you are mostly playing music from CDs, then these
will be 44.1kHz so to get the best audio quality, we want
to change this default rate. This can be done with the following command: sed -i s/48000/44100/ /usr/share/alsa/alsa.conf
Confirm this worked by running grep 44100 /usr/share/alsa/
alsa.conf and you should see: defaults.pcm.dmix.rate 44100
cp /tmp/lib/libpthread-0.9.33.2.so /tmp/lib/librt-0.9.33.2.so /lib
cd /lib
ln -s libpthread-0.9.33.2.so libpthread.so.0
ln -s librt-0.9.33.2.so librt.so.0
cp /tmp/usr/lib/libasound.so.2.0.0 /usr/lib
cd /usr/lib
ln -s libasound.so.2.0.0 libasound.so.2
cp /tmp/usr/bin/aplay /usr/bin
cp -R /tmp/usr/share/alsa /usr/share
(28) We are now ready to set up the streaming audio receiver. This can be done with the following command (be
careful to type it exactly and only press enter at the end):
siliconchip.com.au
echo ‘while [ 1 ]; do netcat -l -p 44100 | aplay -B 100000 -r 44100 -c
2 -f S16_LE -t raw -; done &’ > /etc/rc.local
Then to get it going, make sure the USB audio device is
plugged in and then type this command: source /etc/rc.local
This will happen automatically each time it boots from
now on.
July 2013 29
Problems With The WR-703N Router & OpenWRT
W
E GOT AN enthusiastic response to our articles on
re-flashing the WR703N mini router (“Hacking A Mini
Wireless Web Server”, November & December 2012).
Unfortunately though, some readers who purchased a
WR703N and attempted to re-flash it ran into problems.
There were two different reasons for this.
The first is that late last year, the manufacturers of the
WR703N brought out a new version of the device (v1.7) that
worked a bit differently from the previous version. Specifically, its bootloader software disables the Ethernet port on boot
and relies on the main program to re-enable it, something
that was not necessary with earlier versions of the device.
Note that many of the affected devices have a sticker on the
bottom incorrectly showing the version as 1.6.
The OpenWRT software has since been patched to fix
this (ie, enable Ethernet on boot), so if you buy one of these
routers now and attempt to flash it, it should work. But those
people who flashed their units before this fix was released
(right at the end of 2012/beginning of 2013) were left unable
to connect to it via either Ethernet, which was disabled, or
WiFi, which needs to be set up before it can be used.
In this case, the only solution is to solder a serial port
connector to three small pads on the PCB, as shown here:
http://forums.openpilot.org/blog/52/entry-92-unbrickwr703n-wifi-router/ You can then change settings or
re-flash the unit via a serial console, as described on that
web page. More information on the Ethernet boot problem
can be found at https://forum.openwrt.org/viewtopic.
php?id=40986
New versions of OpenWRT
Another problem that some readers encountered was that
they were unable to install certain packages using the opkg
program, mainly those starting with kmod. The problem
is that OpenWRT was a work in progress last year when
we published the articles describing how to re-flash the
WR703N. After you had re-flashed your unit, there was the
possibility that changes to the software on the OpenWRT
website would render the available packages incompatible
The DIR-412 is now ready to receive audio. Check that
the USB audio device is plugged into it and move on to
setting up your PC.
Streaming to it
To send audio to the unit, it’s simply a matter of making
a TCP connection on port 44,100 and sending a WAV file
containing the PCM audio data.
That sounds easy but we couldn’t easily find Windows
music players with this sort of capability so we’ve come
up with a small program which allows you do this. It’s
called “TCPWAVStream” and we are making the source
code and Windows executable file available for download.
It also builds and runs on Linux (make sure gcc and binutils
are installed, then run make). It will probably work in Mac
OSX too, since that is based on BSD. However, we haven’t
actually tried to compile it on a Mac.
This software can work in one of two ways. The simplest is to use a music/video player such as VLC. You can
30 Silicon Chip
with the now out-of-date version of the firmware on your
router.
In fact, the version of the software that we recommended
using, Attitude Adjustment, has now been finalised with
version 12.09 and they have started work on a new version called Barrier Breaker. Because we recommended
installing OpenWRT from the “trunk” repository, that means
that when they switched over from Attitude Adjustment
to Barrier Breaker, it became virtually impossible to install
kernel module packages as it would try to download files for
the wrong version.
If you have this problem, you have two options: either reflash your router with the latest version of Attitude Adjustment or move over to Barrier Breaker. In general, we recommend sticking with the former solution as it means you
are far less likely to run into this same module compatibility
problem in future although Barrier Breaker has some new
features which some people may wish to experiment with.
Either way, the procedure is similar. For Attitude Adjustment, download the latest sysupgrade firmware from this
location:
http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/openwrt-ar71xx-generic-tlwr703n-v1-squashfs-sysupgrade.bin
For Barrier Breaker, it can be found here:
http://downloads.openwrt.org/snapshots/trunk/ar71xx/
openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-sysupgrade.bin
Use the procedure described in this article (step 12) to
re-flash the router with this new firmware. Note that you may
need to re-install any packages you installed previously with
opkg after doing this.
Note also that you may already have Barrier Breaker
if you used the instructions we published previously after
the trunk had been switched over. And if you do, some of
the packages that we explained you should install in those
articles may not be necessary. For example, kmod-usbstorage may already be present and not required to access
a USB flash drive that’s plugged into the router.
download the Windows version for free from http://www.
videolan.org/vlc/download-windows.html
Once VLC is installed, you then set it up to output
sound to a WAV file. To do this, go to Tools -> Preferences ->
Audio and then change the Output module to “File audio
output”. Select a destination file on a drive with plenty of
free space. We set ours to c:\temp\temp.wav (see Fig.12; the
directory c:\temp must exist). You will then need to re-start
VLC for this to take effect.
Download and unzip TCPWAVStream.exe and cygwin1.dll
to a convenient location (eg, C:\Program Files), then create a
shortcut to the exe file on your desktop, or wherever you
prefer. Right-click on this shortcut, then select “Properties”
and change the Target field to add a space at the end, then
the name of your WAV file in quotes, then another space
and then the IP address of the router to stream to.
In our case, the Target field then contains (see Fig.13):
“C:\Program Files\TCPWAVStream.exe” “c:\temp\temp.wav”
192.168.0.200
siliconchip.com.au
Double-click this shortcut and it should open a text box.
Now play a file in VLC and you should see the buffer fill
up, as indicated by an increasing buffer percentage (Fig.14).
Once the buffer reaches about 70% full, assuming your
router is switched on and ready, the program will open a
connection and start streaming audio to it.
When this happens, the buffer percentage should drop
to about 50% and hover around that. Meanwhile, the lights
on the router will flash to indicate constant data reception
and audio playback should begin. Confirm this by listening
to the DAC’s output. To stream audio in future, assuming
the wireless router is powered on, you just need to launch
that shortcut and then play the file(s) in VLC.
Another option
If you want to use other audio software which doesn’t
have a WAV writer feature, there is another option. Download and install the latest version of the “Virtual Audio
Capture Grabber Device” from http://sourceforge.net/
projects/virtualaudiodev/files/
This software essentially allows you to record whatever
is being played from your PC, ie, it is a loopback device.
You can then feed this recorded audio to our streaming
software. Then anything you play on your PC will also be
sent to the router and thus to your hifi system. We don’t
know for sure whether this is a purely digital path or
whether noise and distortion can be introduced by this
process but it sounds reasonably clean.
Once you have installed the device, you can then create
a shortcut to start up the streaming. Navigate to the directory where is has installed ffmpeg.exe. In our case, this is
the following rather long path:
C:\Program Files (x86)\Virtual Audio Capture Grabber\screencapture-recorder-to-video-windows-free\configuration_setup_
utility\vendor\ffmpeg\bin
You will then need to create a batch file (eg, TCPWAVStream.
bat) to initiate streaming. This should contain the following,
which you will need to adjust depending on where your
ffmpeg.exe and TCPWAVStream.exe files are located:
cd “C:\Program Files (x86)\Virtual Audio Capture Grabber\screencapture-recorder-to-video-windows-free\configuration_setup_
utility\vendor\ffmpeg\bin”
ffmpeg -f dshow -i audio=virtual-audio-capturer -acodec pcm_s16le
-f wav -loglevel panic - | “c:\Program Files\TCPWAVStream.exe” 192.168.0.200
You can do this by typing those lines into notepad
(note: just two lines, one starting with “cd” and one with
“ffmpeg”) and then saving it as a file with a .bat (batch
file) extension.
Run this .bat file and you should get a result similar to
that described above although since this will be constantly
capturing audio whether or not you are playing anything,
it should begin buffering immediately.
Direct streaming
You can also use ffmpeg to decode and stream audio files
direct to the router without going through your system’s
sound card or a temporary file but you will need to use the
command line to play back files. All you need to do is use
the ffmpeg command above but get rid of the -f dshow and
-i audio=virtual-audio-capturer parameters and replace them
with the name and path of the file to be played.
This works in Linux too but is really only appropriate
siliconchip.com.au
Fig.14: our simple program runs in a command prompt
box and streams audio data when you are playing a file.
for advanced users who are comfortable with a command
line interface.
How our software works
While the TCPWAVStream program is rather elegant in its
operation (we think), it is still rather complex and we won’t
go into great detail here – if you’re interested, have a look
at the source code. But in brief, what it does is constantly
read from the end of the file specified (or standard input)
into a circular memory buffer while also emptying that
buffer to a TCP “socket” which sends the data to the router.
The WAV header contains the audio format details
(sampling rate, etc) and the router thus configures its audio
output to match that of your PC. Because the router only
consumes the data from its socket at its internal sampling
rate, this effectively throttles the emptying of the buffer.
While the sampling rate of the playback from your PC
will in theory match that of the audio device attached to
the router, in practice they will never be exactly the same
as they are using different crystals to derive the sampling
rate. This means that the memory buffer in the PC software
will slowly fill or empty over time. The software attempts
to keep the fill to about 50% by slightly shortening or
lengthening any periods of silence in the data it streams.
The software gracefully handles situations such as the
WAV file being deleted or truncated (which is what happens
when VLC starts playing a different file), the connection to
the router being dropped or the router being temporarily
unreachable and so on. Note that it will delete the WAV file
once it has finished reading it, if it remains unchanged for a
short period, so you should only point it at temporary files.
Also note that because there are multiple layers of buffering – ie, in VLC/Virtual Audio Grabber, the file system,
the TCPWAVStream software, the network buffers on both
ends, in the audio player on the router, its USB hardware
and in the USB device itself – there will be quite a delay
between starting or stopping playback and a change actually occurring at the output. This will be of the order of a
couple of seconds.
This isn’t normally a problem when playing music but if
you want to stream the audio from a video, you will need
to change the A/V synchronisation delay or else the audio
and video will not match up. With VLC, this can be done
using the “j” and “k” keys on your keyboard. Other video
playback software may or may not have this capability.
If you experience audio dropouts in the audio while
streaming, the likely cause is an unreliable WiFi link. Refer
to the section on wireless performance for information on
SC
likely methods to correct this.
July 2013 31
|