lib/minim/src/ddf/minim/Minim.java
/**
	 * Loads the requested file into a MultiChannelBuffer. The buffer's channel count
	 * and buffer size will be adjusted to match the file.
	 * 
	 * @shortdesc Loads the requested file into a MultiChannelBuffer.
	 * 
	 * @example Advanced/loadFileIntoBuffer
	 * 
	 * @param filename 
	 * 			the file to load
	 * @param outBuffer
	 * 			the MultiChannelBuffer to fill with the file's audio samples
	 * 
	 * @return	the sample rate of audio samples in outBuffer, or 0 if the load failed.
	 * 
	 * @related MultiChannelBuffer
	 */
Loads the requested file into a MultiChannelBuffer. The buffer's channel count
and buffer size will be adjusted to match the file.

@shortdesc Loads the requested file into a MultiChannelBuffer.



@param filename
the file to load
@param outBuffer
the MultiChannelBuffer to fill with the file's audio samples

@return      the sample rate of audio samples in outBuffer, or 0 if the load failed.


Loads the requested file into a MultiChannelBuffer . The buffer ' s channel count and buffer size will be adjusted to match the file . @shortdesc Loads the requested file into a MultiChannelBuffer . @param filename the file to load @param outBuffer the MultiChannelBuffer to fill with the file ' s audio samples @return the sample rate of audio samples in outBuffer or 0 if the load failed .
public float loadFileIntoBuffer( String filename, MultiChannelBuffer outBuffer )
	{
		final int readBufferSize 		= 4096;
		float     sampleRate 			= 0;
		AudioRecordingStream  stream 	= mimp.getAudioRecordingStream( filename, readBufferSize, false );
		if ( stream != null )
		{
			stream.play();
			sampleRate = stream.getFormat().getSampleRate();
			final int channelCount = stream.getFormat().getChannels();
			MultiChannelBuffer readBuffer = new MultiChannelBuffer( channelCount, readBufferSize );
			outBuffer.setChannelCount( channelCount );
			long totalSampleCount = stream.getSampleFrameLength();
			if ( totalSampleCount == -1 )
			{
				totalSampleCount = AudioUtils.millis2Frames( stream.getMillisecondLength(), stream.getFormat() );
			}
			debug( "Total sample count for " + filename + " is " + totalSampleCount );
			outBuffer.setBufferSize( (int)totalSampleCount );
			long totalSamplesRead = 0;
			while( totalSamplesRead < totalSampleCount )
			{
				if ( totalSampleCount - totalSamplesRead < readBufferSize )
				{
					readBuffer.setBufferSize( (int)(totalSampleCount - totalSamplesRead) );
				}
				int samplesRead = stream.read( readBuffer );
				if ( samplesRead == 0 )
				{
					debug( "loadSampleIntoBuffer: got 0 samples read" );
					break;
				}
				for(int i = 0; i < channelCount; ++i)
				{
					for(int s = 0; s < samplesRead; ++s)
					{
						outBuffer.setSample( i, (int)totalSamplesRead+s, readBuffer.getSample( i, s ) );
					}
				}
				totalSamplesRead += samplesRead;
			}
			if ( totalSamplesRead != totalSampleCount )
			{
				outBuffer.setBufferSize( (int)totalSamplesRead );
			}
			debug("loadSampleIntoBuffer: final output buffer size is " + outBuffer.getBufferSize() );
			stream.close();
		}
	    else
	    {
	        debug("Unable to load an AudioRecordingStream for " + filename);
	    }
		return sampleRate;
	}
public float loadFileIntoBuffer ( String filename , MultiChannelBuffer outBuffer ) { final int readBufferSize = 4096 ; float sampleRate = 0 ; AudioRecordingStream stream = mimp . getAudioRecordingStream ( filename , readBufferSize , false ) ; if ( stream != null ) { stream . play ( ) ; sampleRate = stream . getFormat ( ) . getSampleRate ( ) ; final int channelCount = stream . getFormat ( ) . getChannels ( ) ; MultiChannelBuffer readBuffer = new MultiChannelBuffer ( channelCount , readBufferSize ) ; outBuffer . setChannelCount ( channelCount ) ; long totalSampleCount = stream . getSampleFrameLength ( ) ; if ( totalSampleCount == - 1 ) { totalSampleCount = AudioUtils . millis2Frames ( stream . getMillisecondLength ( ) , stream . getFormat ( ) ) ; } debug ( "Total sample count for " + filename + " is " + totalSampleCount ) ; outBuffer . setBufferSize ( ( int ) totalSampleCount ) ; long totalSamplesRead = 0 ; while ( totalSamplesRead < totalSampleCount ) { if ( totalSampleCount - totalSamplesRead < readBufferSize ) { readBuffer . setBufferSize ( ( int ) ( totalSampleCount - totalSamplesRead ) ) ; } int samplesRead = stream . read ( readBuffer ) ; if ( samplesRead == 0 ) { debug ( "loadSampleIntoBuffer: got 0 samples read" ) ; break ; } for ( int i = 0 ; i < channelCount ; ++ i ) { for ( int s = 0 ; s < samplesRead ; ++ s ) { outBuffer . setSample ( i , ( int ) totalSamplesRead + s , readBuffer . getSample ( i , s ) ) ; } } totalSamplesRead += samplesRead ; } if ( totalSamplesRead != totalSampleCount ) { outBuffer . setBufferSize ( ( int ) totalSamplesRead ) ; } debug ( "loadSampleIntoBuffer: final output buffer size is " + outBuffer . getBufferSize ( ) ) ; stream . close ( ) ; } else { debug ( "Unable to load an AudioRecordingStream for " + filename ) ; } return sampleRate ; }
Loads the requested file into a MultiChannelBuffer.
Loads the requested file into a MultiChannelBuffer .
//stream.open(); // for reading the file in, in chunks. // make sure the out buffer is the correct size and type. // how many samples to read total // now read in chunks. // is the remainder smaller than our buffer? // copy data from one buffer to the other. // a faster way to do this would be nice.