if(m_buffer.Used() < m_sinkBlockSize)
return;
- int wroteFrames = m_sink->AddPackets((uint8_t*)m_buffer.Raw(m_sinkBlockSize), m_sinkFormat.m_frames);
+ void *data = m_buffer.Raw(m_sinkBlockSize);
+
+ if (CAEUtil::S16NeedsByteSwap(AE_FMT_S16NE, m_sinkFormat.m_dataFormat))
+ {
+ /*
+ * It would really be preferable to handle this at packing stage, so that
+ * it could byteswap the data efficiently without wasting CPU time on
+ * swapping the huge IEC 61937 zero padding between frames (or not
+ * byteswap at all, if there are two byteswaps).
+ *
+ * Unfortunately packing is done on a higher level and we can't easily
+ * tell it the needed format from here, so do it here for now (better than
+ * nothing)...
+ */
+ AllocateConvIfNeeded(m_sinkBlockSize);
+ Endian_Swap16_buf((uint16_t *)m_converted, (uint16_t *)data, m_sinkBlockSize / 2);
+ data = m_converted;
+ }
+
+ int wroteFrames = m_sink->AddPackets((uint8_t *)data, m_sinkFormat.m_frames);
+
+ /* Return value of INT_MAX signals error in sink - restart */
+ if (wroteFrames == INT_MAX)
+ {
+ CLog::Log(LOGERROR, "CSoftAE::RunRawOutputStage - sink error - reinit flagged");
+ wroteFrames = 0;
+ m_reOpen = true;
+ }
+
m_buffer.Shift(NULL, wroteFrames * m_sinkFormat.m_frameSize);
}