Restored LoadSoundObject
Can be used to load SFX from .wav files
This commit is contained in:
parent
cc0464e774
commit
a015d4d02e
1 changed files with 45 additions and 53 deletions
|
@ -13,14 +13,14 @@ equivalents.
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
//#include <stdio.h> // Used by commented-out code
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "WindowsWrapper.h"
|
#include "WindowsWrapper.h"
|
||||||
|
|
||||||
#include "Backends/Audio.h"
|
#include "Backends/Audio.h"
|
||||||
//#include "Main.h" // Was for gModulePath, but this is unneeded in the portable branch since LoadSoundObject is commented-out
|
#include "Main.h"
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
#include "Organya.h"
|
#include "Organya.h"
|
||||||
#include "PixTone.h"
|
#include "PixTone.h"
|
||||||
|
@ -103,35 +103,33 @@ BOOL InitSoundObject(const char *resname, int no)
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
// Completely unused function for loading a .wav file as a sound effect.
|
// Completely unused function for loading a .wav file as a sound effect.
|
||||||
// Some say that sounds heard in CS Beta footage don't sound like PixTone...
|
// Some say that sounds heard in CS Beta footage don't sound like PixTone...
|
||||||
BOOL LoadSoundObject(LPCSTR file_name, int no)
|
BOOL LoadSoundObject(const char *file_name, int no)
|
||||||
{
|
{
|
||||||
char path[MAX_PATH];
|
std::string path;
|
||||||
DWORD i;
|
unsigned long i;
|
||||||
DWORD file_size = 0;
|
unsigned long file_size = 0;
|
||||||
char check_box[58];
|
char check_box[58];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
HANDLE hFile;
|
|
||||||
|
|
||||||
sprintf(path, "%s\\%s", gModulePath, file_name);
|
path = gModulePath + '/' + file_name;
|
||||||
|
|
||||||
if (lpDS == NULL)
|
if (!audio_backend_initialised)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
hFile = CreateFileA(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
if ((fp = fopen(path.c_str(), "rb")) == NULL)
|
||||||
if (hFile == INVALID_HANDLE_VALUE)
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
file_size = GetFileSize(hFile, NULL);
|
fseek(fp, 0, SEEK_END);
|
||||||
CloseHandle(hFile);
|
file_size = ftell(fp);
|
||||||
|
rewind(fp);
|
||||||
|
|
||||||
if ((fp = fopen(path, "rb")) == NULL)
|
// Let's not throttle disk I/O, shall we...
|
||||||
return FALSE;
|
//for (i = 0; i < 58; i++)
|
||||||
|
// fread(&check_box[i], sizeof(char), 1, fp);
|
||||||
for (i = 0; i < 58; i++)
|
fread(check_box, 1, 58, fp);
|
||||||
fread(&check_box[i], sizeof(char), 1, fp);
|
|
||||||
|
|
||||||
if (check_box[0] != 'R')
|
if (check_box[0] != 'R')
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -142,57 +140,51 @@ BOOL LoadSoundObject(LPCSTR file_name, int no)
|
||||||
if (check_box[3] != 'F')
|
if (check_box[3] != 'F')
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
DWORD *wp;
|
unsigned char *wp;
|
||||||
wp = (DWORD*)malloc(file_size); // ファイルのワークスペースを作る (Create a file workspace)
|
wp = (unsigned char*)malloc(file_size); // ファイルのワークスペースを作る (Create a file workspace)
|
||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
for (i = 0; i < file_size; i++)
|
// Bloody hell, Pixel, come on...
|
||||||
fread((BYTE*)wp+i, sizeof(BYTE), 1, fp);
|
//for (i = 0; i < file_size; i++)
|
||||||
|
// fread((BYTE*)wp+i, sizeof(char), 1, fp);
|
||||||
|
fread(wp, 1, file_size, fp);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
// セカンダリバッファの生成 (Create secondary buffer)
|
// Get sound properties, and check if it's valid
|
||||||
DSBUFFERDESC dsbd;
|
unsigned long buffer_size = wp[0x36] | (wp[0x37] << 8) | (wp[0x38] << 16) | (wp[0x39] << 24);
|
||||||
ZeroMemory(&dsbd, sizeof(dsbd));
|
unsigned short format = wp[5] | (wp[6] << 8);
|
||||||
dsbd.dwSize = sizeof(dsbd);
|
unsigned short channels = wp[7] | (wp[8] << 8);
|
||||||
dsbd.dwFlags = DSBCAPS_STATIC | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
|
unsigned long sample_rate = wp[9] | (wp[0xA] << 8) | (wp[0xB] << 16) | (wp[0xC] << 24);
|
||||||
dsbd.dwBufferBytes = *(DWORD*)((BYTE*)wp+0x36); // WAVEデータのサイズ (WAVE data size)
|
|
||||||
dsbd.lpwfxFormat = (LPWAVEFORMATEX)(wp+5);
|
|
||||||
|
|
||||||
if (lpDS->CreateSoundBuffer(&dsbd, &lpSECONDARYBUFFER[no], NULL) != DS_OK)
|
if (format != 1) // 1 is WAVE_FORMAT_PCM
|
||||||
|
{
|
||||||
|
free(wp);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channels != 1) // The mixer only supports mono right now
|
||||||
|
{
|
||||||
|
free(wp);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// セカンダリバッファの生成 (Create secondary buffer)
|
||||||
|
lpSECONDARYBUFFER[no] = AudioBackend_CreateSound(sample_rate, wp + 0x3A, buffer_size);
|
||||||
|
|
||||||
|
if (lpSECONDARYBUFFER[no] == NULL)
|
||||||
{
|
{
|
||||||
#ifdef FIX_BUGS
|
#ifdef FIX_BUGS
|
||||||
free(wp); // The updated Organya source code includes this fix
|
free(wp); // The updated Organya source code includes this fix
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
LPVOID lpbuf1, lpbuf2;
|
|
||||||
DWORD dwbuf1, dwbuf2;
|
|
||||||
|
|
||||||
HRESULT hr;
|
|
||||||
hr = lpSECONDARYBUFFER[no]->Lock(0, *(DWORD*)((BYTE*)wp+0x36), &lpbuf1, &dwbuf1, &lpbuf2, &dwbuf2, 0);
|
|
||||||
|
|
||||||
if (hr != DS_OK)
|
|
||||||
{
|
|
||||||
#ifdef FIX_BUGS
|
|
||||||
free(wp); // The updated Organya source code includes this fix
|
|
||||||
#endif
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
CopyMemory(lpbuf1, (BYTE*)wp+0x3A, dwbuf1); // +3aはデータの頭 (+ 3a is the head of the data)
|
|
||||||
|
|
||||||
if (dwbuf2 != 0)
|
|
||||||
CopyMemory(lpbuf2, (BYTE*)wp+0x3A+dwbuf1, dwbuf2);
|
|
||||||
|
|
||||||
lpSECONDARYBUFFER[no]->Unlock(lpbuf1, dwbuf1, lpbuf2, dwbuf2);
|
|
||||||
|
|
||||||
free(wp);
|
free(wp);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
void PlaySoundObject(int no, int mode)
|
void PlaySoundObject(int no, int mode)
|
||||||
{
|
{
|
||||||
if (!audio_backend_initialised)
|
if (!audio_backend_initialised)
|
||||||
|
|
Loading…
Add table
Reference in a new issue