Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ Switch audio to synchronized buffers

  • Loading branch information...
commit fa623a2f0b0708b6cdd7d4edcd3deac6926e7427 1 parent bf93db9
ru authored
View
17 sqmod/sqmod_asio/asio_drv.cpp
@@ -669,8 +669,17 @@ int CAsioDrv::OpenChannels( sqbind::CSqMulti *m, int nFlags, int nFmt )
sqbind::stdString sShare = it->first;
m_share[ nS ].share.setCbId( getCbId() );
m_share[ nS ].share.setPrefix( getPrefix() );
- if ( !m_share[ nS ].share.Create( sShare, oexT( "" ), nBufSize, m_share[ nS ].channels,
- oex::obj::StaticSize( nType ), *((double*)&sr), nFmt ? nFmt : nType ) )
+
+ sqbind::CSqMulti mHeaders;
+ mHeaders[ oexT( "channels" ) ].set( sqbind::ToStr( m_share[ nS ].channels ) );
+ mHeaders[ oexT( "type" ) ].set( sqbind::ToStr( nType ) );
+ mHeaders[ oexT( "type_size" ) ].set( sqbind::ToStr( oex::obj::StaticSize( nType ) ) );
+ mHeaders[ oexT( "sample_rate" ) ].set( sqbind::ToStr( *((double*)&sr) ) );
+ mHeaders[ oexT( "format" ) ].set( sqbind::ToStr( nFmt ? nFmt : nType ) );
+
+// if ( !m_share[ nS ].share.Create( sShare, oexT( "" ), nBufSize, m_share[ nS ].channels,
+// oex::obj::StaticSize( nType ), *((double*)&sr), nFmt ? nFmt : nType ) )
+ if ( !m_share[ nS ].share.Create( sShare, oexT( "" ), nBufSize, 1024, mHeaders.getJSON() ) )
{ setLastErrorStr( sqbind::oex2std( oexMks( oexT( "Failed to create memory share : nBufSize = " ), nBufSize,
oexT( " : nType = " ), nType,
oexT( " : data size = " ), oex::obj::StaticSize( nType ),
@@ -830,7 +839,7 @@ ASIOTime* CAsioDrv::onBufferSwitchTimeInfo( ASIOTime* params, long doubleBufferI
if ( 0 <= nCh && eMaxChannels > nCh )
{ long nIdx = m_chmap[ nCh ];
if ( 0 <= nIdx && nIdx < m_nOpenChannels )
- m_share[ nSh ].share.WritePtr( pAbi[ nIdx ].buffers[ doubleBufferIndex ], lBytes );
+ m_share[ nSh ].share.WritePtr( pAbi[ nIdx ].buffers[ doubleBufferIndex ], lBytes, "", 0, 0 );
} // end if
} // end if
@@ -890,7 +899,7 @@ ASIOTime* CAsioDrv::onBufferSwitchTimeInfo( ASIOTime* params, long doubleBufferI
#endif
// Write data to share
- m_share[ nSh ].share.Write( &m_buf );
+ m_share[ nSh ].share.Write( &m_buf, "", 0, 0 );
} // end else
View
2  sqmod/sqmod_asio/asio_drv.h
@@ -27,7 +27,7 @@ class CAsioDrv
struct SShareInfo
{
/// Memory share
- sqbind::CSqBinaryShare share;
+ sqbind::CSqFifoShare share;
/// Number of active channels
long channels;
View
8 sqmod/sqmod_ffmpeg/ff_audio_encoder.cpp
@@ -20,6 +20,7 @@ SQBIND_REGISTER_CLASS_BEGIN( CFfAudioEncoder, CFfAudioEncoder )
SQBIND_MEMBER_FUNCTION( CFfAudioEncoder, getFrameSize )
SQBIND_MEMBER_FUNCTION( CFfAudioEncoder, BufferData )
SQBIND_MEMBER_FUNCTION( CFfAudioEncoder, UnbufferData )
+ SQBIND_MEMBER_FUNCTION( CFfAudioEncoder, getBufferSize )
SQBIND_MEMBER_FUNCTION( CFfAudioEncoder, getCodecId )
SQBIND_MEMBER_FUNCTION( CFfAudioEncoder, getFmtCnv )
SQBIND_MEMBER_FUNCTION( CFfAudioEncoder, setFmtCnv )
@@ -289,7 +290,7 @@ int CFfAudioEncoder::BufferData( sqbind::CSqBinary *in )
int CFfAudioEncoder::UnbufferData( int uUsed )
{
- if ( 0 > uUsed )
+ if ( 0 > uUsed || m_buf.getUsed() <= uUsed )
m_buf.setUsed( 0 );
else if ( 0 < uUsed )
m_buf.LShift( uUsed );
@@ -324,11 +325,11 @@ int CFfAudioEncoder::Encode( sqbind::CSqBinary *in, sqbind::CSqBinary *out, sqbi
// Output buffer pointer
uint8_t *pOut = (uint8_t*)out->_Ptr();
- // While we have input data
- //while ( nIn >= bs )
if ( nIn < bs )
return 0;
+ // While we have input data
+// while ( nIn >= bs )
{
// Ensure a reasonable output buffer
while ( ( nOut - nOutPtr ) < ( bs + FF_MIN_BUFFER_SIZE ) )
@@ -408,6 +409,7 @@ int CFfAudioEncoder::Encode( sqbind::CSqBinary *in, sqbind::CSqBinary *out, sqbi
// Unbuffer used data
nIn = UnbufferData( bs );
+// if ( !nOutPtr )
if ( !nBytes )
return 0;
View
3  sqmod/sqmod_ffmpeg/ff_audio_encoder.h
@@ -133,6 +133,9 @@ class CFfAudioEncoder
/// Unbuffers the specified number of bytes
int UnbufferData( int uUsed );
+ /// Returns the number of bytes buffered
+ int getBufferSize() { return m_buf.getUsed(); }
+
/// Get input data format
int getFmtCnv() { return m_nCnv; }
Please sign in to comment.
Something went wrong with that request. Please try again.