// ---------------------------------------------------------------------------
//	importPartials
// ---------------------------------------------------------------------------
//	Clients should be prepared to catch ImportExceptions.
//
//	THIS WON'T WORK IF CHUNKS ARE IN A DIFFERENT ORDER!!!
//	Fortunately, they never will be, since only the research 
//	version of Lemur ever wrote these files anyway.
//
static void
importPartials( std::istream & s, PartialList & partials, double bweCutoff )
{
	try 
	{
		//	the Container chunk must be first, read it:
		readContainer( s );
		
		//	read other chunks:
		bool foundParams = false, foundTracks = false;
		while ( ! foundParams || ! foundTracks )
		{
			//	read a chunk header, if it isn't the one we want, skip over it.
			CkHeader h;
			readChunkHeader( s, h );
			
			if ( h.id == AnalysisParamsID )
			{
				readParamsChunk( s );
				foundParams = true;
			}
			else if ( h.id == TrackDataID )
			{
				if (! foundParams) 	//	 I hope this doesn't happen
				{
					Throw( ImportException, 
							"Mia culpa! I am not smart enough to read the Track data before the Analysis Parameters data." );
				}							
				//	read Partials:
				for ( long counter = readTracksChunk( s ); counter > 0; --counter ) 
				{
					getPartial(s, partials, bweCutoff);
				}
				foundTracks = true;
			}
			else
			{
				s.ignore( h.size );
			}
		}

	}
	catch ( Exception & ex ) 
	{
		if ( s.eof() )
		{
			ex.append("Reached end of file before finding both a Tracks chunk and a Parameters chunk.");
		}
		ex.append( "Import failed." );
		Throw( ImportException, ex.str() );
	}

}
Example #2
0
        void readMap( std::istream& stream, Map& m)
        {
            m.clear();
            unsigned int mapEntries = 0;
            readValue( stream, mapEntries );
            for( unsigned int entry = 0; entry<mapEntries; ++entry )
            {
                std::pair< typename Map :: key_type, typename Map :: mapped_type > mapEntry;
                // read key
                readAndResizeContainer( stream, mapEntry.first );
                // read values
                readContainer( stream, mapEntry.second );

                // insert entry into map
                m.insert( mapEntry );
            }
        }
Example #3
0
void Reader4167::read(QByteArray *data)
{
    QString msg = QString(*data);
    QStringList msgList = msg.split("*");
    //qDebug() << msg;

    if( msgList.at(1) != "0")
    {
        qDebug() << "Error: " << msg;
    }
    else
    {
        //success

        int ctnCount = msgList.at(5).toInt();
        msgList.pop_front(); //0
        msgList.pop_front(); //1
        msgList.pop_front(); //2
        msgList.pop_front(); //3
        msgList.pop_front(); //4
        msgList.pop_front(); //5

        static bool readNew = false;
        if( readNew )
        {
            ctnList.clear();
            readNew = false;
        }

        for( int i = 0; i < ctnCount; i++ )
        {
            readContainer(msgList.at(i));
        }

        if( msgList.last() == QString("1") )
            readNew = true;
        //qDebug() << msgList;
    }

    qDebug() << ctnList.size();
}
Example #4
0
// ---------------------------------------------------------------------------
//	readAiffData
// ---------------------------------------------------------------------------
//
void 
AiffFile::readAiffData( const std::string & filename )
{
	ContainerCk containerChunk;
	CommonCk commonChunk;
	SoundDataCk soundDataChunk;
	InstrumentCk instrumentChunk;
	MarkerCk markerChunk;

	try 
	{
		std::ifstream s( filename.c_str(), std::ifstream::binary );
	
		//	the Container chunk must be first, read it:
		readChunkHeader( s, containerChunk.header );
        if ( !s )
        {
			Throw( FileIOException, "File not found, or corrupted." );
        }
		if ( containerChunk.header.id != ContainerId )
        {
			Throw( FileIOException, "Found no Container chunk." );
        }
		readContainer( s, containerChunk, containerChunk.header.size );
		
		//	read other chunks, we are only interested in
		//	the Common chunk, the Sound Data chunk, the Markers: 
		CkHeader h;
		while ( readChunkHeader( s, h ) )
		{			
			switch (h.id)
			{
				case CommonId:
					readCommonData( s, commonChunk, h.size );
					if ( commonChunk.channels != 1 )
					{
						Throw( FileIOException, 
							   "Loris only processes single-channel AIFF samples files." );
					}					
					if ( commonChunk.bitsPerSample != 8 &&
						 commonChunk.bitsPerSample != 16 &&
						 commonChunk.bitsPerSample != 24 &&
						 commonChunk.bitsPerSample != 32 )
					{
						Throw( FileIOException, "Unrecognized sample size." );
					}										
					break;
				case SoundDataId:
					readSampleData( s, soundDataChunk, h.size );
					break;
				case InstrumentId:
					readInstrumentData( s, instrumentChunk, h.size );
					break;
				case MarkerId:
					readMarkerData( s, markerChunk, h.size );
					break;
				default:
					s.ignore( h.size );
			}
		}
	
		if ( ! commonChunk.header.id || ! soundDataChunk.header.id )
		{
			Throw( FileIOException, 
				   "Reached end of file before finding both a Common chunk and a Sound Data chunk." );
		}
	}
	catch ( Exception & ex ) 
	{
		ex.append( " Failed to read AIFF file." );
		throw;
	}
	
	
	//	all the chunks have been read, use them to initialize
	//	the AiffFile members:
	rate_ = commonChunk.srate;
	
	if ( instrumentChunk.header.id )
	{
		notenum_ = instrumentChunk.baseNote;
		notenum_ -= 0.01 * instrumentChunk.detune;
	}
	
	if ( markerChunk.header.id )
	{
		for ( int j = 0; j < markerChunk.numMarkers; ++j )
		{
			MarkerCk::Marker & m = markerChunk.markers[j];
			markers_.push_back( Marker( m.position / rate_, m.markerName ) );
		}		
	}
	
	convertBytesToSamples( soundDataChunk.sampleBytes, samples_, commonChunk.bitsPerSample );
	if ( samples_.size() != commonChunk.sampleFrames )
	{
		notifier << "Found " << samples_.size() << " frames of "
				 << commonChunk.bitsPerSample << "-bit sample data." << endl;
		notifier << "Header says there should be " << commonChunk.sampleFrames 
				 << "." << endl;
	}
}