• No results found

S/PDIF Software Component

N/A
N/A
Protected

Academic year: 2021

Share "S/PDIF Software Component"

Copied!
11
0
0

Loading.... (view fulltext now)

Full text

(1)

S/PDIF Software Component

Document Number: X9128A

Publication Date: 2012/3/21 XMOS © 2012, All Rights Reserved.

(2)

C O N T E N T S

· SPDIF software

· S/PDIF Receive

· S/PDIF Transmit

(3)

1 SPDIF software

I N T H I S C H A P T E R

· module_spdif_tx

· module_spdif_rx

S/PDIF, or Sony/Philips Digital Interface is a protocol to transmit audio data over either coaxial or optical cables. The data transmission rate is determined by the transmitter, and the receiver has to recover the sample rate.

Important characteristics of S/PDIF software are the following:

· The number of audio channels: 2 (Stereo)

· The sample rate(s) supported. Typical values are 44.1, 48, 96, and 192 Khz.

Some systems require only a single frequency to be supported, others need to support all frequencies and need to auto-detect the frequency.

· Transmit and Receive support. Some systems require only S/PDIF output, or only S/PDIF input. Others require both.

1.1 module_spdif_tx

This module can transmit S/PDIF signals at the following rates (assuming a 50 MIPS thread):

Functionality provided Resources required Status Channels Sample Rate 1-bit port Memory

2 up to 192 KHz 1-2 3.5 KB Implemented and tested

It requires a single thread to run the transmit code. The number of 1-bit ports depends on whether the master clock is already available on a one-bit port. If available, then only a single 1-bit port is required to output S/PDIF. If not, then two ports are required, one for the signal output, and one for the master-clock input.

The jitter on the output-pin is within tolerances allowed by the spec provided a 500 MHz part is used. It is recommended to use an external flip-flop to resynchronise the data signal to the master-clock, which will eliminate the remaining jitter on the S/PDIF edges.

The precise transmission frequencies supported depend on the availability of an external clock (eg, a PLL or a crystal oscillator) that runs at a frequency of:

c h a n n e l s * s a m p l e R a t e * 64

(4)

or a power-of-2 multiple. For example, for 2 channels at 192 Khz the external clock has to run at a frequency of 24.576 MHz. This same frequency also supports 2 channels at 48 KHz (which requires a minimum frequency of 6.144 MHz). If both 44,1 and 48 Khz frequencies are to be supported, both a 24.576 MHz and a 22.579 MHz master clock is required. This is normally not an issue since the same clocks can be used to drive the audio codecs.

Typical applications for this module include iPod docks, digital microphones, digital mixing desks, USB audio, and AVB.

1.2 module_spdif_rx

This module can receive S/PDIF signals at three different rates. It automatically adjusts to the incoming rate, but for high rates a fast thread is required. The thread will fail silently if it does not have enough MIPS to parse the input stream.

The S/PDIF receiver is generated from a state machine description. The generated code requires a one bit buffered input port (transfer width of 4), and a clock block to work.

Functionality provided Resources required Status

Channels Sample Rate 1-bit port Memory Thread rate

2 up to 192 KHz 1 3 KB 80 MIPS Implemented and tested

The receiver does not require any external clock, but can only recover 44.1, 48, 88.2, 96, and 192 KHz sample rates.

Typical applications for this module include digital speakers, digital mixing desks, USB audio, and AVB.

(5)

2 S/PDIF Receive

I N T H I S C H A P T E R

· Symbolic constants

· API

· Example

The S/PDIF receive module comprises a single thread that parses data as it arrives on a one-bit port and outputs words of data onto a streaming channel end. Each word of data carries 24 bits of data and 4 bits of channel information.

This module requires the reference clock to be exactly 100 MHz.

2.1 Symbolic constants

FRAME_X This constant defines the four least-significant bits of the first sample of a frame (typically a sample from the left channel).

FRAME_Y This constant defines the four least-significant bits of the second or later sample of a frame (typically a sample from the right channel, unless there are more than two channels).

FRAME_Z This constant defines the four least-significant bits of the first sample of the first frame of a block (typically a sample from the left channel).

2.2 API

void SpdifReceive(in buffered port:4 p, streaming chanend c, int initial_divider, clock clk)

S/PDIF receive function.

This function needs 1 thread and no memory other than ~2800 bytes of program code. It can do 11025, 12000, 22050, 24000, 44100, 48000, 88200, 96000, and 192000 Hz. When the decoder encounters a long series of zeros it will lower the divider; when it encounters a short series of 0-1 transitions it will increase the divider.

