- const u8 pi_sync[4] = { 0x72, 0xF8, 0x1F, 0x4E };
-
- /* add the spdif headers */
- memcpy( pi_out, pi_sync, 4 );
- if( i_length )
- pi_out[4] = 0x01;
- else
- pi_out[4] = 0;
- pi_out[5] = 0x00;
- pi_out[6] = ( i_length *8 ) & 0xFF;
- pi_out[7] = ( ( i_length *8 ) >> 8 ) & 0xFF;
-
- swab( pi_data, pi_out + 8, i_length );
- /* adds zero to complete the spdif frame
+ const u8 p_sync[4] = { 0x72, 0xF8, 0x1F, 0x4E };
+ int i_length = p_spdif->ac3_info.i_frame_size;
+#ifndef HAVE_SWAB
+ /* Skip the first byte if i_length is odd */
+ u16 * p_in = (u16 *)( p_spdif->p_ac3 + ( i_length & 0x1 ) );
+ u16 * p_out = (u16 *)p_spdif->p_iec;
+#endif
+
+ /* Add the spdif headers */
+ memcpy( p_spdif->p_iec, p_sync, 4 );
+ p_spdif->p_iec[4] = i_length ? 0x01 : 0x00;
+ p_spdif->p_iec[5] = 0x00;
+ p_spdif->p_iec[6] = ( i_length * 8 ) & 0xFF;
+ p_spdif->p_iec[7] = ( ( i_length * 8 ) >> 8 ) & 0xFF;
+
+#ifdef HAVE_SWAB
+ swab( p_spdif->p_ac3, p_spdif->p_iec + 8, i_length );
+#else
+ /* i_length should be even */
+ i_length &= ~0x1;
+
+ while( i_length )
+ {
+ *p_out = ( (*p_in & 0x00ff) << 16 ) | ( (*p_in & 0xff00) >> 16 );
+ p_in++;
+ p_out++;
+ i_length -= 2;
+ }
+#endif
+
+ /* Add zeroes to complete the spdif frame,