Package de.sciss.io

Examples of de.sciss.io.InterleavedStreamFile


  throws IOException
  {
    final int        len    = (int) readSpan.getLength();
    if( len == 0 ) return 0;

    InterleavedStreamFile  f;
    long          fOffset;
    int[]          channelMap;
    float[][]        mappedData;
 
    synchronized( fs ) {  // protects mappedDatas
      for( int i = 0, j = 0; i < fs.length; i++ ) {
        f      = fs[ i ];
        channelMap  = channelMaps[ i ];
        mappedData  = mappedDatas[ i ];
        fOffset    = fileSpans[ i ].start + readSpan.start - span.start;

        if( (fOffset < fileSpans[ i ].start) || ((fOffset + len) > fileSpans[ i ].stop) ) {
          throw new IllegalArgumentException( fOffset + " ... " + (fOffset + len) + " not within " + fileSpans[ i ].toString() );
        }

        synchronized( f ) {
          if( f.getFramePosition() != fOffset ) {
            f.seekFrame( fOffset );
          }
          for( int k = 0; k < channelMap.length; k++, j++ ) {
            mappedData[ channelMap[ k ]] = data[ j ];
          }
          f.readFrames( mappedData, offset, len );
        }
      }
      clearMappedData()// avoid memory footprint
    }
    return len;
View Full Code Here


  throws IOException
  {
    final int        len      = (int) writeSpan.getLength();
    if( len == 0 ) return 0;

    InterleavedStreamFile  f;
    long          fOffset;
    int[]          channelMap;
    float[][]        mappedData;
   
    synchronized( fs ) {  // protects mappedDatas
      for( int i = 0, j = 0; i < fs.length; i++ ) {
        f      = fs[ i ];
        channelMap  = channelMaps[ i ];
        mappedData  = mappedDatas[ i ];
        fOffset    = fileSpans[ i ].start + writeSpan.start - span.start;

        if( (fOffset < fileSpans[ i ].start) || ((fOffset + len) > fileSpans[ i ].stop) ) {
          throw new IllegalArgumentException( fOffset + " ... " + (fOffset + len) + " not within " + fileSpans[ i ].toString() );
        }

        synchronized( f ) {
          if( f.getFramePosition() != fOffset ) {
            f.seekFrame( fOffset );
          }
          for( int k = 0; k < channelMap.length; k++, j++ ) {
            mappedData[ channelMap[ k ]] = data[ j ];
          }
          f.writeFrames( mappedData, offset, len );
        }
      }
      clearMappedData()// avoid memory footprint
    }
    return len;
View Full Code Here

  throws IOException
  {
    final long  len      = readSpan.getLength();
    if( len == 0 ) return 0;
 
    InterleavedStreamFile  f;
    long          fOffset;
    int[]          channelMap;
    float[][]        mappedData;
    int            chunkLen;
    float[][]        data      = new float[ numChannels ][ (int) Math.min( BUFSIZE, len )];
    long          framesCopied  = 0;
   
    do {
      synchronized( fs ) {  // protects mappedDatas
        for( int i = 0, j = 0; i < fs.length; i++ ) {
          f      = fs[ i ];
          channelMap  = channelMaps[ i ];
          mappedData  = mappedDatas[ i ];
          fOffset    = fileSpans[ i ].start + readSpan.start - span.start;
 
          if( (fOffset < fileSpans[ i ].start) || ((fOffset + len) > fileSpans[ i ].stop) ) {
            throw new IllegalArgumentException( fOffset + " ... " + (fOffset + len) + " not within " + fileSpans[ i ].toString() );
          }
         
          chunkLen  = (int) Math.min( BUFSIZE, len - framesCopied );
          synchronized( f ) {
            if( f.getFramePosition() != fOffset ) {
              f.seekFrame( fOffset );
            }
            for( int k = 0; k < channelMap.length; k++, j++ ) {
              mappedData[ channelMap[ k ]] = data[ j ];
            }
            f.readFrames( mappedData, 0, chunkLen );
          }
          target.writeFrames( data, 0, chunkLen );
          framesCopied += chunkLen;
        }
      }
View Full Code Here

  }

  public void flush()
  throws IOException
  {
    InterleavedStreamFile  f;

    for( int i = 0; i < fs.length; i++ ) {
      f = fs[ i ];
      synchronized( f ) {
        f.flush();
      }
    }
  }
View Full Code Here

  throws IOException
  {
    final int        len    = (int) readSpan.getLength();
    if( len == 0 ) return 0;

    InterleavedStreamFile  f;
    long          fOffset;
    int[]          channelMap;
    float[][]        mappedData;
 
    synchronized( fs ) {  // protects mappedDatas
      for( int i = 0, j = 0; i < fs.length; i++ ) {
        f      = fs[ i ];
        channelMap  = channelMaps[ i ];
        mappedData  = mappedDatas[ i ];
        fOffset    = fileSpans[ i ].start + readSpan.start - span.start;

        if( (fOffset < fileSpans[ i ].start) || ((fOffset + len) > fileSpans[ i ].stop) ) {
          throw new IllegalArgumentException( fOffset + " ... " + (fOffset + len) + " not within " + fileSpans[ i ].toString() );
        }

        synchronized( f ) {
          if( f.getFramePosition() != fOffset ) {
            f.seekFrame( fOffset );
          }
          for( int k = 0; k < channelMap.length; k++, j++ ) {
            mappedData[ channelMap[ k ]] = data[ j ];
          }
          f.readFrames( mappedData, offset, len );
        }
      }
      clearMappedData()// avoid memory footprint
    }
    return len;
View Full Code Here

  throws IOException
  {
    final int        len      = (int) writeSpan.getLength();
    if( len == 0 ) return 0;

    InterleavedStreamFile  f;
    long          fOffset;
    int[]          channelMap;
    float[][]        mappedData;
   
    synchronized( fs ) {  // protects mappedDatas
      for( int i = 0, j = 0; i < fs.length; i++ ) {
        f      = fs[ i ];
        channelMap  = channelMaps[ i ];
        mappedData  = mappedDatas[ i ];
        fOffset    = fileSpans[ i ].start + writeSpan.start - span.start;

        if( (fOffset < fileSpans[ i ].start) || ((fOffset + len) > fileSpans[ i ].stop) ) {
          throw new IllegalArgumentException( fOffset + " ... " + (fOffset + len) + " not within " + fileSpans[ i ].toString() );
        }

        synchronized( f ) {
          if( f.getFramePosition() != fOffset ) {
            f.seekFrame( fOffset );
          }
          for( int k = 0; k < channelMap.length; k++, j++ ) {
            mappedData[ channelMap[ k ]] = data[ j ];
          }
          f.writeFrames( mappedData, offset, len );
        }
      }
      clearMappedData()// avoid memory footprint
    }
    return len;
View Full Code Here

  throws IOException
  {
    final long  len      = readSpan.getLength();
    if( len == 0 ) return 0;
 
    InterleavedStreamFile  f;
    long          fOffset;
    int[]          channelMap;
    float[][]        mappedData;
    int            chunkLen;
    float[][]        data      = new float[ numChannels ][ (int) Math.min( BUFSIZE, len )];
    long          framesCopied  = 0;
   
    do {
      synchronized( fs ) {  // protects mappedDatas
        for( int i = 0, j = 0; i < fs.length; i++ ) {
          f      = fs[ i ];
          channelMap  = channelMaps[ i ];
          mappedData  = mappedDatas[ i ];
          fOffset    = fileSpans[ i ].start + readSpan.start - span.start;
 
          if( (fOffset < fileSpans[ i ].start) || ((fOffset + len) > fileSpans[ i ].stop) ) {
            throw new IllegalArgumentException( fOffset + " ... " + (fOffset + len) + " not within " + fileSpans[ i ].toString() );
          }
         
          chunkLen  = (int) Math.min( BUFSIZE, len - framesCopied );
          synchronized( f ) {
            if( f.getFramePosition() != fOffset ) {
              f.seekFrame( fOffset );
            }
            for( int k = 0; k < channelMap.length; k++, j++ ) {
              mappedData[ channelMap[ k ]] = data[ j ];
            }
            f.readFrames( mappedData, 0, chunkLen );
          }
          target.writeFrames( data, 0, chunkLen );
          framesCopied += chunkLen;
        }
      }
View Full Code Here

  }

  public void flush()
  throws IOException
  {
    InterleavedStreamFile  f;

    for( int i = 0; i < fs.length; i++ ) {
      f = fs[ i ];
      synchronized( f ) {
        f.flush();
      }
    }
  }
View Full Code Here

  public void toXML( Document domDoc, Element node, Map options )
  throws IOException
  {
    super.toXML( domDoc, node, options );
 
    InterleavedStreamFile  iff;
    float[][]        frameBuf  = new float[ 1 ][];
    File          dir      = new File( (File) options.get(
                        XMLRepresentation.KEY_BASEPATH ), SUBDIR );
    AudioFileDescr      afd;
   
    if( !dir.isDirectory() ) IOUtil.createEmptyDirectory( dir );
   
    afd          = new AudioFileDescr();
    afd.type      = AudioFileDescr.TYPE_AIFF;
    afd.channels    = 1;
    afd.rate      = 1000.0f// XXX
    afd.bitsPerSample  = 32;
    afd.sampleFormat  = AudioFileDescr.FORMAT_FLOAT;
    afd.file      = new File( dir, getName() + SUFFIX_DISTANCE );
    iff          = AudioFile.openAsWrite( afd );
           
    frameBuf[ 0 ]    = distanceTable;
    iff.writeFrames( frameBuf, 0, distanceTable.length );
    iff.truncate();
    iff.close();

    afd          = new AudioFileDescr( afd );
    afd.file      = new File( dir, getName() + SUFFIX_ROTATION );
    iff          = AudioFile.openAsWrite( afd );
     
    frameBuf[ 0 ]    = rotationTable;
    iff.writeFrames( frameBuf, 0, rotationTable.length );
    iff.truncate();
    iff.close();
  }
View Full Code Here

  public void fromXML( Document domDoc, Element node, Map options )
  throws IOException
  {
    super.fromXML( domDoc, node, options );

    InterleavedStreamFile  iff;
    float[][]        frameBuf  = new float[ 1 ][];
    int            size;

    // read the tables from a named getName() in the directory getDirectory()
// File f2 = new File( getDirectory(), getName() + SUFFIX_DISTANCE );
// System.err.println( "file name : "+f2.getAbsolutePath() );

    iff = AudioFile.openAsRead( new File( new File( (File) options.get(
        XMLRepresentation.KEY_BASEPATH ), SUBDIR ), getName() + SUFFIX_DISTANCE ));
     
    size = (int) iff.getFrameNum();
    if( size != distanceTable.length ) {
      distanceTable = new float[ size ];
    }
    frameBuf[ 0 ] = distanceTable;
    iff.readFrames( frameBuf, 0, size );
    iff.close();

    iff = AudioFile.openAsRead( new File( new File( (File) options.get(
        XMLRepresentation.KEY_BASEPATH ), SUBDIR ), getName() + SUFFIX_ROTATION ));
     
    size = (int) iff.getFrameNum();
    if( size != rotationTable.length ) {
      rotationTable = new float[ size ];
    }
    frameBuf[ 0 ] = rotationTable;
    iff.readFrames( frameBuf, 0, size );
    iff.close();
  }
View Full Code Here

TOP

Related Classes of de.sciss.io.InterleavedStreamFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.