Output: the received 24-bit sample values are output as a word on the streaming channel end. Each value is shifted up by 4-bits with the bottom four bits being one of FRAME_X, FRAME_Y, or FRAME_Z. The bottom four bits should be removed whereupon the sample value should be sign extended.

(6)

The function does not return unless compiled with TEST defined in which case it returns any time that it loses synchronisation.

This function has the following parameters:

p S/PDIF input port. This port must be 4-bit buffered, declared as in buffered port:4

c channel to output samples to initial_divider

initial divide for initial estimate of sample rate For a 100Mhz reference clock, use an initial divider of 1 for 192000, 2 for 96000/88200, and 4 for 48000/44100.

clk clock block sourced from the 100 MHz reference clock.

2.3 Example

An example program is shown below. An input port and a clock block must be declared. Neither should be configured:

# i n c l u d e < xs1 . h >

# i n c l u d e " S p d i f R e c e i v e . h "

b u f f e r e d in p o r t :4 o n e B i t P o r t = X S 1 _ P O R T _ 1 F ; c l o c k c l o c k b l o c k = X S 1 _ C L K B L K _ 1 ;

All data samples are being received on a streaming channel, after being parsed by the receive process. After reading a sample value from the channel, it must be converted to a signed sample value whilst removing the tag identifying the channel information. In this example, we perform this operation by masking off the bottom four bits and shifting the sample-data into the most significant 24-bits, ready to be used on, for example, I2S:

v o i d h a n d l e S a m p l e s ( s t r e a m i n g c h a n e n d c ) { int v , left , r i g h t ;

w h i l e (1) { c : > v ;

if (( v & 0 xF ) == F R A M E _ Y ) { r i g h t = ( v & ~0 xf ) < < 4;

// o p e r a t e on l e f t and r i g h t } e l s e {

l e f t = ( v & ~0 xf ) < < 4;

} } }

The main program in this example simply starts the S/PDIF receive thread, and the data handling thread in parallel:

int m a i n ( v o i d ) {

(7)

S/PDIF Software Component 7/11

s t r e a m i n g c h a n c ; par {

S p d i f R e c e i v e ( o n e B i t P o r t , c , 1 , c l o c k b l o c k ) ; h a n d l e S a m p l e s ( c ) ;

}

r e t u r n 0;

}

(8)

I N T H I S C H A P T E R

· API

· Example

This module is a single thread that receives samples over a channel and that outputs data on the port.

The S/PDIF transmit module require a one-bit buffered output port (with transfer width of 32), a clock block, and a master clock coming in on an unbuffered one-bit port.

3.1 API

Call SpdifTransmitPortConfig to set up the clock then SpdifTransmit to output data.

void SpdifTransmitPortConfig(out buffered port:32 p, clock cl,

in port p_mclk)

Configure out port to be clocked by clock block, driven from master clock input.

Must be called beforeSpdifTransmit() This function has the following parameters:

p S/PDIF tx port

cl Clock block to be used p_mclk Master-clock input port void SpdifTransmit(buffered out port:32 p, chanend c)

Function expects a buffered single bit port clock from the master clock.

All channel communication is done via builtins (e.g. outuint, outct etc.) On startup expects two words over the channel:

1. Desired sample frequency (in Hz) 2. Master clock frequency (in Hz) Then sample pairs:

(9)

S/PDIF Software Component 9/11

1. Left sample 2. Right sample

The data format is 24-bit signed left aligned in a 32-bit word.

If a XS1_CT_END token is received, the thread stops and waits for new sample/- master freq pair

This function has the following parameters:

p S/PDIF tx port

c Channel-end for sample freq and samples

3.2 Example

This example generates a triangle sound wave on the SPDIF interface from a USB Audio 2.0 multichannel interface board. On this board the master clock input is from a PLL. The program is shown below (excluding code to set up the PLL on the board).

An output port, a master-clock input port and a clock block must be declared:

# i n c l u d e < xs1 . h >

# i n c l u d e < p l a t f o r m . h >

# i n c l u d e " S p d i f T r a n s m i t . h "

# d e f i n e S A M P L E _ F R E Q U E N C Y _ H Z 9 6 0 0 0

# d e f i n e M A S T E R _ C L O C K _ F R E Q U E N C Y _ H Z 1 2 2 8 8 0 0 0

on s t d c o r e [1] : b u f f e r e d out p o r t :32 o n e B i t P o r t = X S 1 _ P O R T _ 1 K ; on s t d c o r e [1] : in p o r t m a s t e r C l o c k P o r t = X S 1 _ P O R T _ 1 L ;

on s t d c o r e [1] : c l o c k c l o c k b l o c k = X S 1 _ C L K B L K _ 1 ;

