コード例 #1
0
ファイル: SoundData.cpp プロジェクト: Cpasjuste/Kairy
bool SoundData::load(const std::string & filename)
{
    byte signature[4];
    bool isWav = false;

    FILE* fp = fopen(filename.c_str(), "rb");

    if (!fp)
    {
        return false;
    }

    fread(signature, 1, 4, fp);
    fclose(fp);

    if (signature[0] == 'R' &&
            signature[1] == 'I' &&
            signature[2] == 'F' &&
            signature[3] == 'F')
    {
        isWav = true;
    }

    return isWav ? loadWav(filename) : loadOgg(filename);
}
コード例 #2
0
ファイル: sound.cpp プロジェクト: AakashDabas/DrBrain
void cSound::load(int sndCode, char* fileName)
{
	arrBuffer* tmp = sndBuffers;
	if (tmp != NULL)
	{
		while (tmp->next != NULL)
		{
			if (tmp->sndCode == sndCode)
				assert(0 && "sndCode already loaded. Please choose someother code");
			tmp = tmp->next;
		}
		if (tmp->sndCode == sndCode)
			assert(0 && "sndCode already loaded. Please choose someother code");
		tmp->next = new arrBuffer;
		tmp = tmp->next;
	}
	else
	{
		sndBuffers = new arrBuffer;
		tmp = sndBuffers;
	}
	tmp->sndCode = sndCode;
	if (!loadWav(fileName, &tmp->secBuffer))
		assert(0 && "Snd File Can't Be Accessed");
}
コード例 #3
0
ファイル: sound.cpp プロジェクト: YurieCo/game-basecode
sound::sound(game *g, std::string filename)
{
    this->g = g;

    resource r(filename);

    loadWav(r.getRaw(), r.getLength());
}
コード例 #4
0
ファイル: WavLoader.cpp プロジェクト: 67-6f-64/OryxEngine
	AudioStream* WavLoader::streamSound(String filename)
	{
		int sampleRate;
		int format;
		int dataSize;
		std::ifstream* file = loadWav(filename, format, sampleRate, dataSize);
		return new WavStream(file, format, sampleRate, dataSize);
	}
コード例 #5
0
ファイル: Audio.cpp プロジェクト: jameshegarty/bajaengine
int Audio::load(Path file){
	// Variables to load into.

	if(!os().fileExists(file)){
		logs().audio.write("[AudioObject] Error, file '"+file.getRelative()+"' doesn't exist");
		console().write("audio error: file '"+file.getRelative()+"' doesn't exist");

		return -1;
	}

	for(int i=0; i<sources.size(); i++){
		if(sources[i]->filename==file){
			console().write("NOTE: the file "+file.getRelative()+" was already loaded as another audio object.  This is not an error, but may not be what was intended");
		}
	}

	String filetype=file.getExtension();

	if(filetype=="wav"){
		if(hardware.audio){
			return loadWav(file);
		}else{
			return loadFakeWav(file);
		}
	}else if(filetype=="ogg"){

		#ifdef FEATURE_OGG
			if(hardware.audio){
				#ifdef OGG_STREAM
					return loadOggStream(file);
				#else
					return loadOgg(file);
				#endif
			}else{
				return loadFakeOgg(file);
			}
		#else
			console().write("audio error: this version of the engine can't open oggs");
			return -1;
		#endif

	}else{
		logs().audio.write("[AudioObject] error: unknown filetype '"+filetype+"' for file '"+file.getRelative()+"'");
		console().write("audio error: unknown filetype '"+filetype+"' for file '"+file.getRelative()+"'");

		return -1;

	}


	
	
}
コード例 #6
0
ファイル: SoundData.cpp プロジェクト: Cpasjuste/Kairy
bool SoundData::load(const byte * buffer, Uint32 bufferSize)
{
    if (!buffer || bufferSize == 0)
    {
        return false;
    }

    if (buffer[0] == 'R' &&
            buffer[1] == 'I' &&
            buffer[2] == 'F' &&
            buffer[3] == 'F')
    {
        return loadWav(buffer, bufferSize);
    }

    return loadOgg(buffer, bufferSize);
}
コード例 #7
0
ファイル: WavLoader.cpp プロジェクト: 67-6f-64/OryxEngine
	void WavLoader::loadSound(String filename, ALuint& out)
	{
		int sampleRate;
		int format;
		int dataSize;

		std::ifstream* file = loadWav(filename, format, sampleRate, dataSize);

		// read in the entire contents of the data chunk
		char* data = new char[dataSize];
		file->read(data, dataSize);

		// create and write to output buffer
		alGenBuffers(1, &out);
		alBufferData(out, format, static_cast<void*>(data), dataSize, sampleRate);

		// cleanup
		delete file;
		delete[] data;
		file->close();
	}
