Пример #1
0
int checkALCError()
{
    char *pErrorString = GetALCErrorString(alcGetError(pDevice));
    if(pErrorString)
    {
        fprintf(stderr, "[SPU] ALC: %s.\n", pErrorString);
        return -1;
    }
    
    return 0;
}
Пример #2
0
void openWAV(char* fileName, ALuint* dest) {
	alGetError();
	int errorNum = 0;
	
	ALuint buffer;
	alGenBuffers(1, &buffer);
	
	errorNum = alGetError();
	
	
	
	errorNum = alGetError();
	
	FILE* file;
	file = fopen(fileName, "r");
	if (file == NULL) {
		printf("File access error\n");
		exit(1);
	}
	
	//dumpWholeFile(file);
	
	char xbuffer[5];
	if (fread(xbuffer, sizeof(char), 4, file) != 4 || strcmp(xbuffer, "RIFF") != 0)
		throw "Not a WAV file";
	
	file_read_int32_le(xbuffer, file);
	if (fread(xbuffer, sizeof(char), 4, file) != 4 || strcmp(xbuffer, "WAVE") != 0)
		throw "Not a WAV file!";
	
	if (fread(xbuffer, sizeof(char), 4, file) != 4 || strcmp(xbuffer, "fmt ") != 0)
		throw "Invalid WAV file!";
	
	printf("char size: %lu", sizeof(char));
	
	errorNum = alGetError();
	
	GetALErrorString(errorNum);
	GetALCErrorString(errorNum);
	
	file_read_int32_le(xbuffer, file);
	short audioFormat = file_read_int16_le(xbuffer, file);
	short channels = file_read_int16_le(xbuffer, file);
	int sampleRate = file_read_int32_le(xbuffer, file);
	int byteRate = file_read_int32_le(xbuffer, file);
	file_read_int16_le(xbuffer, file);
	short bitsPerSample = file_read_int16_le(xbuffer, file);
	
	//if (audioFormat != 16) {
	//	short extraParams = file_read_int16_le(xbuffer, file);
	//	file_ignore_bytes(file, extraParams);
	//}
	
	bool atData = false;
	
	while (!atData) {
		if (fread(xbuffer, sizeof(char), 4, file) != 4 || strcmp(xbuffer, "data") != 0)
			printf("Discarding fluff\n");
		else
			atData = true;
			//throw "Invalid WAV file";
	}
	
	int dataChunkSize = file_read_int32_le(xbuffer, file)+4;
	unsigned char* bufferData = file_allocate_and_read_bytes(file, (size_t)dataChunkSize);
	
	printf("Error before alBufferData: %x\n", alGetError());
	
//	float duration = float(dataChunkSize)/byteRate;
	alBufferData(buffer, GetFormatFromInfo(channels, bitsPerSample), bufferData, dataChunkSize, sampleRate);
	//*dest = buffer;
	alSourcei(*dest, AL_BUFFER, buffer);
	errorNum = alGetError();
	free(bufferData);
	fclose(file);
}