In this example transmitSpdif sets up the clock and starts the transmit function to receive on a chanend.

v o i d t r a n s m i t S p d i f ( c h a n e n d c ) {

S p d i f T r a n s m i t P o r t C o n f i g ( o n e B i t P o r t , c l o c k b l o c k , m a s t e r C l o c k P o r t ) ; S p d i f T r a n s m i t ( o n e B i t P o r t , c ) ;

}

The generate function sends configuration settings over a channel then a triangle wave.

# d e f i n e W A V E _ L E N 512 v o i d g e n e r a t e ( c h a n e n d c ) {

int i = 0;

o u t u i n t ( c , S A M P L E _ F R E Q U E N C Y _ H Z ) ; o u t u i n t ( c , M A S T E R _ C L O C K _ F R E Q U E N C Y _ H Z ) ; w h i l e (1) {

// G e n e r a t e a t r i a n g l e w a v e int s a m p l e = i ;

(10)

if ( i > ( W A V E _ L E N / 4) ) {

// A f t e r the f i r s t q u a r t e r of the c y c l e s a m p l e = ( W A V E _ L E N / 2) - i ;

}

if ( i > (3 * W A V E _ L E N / 4) ) {

// In the l a s t q u a r t e r of the c y c l e s a m p l e = i - W A V E _ L E N ;

}

s a m p l e < <= 23; // S h i f t to h i g h e s t but 1 b i t s o u t u i n t ( c , s a m p l e ) ; // L e f t c h a n n e l

o u t u i n t ( c , s a m p l e ) ; // R i g h t c h a n n e l

i ++;

i %= W A V E _ L E N ; }

// o u t c t ( c , X S 1 _ C T _ E N D ) ; // to s t o p S p d i f T r a n s m i t t h r e a d }

· S/PDIF transmit

· the data generator

· clock generator for the PLL

An XC channel connects the generator and the transmit thread.

v o i d e x a m p l e ( v o i d ) { c h a n c ;

s e t u p P l l () ; par {

t r a n s m i t S p d i f ( c ) ; g e n e r a t e ( c ) ; c l o c k G e n () ; }

}

int m a i n ( v o i d ) { par {

on s t d c o r e [ 1 ] : e x a m p l e () ; }

r e t u r n 0;

}

(11)

S/PDIF Software Component 11/11

Table of Contents

1 SPDIF software 3

1.1 module_spdif_tx. . . 3 1.2 module_spdif_rx. . . 4

2 S/PDIF Receive 5

2.1 Symbolic constants . . . 5 2.2 API. . . 5 2.3 Example . . . 6

3 S/PDIF Transmit 8

3.1 API. . . 8 3.2 Example . . . 9

Copyright © 2012, All Rights Reserved.

Xmos Ltd. is the owner or licensee of this design, code, or Information (collectively, the “Information”) and is providing it to you “AS IS” with no warranty of any kind, express or implied and shall have no liability in relation to its use. Xmos Ltd. makes no representation that the Information, or any particular implementation thereof, is or will be free from any claims of infringement and again, shall have no liability in relation to any such claims.

XMOS and the XMOS logo are registered trademarks of Xmos Ltd. in the United Kingdom and other countries, and may not be used without written permission. All other trademarks are property of their respective owners.

Where those designations appear in this book, and XMOS was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.

References

Related documents

If you discover a defect, Hagerman Technology LLC will, at its option, repair or replace the product at no charge to you provided you return it during the warranty

E-commerce has enhanced the corporate image of your organization (B=2.038) carried the heaviest weight in explaining Benefit of effect of E-commerce on the performance of

This method allows us to elicit risk preferences involving pain intensity and duration using choice scenarios where subjects face real consequences of their decisions.. To

The ADSP-2148x processors are available with unique audio- centric peripherals, such as the digital applications interface, serial ports, precision clock generators, S/PDIF

static port) Windows registry • On a 32-bit version of Windows: HKEY_LOCAL_MACHIN E\SOFTWARE\Research In Motion\BlackBerry Enterprise Server \Database\Port • On a 64-bit version of

Through a specific audio cable, you can connect the S/PDIF connector to other end of the S/PDIF audio module, which bears S/PDIF digital output.. Normally there are two S/PDIF

CSRC Clock Source Selection (synch mode only) 1 = Master mode, clock generated by internal BRG 0 = Slave mode, clock derived from external TX9 9-bit / 8-bit Mode Transmission

The Audio Return Channel (ARC) Block allows digital S/PDIF data received from the sink device to be transmitted in the direction opposite to the TMDS input port signal.. The