コード例 #8
0
SoundManager::SoundManager(QString soundDirectory)
{
    QString applicationDirectory;
    QString completeSoundDirectory;
    char cwd[PATH_MAX];

    // Initialize ALUT.
    if (alutInit(NULL, NULL) == false) {
        reportALUTError(alutGetError());
    }

    // Get the complete application directory in which we will load sounds from.
    // We convert to QString since it is more convenient when working with directories.
    getcwd(cwd, PATH_MAX);
    applicationDirectory = QString(cwd);

    // Append the assets directory and the actual sounds directory name.
    completeSoundDirectory = applicationDirectory
                            .append("/app/native/assets/")
                            .append(soundDirectory);

    // Create OpenAL buffers from all files in the sound directory.
    QDir dir(completeSoundDirectory);

    if (!dir.exists()) {
        qDebug() << "Cannot find the sounds directory." << completeSoundDirectory;
    } else {

        // Set a filter for file listing, only files should be listed.
        dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);

        // Get a directory listing.
        QFileInfoList list = dir.entryInfoList();

        // Traverse and load all the audio files into buffers.
        for (int i = 0; i < list.size(); ++i) {

            // Create a file info for each audio file.
        	QFileInfo fileInfo = list.at(i);
        	const char* path = fileInfo.absoluteFilePath().toStdString().c_str();
        	ALenum error;

        	// Generate buffers to hold audio data.
			alGenBuffers(1, &mSoundBuffers[fileInfo.fileName()]);

			error = alGetError();
			if (error != AL_NO_ERROR) {
				reportOpenALError(error);
				break;
			}

			// Load sound file.
			FILE* file = fopen(path, "rb");
			if (!file) {
				qDebug() << "Failed to load audio file " << path;
				break;
			}

			// Read the file header
			char header[12];
			ALuint bufferId = mSoundBuffers[fileInfo.fileName()];
			if (fread(header, 1, 12, file) != 12) {
				qDebug() << "Invalid header for audio file " << path;
				alDeleteBuffers(1, &bufferId);
				goto cleanup;
			}

			// Check the file format & load the buffer with audio data.
			if (memcmp(header, "RIFF", 4) == 0) {
				if (!loadWav(file, bufferId)) {
					qDebug() << "Invalid wav file: " << path;
					alDeleteBuffers(1, &bufferId);
					goto cleanup;
				}
			}
			else if (memcmp(header, "OggS", 4) == 0) {
				if (!loadOgg(file, bufferId)) {
					qDebug() << "Invalid ogg file: " << path;
					alDeleteBuffers(1, &bufferId);
					goto cleanup;
				}
			}
			else {
				qDebug() << "Unsupported audio file: " << path;
				goto cleanup;
			}

		cleanup:
			if (file) {
				fclose(file);
			}
        }
    }

    // Generate a number of sources used to attach buffers and play.
    alGenSources(SOUNDMANAGER_MAX_NBR_OF_SOURCES, mSoundSources);
    ALenum error = alGetError();
    if (error != AL_NO_ERROR) {
        reportOpenALError(error);
    }
}
コード例 #9
0
ファイル: Audio.cpp プロジェクト: bruni68510/Joyau
Sound::Sound(const Sound &obj)
{
   loadWav(obj.sound.c_str());
}