real-time hight-quality audio streaming - ccrma · juan-pablo cáceres | ccrma | stanford...

27
Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected] REAL-TIME HIGHT-QUALITY AUDIO STREAMING Juan-Pablo Cáceres Network Sound and Data Center for Computer Research in Music and Acoustics (CCRMA) Stanford University

Upload: nguyenque

Post on 18-Aug-2019

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

REAL-TIME HIGHT-QUALITYAUDIO STREAMING

Juan-Pablo CáceresNetwork Sound and Data

Center for Computer Research in Music and Acoustics (CCRMA)Stanford University

Page 2: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Perform MusicOn-Line

in Real-Timewith the Highest Audio Quality Possible

Page 3: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Goals of High-Quality Audio over Networks

Maximize Audio Quality for available networks conditions

Minimize Latency

But more important, Minimize Jitter

Adjustable Number of Channels

Audio routing flexibility

Multiple peers

Page 4: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Keep Delay ConstantMaximize Audio Quality

Page 5: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Why Latency MattersSaint Lawrence String Quartet (Quintet)

Banff Centre, Alberta, CanadaQuartet

Stanford, Anechoic RoomViola

25 ms One-way Delay

Page 6: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Why Latency MattersSaint Lawrence String Quartet (Quintet) 25 ms One-way Delay

‣What Happens Naturally with Delay?

‣The whole Quintet

‣Now, they are conscious...

‣...and they try to be stable

Page 7: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Basic Principle: Uncompressed Audio

Some Historical/Technical Foundations

Year 2000McGill Xu & Cooperstock

Stanford Chafe, Wilson, Leistikow, Chisholm, Scavone

Page 8: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

UDP and TCP revisited

UDP

- Unreliable- Connections-less- Datagram Oriented

TCP

- Reliable- Connected (virtual circuit)- Byte-Stream Oriented

Delay Constant?

Page 9: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Why TCP is problematic382 5 End-to-End Protocols

Application process

Writebytes

TCP

Send buffer

Segment Segment Segment

Transmit segments

Application process

Readbytes

TCP

Receive buffer

… …Figure 5.3 How TCP manages a byte stream.

5.2.2 Segment Format

TCP is a byte-oriented protocol, which means that the sender writes bytes into a TCP

connection and the receiver reads bytes out of the TCP connection. Although “byte

stream” describes the service TCP offers to application processes, TCP does not, itself,

transmit individual bytes over the Internet. Instead, TCP on the source host buffers

enough bytes from the sending process to fill a reasonably sized packet and then sends

this packet to its peer on the destination host. TCP on the destination host then empties

the contents of the packet into a receive buffer, and the receiving process reads from

this buffer at its leisure. This situation is illustrated in Figure 5.3, which, for simplicity,

shows data flowing in only one direction. Remember that, in general, a single TCP

connection supports byte streams flowing in both directions.

The packets exchanged between TCP peers in Figure 5.3 are called segments,

since each one carries a segment of the byte stream. Each TCP segment contains the

header schematically depicted in Figure 5.4. The relevance of most of these fields will

become apparent throughout this section. For now, we simply introduce them.

The SrcPort and DstPort fields identify the source and destination ports, respec-

tively, just as in UDP. These two fields, plus the source and destination IP addresses,

combine to uniquely identify each TCP connection. That is, TCP’s demux key is given

by the 4-tuple

! SrcPort, SrcIPAddr, DstPort, DstIPAddr "

Note that because TCP connections come and go, it is possible for a connection be-

tween a particular pair of ports to be established, used to send and receive data, and

closed, and then at a later time for the same pair of ports to be involved in a second

Sec. 13.5 The Idea Behind Sliding Windows 215

Conceptually, a sliding window protocol always remembers which packets have been acknowledged and keeps a separate timer for each unacknowledged packet. If a packet is lost, the timer expires and the sender retransmits that packet. When the sender slides its window, it moves past all acknowledged packets. At the receiving end, the protocol software keeps an analogous window, accepting and acknowledging packets as they arrive. Thus, the window partitions the sequence of packets into three sets: those packets to the left of the window have been successfully transmitted, received, and ack- nowledged; those packets to the right have not yet been transmitted; and those packets that lie in the window are being transmitted. The lowest numbered packet in the win- dow is the first packet in the sequence that has not been acknowledged.

Events At Sender Site Network Messages

Send Packet 1

Send Packet 2

Send Packet 3

Receive ACK 1

Receive ACK 2

Receive ACK 3

Events At Receiver Site

Receive Packet 1 Send ACK 1 Receive Packet 2 Send ACK 2 Receive Packet 3 Send ACK 3

Figure 13.4 An example of three packets transmitted using a sliding window protocol. The key concept is that the sender can transmit all packets in the window without waiting for an acknowledgement.

13.6 The Transmission Control Protocol

Now that we understand the principle of sliding windows, we can examine the reli- able stream service provided by the TCPIIP Internet protocol suite. The service is de- fined by the Transmission Control Protocol, or TCP. The reliable stream service is so important that the entire protocol suite is referred to as TCPAP. It is important to understand that:

TCP is a communication protocol, not a piece of sojhare.

The difference between a protocol and the software that implements it is analogous to the difference between the definition of a programming language and a compiler. As in the programming language world, the distinction between definition and implementa-

Page 10: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

TCP makes the underlying delayelastic and ever-increasing

Use UDP

Page 11: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

A JackTrip Session

Jmess

Page 12: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

What is Jack?

Demo: Jack

