Issue #47 - work in progress

This commit is contained in:
denny
2016-01-18 04:53:49 -05:00
parent 810bb7384e
commit c12f535f3c
2 changed files with 69 additions and 12 deletions

View File

@@ -186,11 +186,40 @@ public class MonoAudioOutput extends AudioOutput
{
shortBuffer.put( (short)( sample * Short.MAX_VALUE ) );
}
mOutput.write( buffer.array(), 0,
buffer.array().length );
checkStart();
if( mOutput.available() >= buffer.array().length )
{
mOutput.write( buffer.array(), 0,
buffer.array().length );
checkStart();
}
else
{
int wrote = 0;
int toWrite = buffer.array().length;
while( toWrite > 0 )
{
int available = mOutput.available();
if( available < toWrite )
{
wrote += mOutput.write( buffer.array(), wrote,
available );
}
else
{
wrote += mOutput.write( buffer.array(), wrote,
toWrite );
}
checkStart();
toWrite = buffer.array().length - wrote;
}
}
broadcast( packet.getAudioMetadata() );

View File

@@ -141,9 +141,8 @@ public class StereoAudioOutput extends AudioOutput
private ByteBuffer convert( float[] samples )
{
/* Little-endian byte buffer */
ByteBuffer buffer =
ByteBuffer.allocate( samples.length * 4 )
.order( ByteOrder.LITTLE_ENDIAN );
ByteBuffer buffer = ByteBuffer.allocate( samples.length * 4 )
.order( ByteOrder.LITTLE_ENDIAN );
ShortBuffer shortBuffer = buffer.asShortBuffer();
@@ -203,10 +202,39 @@ public class StereoAudioOutput extends AudioOutput
ByteBuffer buffer = convert(
packet.getAudioBuffer().getSamples() );
mOutput.write( buffer.array(), 0,
buffer.array().length );
checkStart();
if( mOutput.available() >= buffer.array().length )
{
mOutput.write( buffer.array(), 0,
buffer.array().length );
checkStart();
}
else
{
int wrote = 0;
int toWrite = buffer.array().length;
while( toWrite > 0 )
{
int available = mOutput.available();
if( available < toWrite )
{
wrote += mOutput.write( buffer.array(), wrote,
available );
}
else
{
wrote += mOutput.write( buffer.array(), wrote,
toWrite );
}
checkStart();
toWrite = buffer.array().length - wrote;
}
}
broadcast( packet.getAudioMetadata() );