final Synth synthPhasor;
final float realRate;
final float interpolation;
final double nrtServerRate;
final float rate = 1.0f;
Server nrtServer = null;
NRTFile f = null;
int argIdx = 1;
int audioBusOffset, bufferOffset; //, controlBusOffset;
OSCBundle bndl;
double time = 0.0;
boolean even;
int nrtClock;
long pos = nrtPlayOffset;
if( ct == null ) {
// rom.replyFailed( rom, new IOException( "No routing context" ));
try {
rom.replyFailed( 1 );
}
catch( IOException e11 ) {
OSCRoot.failed( rom, e11 );
}
}
try {
f = NRTFile.openAsWrite( new File( rom.msg.getArg( argIdx ).toString() ));
argIdx++;
audioBusOffset = ((Number) rom.msg.getArg( argIdx )).intValue();
argIdx++;
// controlBusOffset= ((Number) rom.msg.getArg( argIdx )).intValue();
argIdx++;
bufferOffset = ((Number) rom.msg.getArg( argIdx )).intValue();
argIdx++;
nrtServerRate = ((Number) rom.msg.getArg( argIdx )).doubleValue();
nrtServer = new Server( "nrt" );
f.write( SuperColliderClient.getInstance().loadDefsMsg() );
defs = createInputDefs( ct.chanMaps ); // ct.numInputChannels
if( defs != null ) {
for( int i = 0; i < defs.length; i++ ) {
f.write( defs[ i ].recvMsg() );
}
}
// sourceRate = doc.timeline.getRate();
// serverRate = server.getSampleRate();
srcFactor = sourceRate / nrtServerRate;
realRate = (float) (rate * srcFactor);
interpolation = realRate == 1.0f ? 1f : 3f;
nrtGrpRoot = Group.basicNew( nrtServer );
f.write( nrtGrpRoot.addToHeadMsg( nrtServer.getDefaultGroup() ));
nrtGrpInput = Group.basicNew( nrtServer );
f.write( nrtGrpInput.addToTailMsg( nrtGrpRoot ));
synthsBufRd = new Synth[ ct.numFiles ];
busInternal = new Bus( nrtServer, kAudioRate, audioBusOffset, ct.numInChans );
audioBusOffset += busInternal.getNumChannels();
busPh = new Bus( nrtServer, kAudioRate, audioBusOffset );
audioBusOffset += busPh.getNumChannels();
bufsDisk = new Buffer[ ct.numFiles ];
for( int i = 0; i < ct.numFiles; i++ ) {
bufsDisk[ i ] = new Buffer( nrtServer, DISKBUF_SIZE, ct.chanMaps[ i ].length, bufferOffset++ );
f.write( bufsDisk[ i ].allocMsg() );
}
for( int i = 0; i < ct.numFiles; i++ ) {
synthsBufRd[ i ] = Synth.basicNew( "eisk-input" + ct.chanMaps[ i ].length, nrtServer );
}
synthPhasor = Synth.basicNew( "eisk-phasor", nrtServer );
for( nrtClock = 0, even = true;; nrtClock++, even = !even ) {
if( even ) {
pos = nrtClock * DISKBUF_SIZE_HM - DISKBUF_PAD + nrtPlayOffset;
} else {
pos = nrtClock * DISKBUF_SIZE_HM + nrtPlayOffset;
}
if( pos >= span.stop ) break;
f.setTime( time );
//System.err.println( "clock = "+clock+"; pos = "+pos+"; time = "+time );
bndl = new OSCBundle( time );
// if( pos >= DISKBUF_PAD ) {
if( pos < 0 ) {
for( int i = 0; i < bufsDisk.length; i++ ) {
bndl.addPacket( bufsDisk[ i ].fillMsg( 0, DISKBUF_PAD * bufsDisk[ i ].getNumChannels(), 0.0f ));
}
pos += DISKBUF_PAD;
}
// bufSpans[ 0 ] = new Span( pos - DISKBUF_PAD, pos - DISKBUF_PAD + DISKBUF_SIZE_H );
bufSpans[ 0 ] = new Span( pos, pos + DISKBUF_SIZE_H );
at.addBufferReadMessages( bndl, bufSpans, bufsDisk, even ? 0 : DISKBUF_SIZE_H );
f.write( bndl );
if( nrtClock == 0 ) {
for( int i = 0, off = 0; i < ct.numFiles; i++ ) {
f.write( synthsBufRd[ i ].newMsg( nrtGrpInput, new String[] {
"i_aInBf", "i_aOtBs", "i_aPhBs", "i_intrp" }, new float[] {
bufsDisk[ i ].getBufNum(), busInternal.getIndex() + off, busPh.getIndex(), interpolation }
));
off += ct.chanMaps[ i ].length;
}
if( ct.numFiles > 0 ) {
f.write( synthPhasor.newMsg( nrtGrpInput, new String[] {
"i_aInBf", "rate", "i_aPhBs" }, new float[] {
bufsDisk[ 0 ].getBufNum(), realRate, busPh.getIndex() }));
}
} else {
time = (nrtClock * DISKBUF_SIZE_HM / sourceRate) + 0.1; // a bit beyond that spot to avoid rounding errors
}
}
time = span.getLength() / sourceRate;
//System.err.println( "time = "+time );
f.setTime( time );
f.write( nrtGrpRoot.freeMsg() );
for( int i = 0; i < bufsDisk.length; i++ ) {
f.write( bufsDisk[ i ].freeMsg() );
}
f.close();
// f.dispose();
f = null;
try {
rom.replyDone( 1, new Object[0] );
}
catch( IOException e11 ) {
OSCRoot.failed( rom, e11 );
}
}
catch( ClassCastException e1 ) {
OSCRoot.failedArgType( rom, argIdx );
}
catch( IndexOutOfBoundsException e1 ) {
OSCRoot.failedArgCount( rom );
}
catch( IOException e1 ) {
// rom.replyFailed( rom, e1 );
e1.printStackTrace();
try {
rom.replyFailed( 1 );
}
catch( IOException e11 ) {
OSCRoot.failed( rom, e11 );
}
}
finally {
if( nrtServer != null ) nrtServer.dispose();
if( f != null ) f.dispose();
}
}