Page 13: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Real-Time Audio: Under the Hood

UDP3 UDP2 UDP1... ...

UDP1 UDP2 UDP3... ...

AudioOut

In

AudioIn

Out

Page 14: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Real-Time Audio: Under the HoodUDP3 UDP2 UDP1... ...

UDP1 UDP2 UDP3... ...

AudioOut

In

AudioIn

Out

BlockingUDP Sender Thread

Audio Process CallbackJackAudio Threads To Peer

Non-blocking

UDP Receiver Thread

FromPeer

Non-blocking

Non-blocking

Audio-Outputs(N-Channels)

Audio-Inputs(N-Channels)

Network

NetworkRing Buffer

Process plug-ins

Ring Buffer

Page 15: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Real-Time Audio: Under the HoodUDP3 UDP2 UDP1... ...

UDP1 UDP2 UDP3... ...

AudioOut

In

AudioIn

Out

BlockingUDP Sender Thread

Audio Process CallbackJackAudio Threads To Peer

Non-blocking

UDP Receiver Thread

FromPeer

Non-blocking

Non-blocking

Audio-Outputs(N-Channels)

Audio-Inputs(N-Channels)

Network

NetworkRing Buffer

Process plug-ins

Ring Buffer

writeposition

readposition

writeposition

readposition

Overow Condition

writeposition

readposition

No empty slotsto write to

writeposition

readposition

Reset pointersand clear older packets

Under-run Condition

Ring Buffer

Read packetsof zeros

Loop throughthe last readpacket

Silent Mode

WavetableMode

No new slotsto read from

Ring Buffer initial"symmetic"pointer positions

full packets

empty packets

Page 16: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Real-Time Audio: Under the HoodBlocking

UDP Sender ThreadAudio Process Callback

JackAudio Threads To Peer

Non-blocking

UDP Receiver Thread

FromPeer

Non-blocking

Non-blocking

Audio-Outputs(N-Channels)

Audio-Inputs(N-Channels)

Network

NetworkRing Buffer

Process plug-ins

Ring Buffer

p[1]

p[2]

p[3]

p[4]p[5]

p[3] p[2] p[1]

UD

P1

To Peer

To Peer

To Peer

From Peer

UDP[3]From Peer

Lost Packet

ringbuffer

time

time Receiving end

Sender end

p[4] p[3] p[2]

p[5] p[4] p[3]

p[3] p[2] p[1]

p[5] p[4] p[3]

UD

P2

UD

P3

UD

P1

UD

P3

Redundancy

Page 17: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Queue Length (latency/jitter tradeoff)

UDP3 UDP2 UDP1

UDP3 UDP2 UDP1

UDP3 UDP2 UDP1

Redundancy (bandwidth)

8 / 16 / 24 / 32 Audio Bit Resolution (bandwidth)

Parameters that matter

writeposition

readposition

writeposition

readposition

Overow Condition

writeposition

readposition

No empty slotsto write to

writeposition

readposition

Reset pointersand clear older packets

Under-run Condition

Ring Buffer

Read packetsof zeros

Loop throughthe last readpacket

Silent Mode

WavetableMode

No new slotsto read from

Ring Buffer initial"symmetic"pointer positions

full packets

empty packets

Page 18: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Parameters that matter

Packet size (latency)Sampling Rate (bandwidth)

Page 19: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Packet Size / Latency

UDP3 UDP2 UDP1

UDP1

latency

latency

BlockingUDP Sender Thread

Audio Process CallbackJackAudio Threads To Peer

Non-blocking

UDP Receiver Thread

FromPeer

Non-blocking

Non-blocking

Audio-Outputs(N-Channels)

Audio-Inputs(N-Channels)

Network

NetworkRing Buffer

Process plug-ins

Ring Buffer

The smaller the packet size,the lower the latency (sampling rate constant)

Page 20: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Sampling Rate / Latency

64 samples

64 samples

For the samepacket size

48kHz: 64/48000 = 1.3 ms

96kHz: 64/96000 = 0.7 ms

The higher the Sampling Rate,the lower the delay (packet size constant)

Page 21: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

A Simple (default) JackTrip Session

jacktrip -c [ccrma-IP-number]

jacktrip -s

at CCRMA (Server)

at UK (Client)

servermode

clientmode

Page 22: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

More Control over a JackTrip Session

jacktrip -c [ccrma-IP-number] -n 8 -q 4 -r 2

jacktrip -s -n 8 -q 4 -r 2

at CCRMA (Server)

at UK (Client)

servermode

clientmode

num chans

Queue

redundancy

Page 23: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

A JackTrip Session (demo)

Page 24: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

JackTripServer

client

client

client

QoS Network “Audible Distances”Plucking the Net

Longer Distance = Lower Pitch

Short Distance=

Higher Pitch

ShortJittery/Lossy

Wireless

Page 25: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

Net vs. Net Collective

Chris Chafe | Chopper

Page 26: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

JamLink

http://www.musicianlink.com/

Page 27: REAL-TIME HIGHT-QUALITY AUDIO STREAMING - CCRMA · Juan-Pablo Cáceres | CCRMA | Stanford University | jcaceres@ccrma.stanford.edu Goals of High-Quality Audio over Networks Maximize

Juan-Pablo Cáceres | CCRMA | Stanford University | [email protected]

More Information

http://ccrma.stanford.edu/groups/soundwire/

JackTrip at Google Code:http://code.google.com/p/jacktrip/

JackTrip Mailing List:http://groups.google.com/group/jacktrip-users