Specifications

Receive MP3
data from
server
Increment the
receive
pointer
Reset the
po inter if it is
past the buffer
boundary
Is the
buffer set
to refill
Is it full
Start the
decoder
Calculate the
buffer size
If buffer is empty
set the buffer to
refill
Is the
buffer
full
Wait for there to be
room in the buffer
for another receive.
No
Yes
No
Yes
Yes
No
Stop button
ISR
Main thread
Disable button
interrupt
The player
Is send
enabled
Read file into
buffer
If at end of file
call op enM P3 to
open the next
song
Send MP3 data
Main thread
Receive command
from player
Decode the
message
If
UNPAUSE
If PAUSE
Enable
send
Disable
send
Thread 2
Server
Yes
No
Yes
Yes
No
No
Disable transfer
to the decoder
Set buffer to
discard
Send STOP
command to
the server
If set to
discard
Is GAP
in buffer
Disable discard and
set pointers to the
data after GAP
Yes
No Yes
No
If STOP
Disable
send
Set variable
to send
GAP
Call
openMP3
ro reopen
current file
No
Yes
If GAP send has
been selected
send the GAP
Figure 23 Buttons with GAP message for buffer control
If the stop, next, or previous button were pressed on the player they enabled a global
variable called ‘discard’. When this variable was set and play was re-enabled, the
receive buffer was not incremented until it receives the string “GAP”. At this point it
would turn off discard and set the transmit buffer to the position after the P in GAP and
the receive pointer would be moved to the end of the packet just received. The program
is then free to start filling the buffer with the new data. When the buffer gets full, the
software interrupt triggers the decoder to start receiving. The result of testing was that
the amount of old data that was being played was greatly reduced but there was still a
very small amount of old data still being played. The reason for this became very
confusing. It did not seem possible that the GAP was some how getting in the middle of
the old data. This was simply not possible in the TCP system because TCP guarantees
order of delivery. Therefore, it seemed it was something to do with the buffer
50