Ejemplo n.º 1
0
ViAudioFormat::ViAudioFormat(const QAudioFormat &other)
{
	if(other.sampleType() == QAudioFormat::SignedInt)
	{
		setSampleType(ViAudioFormat::SignedInt);
	}
	else if(other.sampleType() == QAudioFormat::UnSignedInt)
	{
		setSampleType(ViAudioFormat::UnSignedInt);
	}
	else if(other.sampleType() == QAudioFormat::Float)
	{
		setSampleType(ViAudioFormat::Float);
	}
	else
	{
		setSampleSize(ViAudioFormat::Unknown);
	}

	if(other.byteOrder() == QAudioFormat::BigEndian)
	{
		setByteOrder(ViAudioFormat::BigEndian);
	}
	else
	{
		setByteOrder(ViAudioFormat::LittleEndian);
	}
	
	mQuality = ViAudioFormat::Average;
	mSampleSize = other.sampleSize();
	mSampleRate = other.sampleRate();
	mChannelCount = other.channelCount();
	mCodec = NULL;
}
Ejemplo n.º 2
0
void itsRandom::diversification()
{
    // reinit all
    setSampleSize( getSampleSize() );

    // draw each point in an hyper cube
    for( unsigned int i=0; i < getSampleSize(); i++) {
        // draw solution
        itsPoint p;
        p.setSolution( randomUniform( this->getProblem()->boundsMinima(), this->getProblem()->boundsMaxima() ) );
        // get values
        setSamplePoint(i, evaluate(p) );
    }
}
void itsSimulatedAnnealing::diversification()
{
    // reinit all
    setSampleSize( getSampleSize() );

    // draw each point in an hyper cube
    for( unsigned int i=0; i < getSampleSize(); i++) {
        // draw solution
        p_new.setSolution( randomUniform( this->getProblem()->boundsMinima(), this->getProblem()->boundsMaxima() ) );
        p_new = evaluate(p_new);
        setSamplePoint( i, p_new );
    
        // Metropolis rule
        // if the value is the better than the previous point, accept
        if( isValueSmaller(p_current,p_new) ) {
            p_current = p_new;
        } else {
            // else, draw a random number and see if we accept the new point
            if( randomUniform(0.0,temperature_max) < temperature ) {
                p_current = p_new;
            } // else the current point is kept
        }
    }
}
Ejemplo n.º 4
0
WavFileInputSoundStream::WavFileInputSoundStream(const std::string & fileName): index(0)
{
	try
	{
		std::ifstream file(fileName);
	
		if(file.fail())	throw std::string("File not found.");		

		char chunkId[4];

		read(file, chunkId);

		if(std::string(chunkId, 4) != "RIFF")
			throw std::string("Not a wave file(1)");			

		read(file, chunkSize);

		read(file, chunkId);

        if(std::string(chunkId, 4) != "WAVE")
			throw std::string("Not a wave file(2)");

		read(file, chunkId);

        if(std::string(chunkId, 4) != "fmt ")
			throw std::string("Not a wave file(3)");

		uint32_t subchunkSize;

		read(file, subchunkSize);
			
		// if(subchunkSize != 16)
		//	throw std::string("Not supported fmt subchunk size: ")+std::to_string(subchunkSize);

		uint16_t audioFormat;
		
		read(file, audioFormat);

		if(audioFormat != 1)
			throw std::string("Not supported audio format: ")+std::to_string(audioFormat);

        uint16_t numChannels;

		read(file, numChannels);

		if(numChannels != 1 && numChannels != 2)
			throw std::string("Not supported number of channels: ")+std::to_string(numChannels);

        setChannels(numChannels);

        uint32_t sampleRate;

		read(file, sampleRate);

        setSampleRate(sampleRate);

		read(file, byteRate);

		read(file, blockAlign);

        uint16_t bitsPerSample;
		read(file, bitsPerSample);

        setSampleSize(bitsPerSample);

		if(subchunkSize > 16)
			file.ignore(subchunkSize-16);

		read(file, chunkId);

        if(std::string(chunkId, 4) != "data")
			throw std::string("Unexpected chunk id: ") + std::string(chunkId, 4);

		read(file, dataSize);

		data.resize(dataSize);

		file.read((char *)&data[0], dataSize);

		if(file.fail())
			throw std::string("Not a wave file(5)");

		numFrames = dataSize/(numChannels*bitsPerSample/8);

		file.close();
	}
	catch(const std::string & str)
	{
        this->setFailString(str);
        this->setFail(true);
	}
}