Exemple #1
0
int
MidiFile::read(const char *fileName) {
	if (fileName == NULL)
		return 1;
	
	setFileName(fileName);
	_target = openFile(fileName);
	
	if (!_target)
		return 1;

	readFileHeader();
	setType();
	setTrackCount();
	setBPM();
	for (int i = 0; i < _fileHeader._tracks; i++) {
		_curTrack = i;
		readTrack();
		printContour();
	}

	fclose(_target);
   	return 0;
}		
void WaveAudioEssenceReader::initialise(Reader* reader) throw(Exception)
{
    EssenceReader::initialise(reader);

    reader->setPosition(0, Reader::BEGIN);
    RIFFReader riffReader(reader);

    if (riffReader.descend() == RIFFChunk::fourCC('R', 'I', 'F', 'F'))
    {
        // Check that this is a WAVE file
        if (riffReader.getCurrentChunk()->getType() !=
            RIFFChunk::fourCC('W', 'A', 'V', 'E'))
        {
            error(RIFF_ERROR_NotWAVE);
        }

        UInt32 fourcc;
        while ((fourcc = riffReader.descend()) != 0)
        {
            if (fourcc == RIFFChunk::fourCC('f', 'm', 't', ' '))
            {
                // Get the 'fmt ' chunk
                if (_fmtChunk != 0)
                {
                    delete _fmtChunk;
                }

                _fmtChunk = new fmt_ck;
                riffReader.read(
                    (UInt8*) _fmtChunk,
                    sizeof(fmt_ck));
            }
            else if (fourcc == RIFFChunk::fourCC('b', 'e', 'x', 't'))
            {
                // Get the 'bext' chunk
                if (_bextBuffer != 0)
                {
                    delete _bextBuffer;
                }

                _bextBuffer = new UInt8[riffReader.getCurrentChunk()->getSize()];
                _bextChunk = reinterpret_cast<bext_ck*>(_bextBuffer);
                riffReader.read(
                    _bextBuffer,
                    riffReader.getCurrentChunk()->getSize());
            }
            else if (fourcc == RIFFChunk::fourCC('d', 'a', 't', 'a'))
            {
                // Note the position of the expected 'data' chunk
                _dataOffset = reader->getPosition();
                _dataLength = riffReader.getCurrentChunk()->getSize();
            }

            riffReader.ascend();
        }

        if (_fmtChunk == 0)
        {
            error(RIFF_ERROR_MissingFMTChunk);
            return;
        }
        else if (_dataOffset == 0)
        {
            error(RIFF_ERROR_FileIsEmpty);
            return;
        }
    }
    else
    {
        error(RIFF_ERROR_NotRIFF);
        return;
    }

    //UL* ulContainer = new UL(LABEL_EssenceContainerGC_AES_BWAV);
    //ulContainer->setByte(15, 0x01); // Essence Element Type - Wave Frame Wrapped

    //_essenceContainers.add(ulContainer);

    //_ulAudio = new UL(KEY_GCSoundEssenceElement);
    //_ulAudio->setByte(14, 0x01);    // Essence Element Count
    //_ulAudio->setByte(15, 0x01);    // Essence Element Type - Wave Frame Wrapped
    //_ulAudio->setByte(16, 0x01);    // Essence Element Number
    //getElementKeys().add(_ulAudio);

    //getTrackDataDefinitions().add(new UL(LABEL_SoundEssenceTrack));

    //// Configure the descriptor
    //WaveAudioEssenceDescriptor* waed = static_cast<WaveAudioEssenceDescriptor*>(
    //    getDictionary()->createInstance(KEY_WaveAudioEssenceDescriptor));
    //waed->setSampleRate(_editRate);
    //waed->setEssenceContainer(*ulContainer);
    //waed->setAudioSamplingRate(_fmtChunk->nSamplesPerSec);
    //waed->setChannelCount(_fmtChunk->nChannels);
    //waed->setQuantizationBits(_fmtChunk->wBitsPerSample);
    //waed->setBlockAlign(_fmtChunk->nBlockAlign);
    //waed->setAvgBps(_fmtChunk->nAvgBytesPerSec);
    //_descriptor = waed;

    setEditRate(_editRate);

    // Exit at this point if we failed
    if (_baseSampleCount == 0 || _combinedDataLength == 0)
    {
        return;
    }

    setTrackCount(1);

    // Position the reader at the start of the data
    reset();
}