MilesLib: run the 40250 sound sources verbatim over an AIL software mixer
Copy SoundBase/SoundData/SoundInstance*/SoundManager*/Type from 40250 and implement the AIL_* calls they make in MilesAil.cpp (2D pan, 3D distance and listener pan, threaded stream decode, loop counts). The SDL host drains the mixer. CSoundManager is created/updated/destroyed where 40250 does it and the old AudioCommands bridge is removed. Port-map MilesLib 142/142 PORTED. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d509f0a8b4
commit
11991d4d1f
@@ -11,7 +11,6 @@
|
||||
#include "ui_scale.h"
|
||||
#include "vulkan_window.h"
|
||||
|
||||
#include "platform/MilesLib/AudioCommands.h"
|
||||
#include "platform/PackBackend.h"
|
||||
#include "platform/ScriptLib/PythonBoot.h"
|
||||
#include "platform/UserInterface/ServerClock.h"
|
||||
|
||||
+39
-196
@@ -2,232 +2,75 @@
|
||||
|
||||
#ifdef MT_NATIVE_HAS_LIVE_CLIENT
|
||||
#include "audio_decode.h"
|
||||
#include "texture_decode.h"
|
||||
#include "platform/MilesLib/AudioCommands.h"
|
||||
#include "platform/MilesLib/MilesMixer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
|
||||
namespace mt_host {
|
||||
|
||||
namespace {
|
||||
|
||||
bool decode_miles_file(const void* data, std::size_t size, std::vector<float>& out) {
|
||||
if (!decode_audio(static_cast<const std::uint8_t*>(data), size, out)) {
|
||||
SDL_Log("audio: cannot decode a %zu-byte sound file", size);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
static_assert(MT_MILES_MIX_RATE == kMixRate && kMixChannels == 2, "Miles mix format");
|
||||
|
||||
NativeAudioEngine::NativeAudioEngine() {
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO)) {
|
||||
SDL_AudioSpec spec{};
|
||||
spec.format = SDL_AUDIO_F32;
|
||||
spec.channels = 2;
|
||||
spec.freq = 44100;
|
||||
spec.channels = kMixChannels;
|
||||
spec.freq = kMixRate;
|
||||
stream_ = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, nullptr, nullptr);
|
||||
if (stream_)
|
||||
SDL_ResumeAudioStreamDevice(stream_);
|
||||
else
|
||||
SDL_Log("audio: no playback device: %s", SDL_GetError());
|
||||
}
|
||||
// Always DrainAudioCommands() from cold boot so stale queued commands don't accumulate.
|
||||
(void)DrainAudioCommands();
|
||||
// Without a device the Miles driver does not open, like 40250 with no sound card.
|
||||
if (stream_)
|
||||
MtMilesSetDecoder(decode_miles_file);
|
||||
const char* trace = std::getenv("MT_AUDIO_TRACE");
|
||||
trace_ = trace && *trace == '1';
|
||||
}
|
||||
|
||||
NativeAudioEngine::~NativeAudioEngine() {
|
||||
MtMilesSetDecoder(nullptr);
|
||||
if (stream_)
|
||||
SDL_DestroyAudioStream(stream_);
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
}
|
||||
|
||||
void NativeAudioEngine::pump() {
|
||||
const auto commands = DrainAudioCommands();
|
||||
for (const auto& cmd : commands) {
|
||||
++commands_drained_;
|
||||
switch (cmd.type) {
|
||||
case AudioCommand::PlaySound2D: {
|
||||
const auto* clip = get_clip(cmd.filename);
|
||||
if (clip && !clip->empty()) {
|
||||
Voice v{};
|
||||
v.samples = clip;
|
||||
v.volume = sound_volume_;
|
||||
v.target_volume = sound_volume_;
|
||||
v.filename = cmd.filename;
|
||||
voices_.push_back(std::move(v));
|
||||
++played_2d_;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AudioCommand::PlaySound3D: {
|
||||
const auto* clip = get_clip(cmd.filename);
|
||||
if (clip && !clip->empty()) {
|
||||
Voice v{};
|
||||
v.samples = clip;
|
||||
v.volume = sound_volume_ * std::clamp(cmd.volume, 0.0f, 1.0f);
|
||||
v.target_volume = v.volume;
|
||||
v.loop = cmd.play_count != 1;
|
||||
v.is_3d = true;
|
||||
v.handle = cmd.id;
|
||||
v.filename = cmd.filename;
|
||||
voices_.push_back(std::move(v));
|
||||
++played_3d_;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AudioCommand::StopSound3D:
|
||||
voices_.erase(
|
||||
std::remove_if(voices_.begin(), voices_.end(), [&](const Voice& v) {
|
||||
return v.is_3d && v.handle == cmd.id;
|
||||
}),
|
||||
voices_.end());
|
||||
break;
|
||||
case AudioCommand::StopAllSound3D:
|
||||
voices_.erase(
|
||||
std::remove_if(voices_.begin(), voices_.end(), [](const Voice& v) { return v.is_3d; }),
|
||||
voices_.end());
|
||||
break;
|
||||
case AudioCommand::SetSoundVolume3D:
|
||||
for (auto& v : voices_) {
|
||||
if (v.is_3d && v.handle == cmd.id) {
|
||||
v.volume = sound_volume_ * std::clamp(cmd.volume, 0.0f, 1.0f);
|
||||
v.target_volume = v.volume;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AudioCommand::PlayMusic:
|
||||
case AudioCommand::FadeInMusic: {
|
||||
std::vector<std::uint8_t> bytes;
|
||||
if (cmd.filename.empty() || !read_live_pack_texture(cmd.filename, bytes)) break;
|
||||
if (pending_music_.valid()) superseded_music_.push_back(std::move(pending_music_));
|
||||
// The pack is read here (CEterPackManager is not thread-safe); only the decode runs off-thread.
|
||||
pending_music_ = std::async(std::launch::async, [bytes = std::move(bytes), name = cmd.filename]() -> Clip {
|
||||
auto clip = std::make_shared<std::vector<float>>();
|
||||
if (!decode_audio(bytes.data(), bytes.size(), *clip))
|
||||
SDL_Log("audio: cannot decode %s (%zu bytes)", name.c_str(), bytes.size());
|
||||
return clip;
|
||||
});
|
||||
pending_music_file_ = cmd.filename;
|
||||
pending_music_fade_in_ = cmd.type == AudioCommand::FadeInMusic;
|
||||
pending_music_volume_ = cmd.volume;
|
||||
break;
|
||||
}
|
||||
case AudioCommand::FadeOutMusic:
|
||||
case AudioCommand::FadeOutAllMusic:
|
||||
pending_music_file_.clear(); // a track still decoding is dropped when it finishes
|
||||
if (bgm_.samples) {
|
||||
bgm_.target_volume = 0.0f;
|
||||
bgm_.fade_step_per_frame = -std::max(bgm_.volume, 0.01f) / (44100.0f * 1.0f);
|
||||
bgm_.stop_after_fade = true;
|
||||
}
|
||||
break;
|
||||
case AudioCommand::FadeLimitOutMusic:
|
||||
if (bgm_.samples) {
|
||||
bgm_.target_volume = music_volume_ * std::clamp(cmd.volume, 0.0f, 1.0f);
|
||||
bgm_.fade_step_per_frame = (bgm_.target_volume - bgm_.volume) / (44100.0f * 1.0f);
|
||||
bgm_.stop_after_fade = false;
|
||||
}
|
||||
break;
|
||||
case AudioCommand::SetMusicVolume:
|
||||
music_volume_ = std::clamp(cmd.volume, 0.0f, 1.0f);
|
||||
if (bgm_.samples && !bgm_.stop_after_fade) {
|
||||
bgm_.volume = music_volume_;
|
||||
bgm_.target_volume = music_volume_;
|
||||
}
|
||||
break;
|
||||
case AudioCommand::SetSoundVolume:
|
||||
sound_volume_ = std::clamp(cmd.volume, 0.0f, 1.0f);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pending_music_.valid() &&
|
||||
pending_music_.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
|
||||
Clip clip = pending_music_.get();
|
||||
if (!pending_music_file_.empty() && clip && !clip->empty())
|
||||
start_music(std::move(clip), pending_music_file_, pending_music_fade_in_, pending_music_volume_);
|
||||
pending_music_file_.clear();
|
||||
}
|
||||
superseded_music_.erase(
|
||||
std::remove_if(superseded_music_.begin(), superseded_music_.end(), [](const std::future<Clip>& f) {
|
||||
return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
|
||||
}),
|
||||
superseded_music_.end());
|
||||
|
||||
if (!stream_) return;
|
||||
const int queued_bytes = SDL_GetAudioStreamAvailable(stream_);
|
||||
if (queued_bytes < 0) return;
|
||||
const std::size_t queued_frames = static_cast<std::size_t>(queued_bytes) / (2 * sizeof(float));
|
||||
constexpr std::size_t kTargetQueuedFrames = 4410; // ~100 ms stereo @ 44.1 kHz
|
||||
const std::size_t queued_frames = static_cast<std::size_t>(queued_bytes) / (kMixChannels * sizeof(float));
|
||||
constexpr std::size_t kTargetQueuedFrames = kMixRate / 10; // ~100 ms
|
||||
if (queued_frames >= kTargetQueuedFrames) return;
|
||||
const std::size_t frames_to_mix = kTargetQueuedFrames - queued_frames;
|
||||
mix_buffer_.assign(frames_to_mix * 2, 0.0f);
|
||||
|
||||
auto mix_voice = [&](Voice& v) -> bool {
|
||||
if (!v.samples || v.samples->empty()) return false;
|
||||
const std::size_t total_frames = v.samples->size() / 2;
|
||||
if (total_frames == 0) return false;
|
||||
const float* src = v.samples->data();
|
||||
for (std::size_t f = 0; f < frames_to_mix; ++f) {
|
||||
if (v.frame_cursor >= total_frames) {
|
||||
if (v.loop) v.frame_cursor = 0;
|
||||
else return false;
|
||||
}
|
||||
if (v.fade_step_per_frame != 0.0f) {
|
||||
v.volume += v.fade_step_per_frame;
|
||||
if ((v.fade_step_per_frame > 0.0f && v.volume >= v.target_volume) ||
|
||||
(v.fade_step_per_frame < 0.0f && v.volume <= v.target_volume)) {
|
||||
v.volume = v.target_volume;
|
||||
v.fade_step_per_frame = 0.0f;
|
||||
if (v.stop_after_fade && v.volume <= 0.0001f) {
|
||||
v.samples = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
mix_buffer_[f * 2 + 0] += src[v.frame_cursor * 2 + 0] * v.volume;
|
||||
mix_buffer_[f * 2 + 1] += src[v.frame_cursor * 2 + 1] * v.volume;
|
||||
++v.frame_cursor;
|
||||
}
|
||||
return v.loop || v.frame_cursor < total_frames;
|
||||
};
|
||||
|
||||
if (bgm_.samples) {
|
||||
if (!mix_voice(bgm_)) {
|
||||
bgm_.samples = nullptr;
|
||||
bgm_clip_.reset();
|
||||
}
|
||||
}
|
||||
for (auto it = voices_.begin(); it != voices_.end();) {
|
||||
if (!mix_voice(*it)) it = voices_.erase(it);
|
||||
else ++it;
|
||||
}
|
||||
for (float& sample : mix_buffer_)
|
||||
mix_buffer_.assign(frames_to_mix * kMixChannels, 0.0f);
|
||||
MtMilesMix(mix_buffer_.data(), frames_to_mix);
|
||||
for (float& sample : mix_buffer_) {
|
||||
if (trace_) trace_peak_ = std::max(trace_peak_, std::fabs(sample));
|
||||
sample = std::clamp(sample, -1.0f, 1.0f);
|
||||
SDL_PutAudioStreamData(stream_, mix_buffer_.data(), static_cast<int>(mix_buffer_.size() * sizeof(float)));
|
||||
}
|
||||
|
||||
void NativeAudioEngine::start_music(Clip clip, const std::string& filename, bool fade_in, float volume) {
|
||||
bgm_clip_ = std::move(clip);
|
||||
bgm_.samples = bgm_clip_.get();
|
||||
bgm_.frame_cursor = 0;
|
||||
bgm_.loop = true;
|
||||
bgm_.filename = filename;
|
||||
bgm_.stop_after_fade = false;
|
||||
const float target = music_volume_ * std::clamp(volume, 0.0f, 1.0f);
|
||||
bgm_.target_volume = target;
|
||||
if (fade_in) {
|
||||
bgm_.volume = 0.0f;
|
||||
bgm_.fade_step_per_frame = target / (44100.0f * 1.5f);
|
||||
} else {
|
||||
bgm_.volume = target;
|
||||
bgm_.fade_step_per_frame = 0.0f;
|
||||
}
|
||||
++played_music_;
|
||||
SDL_Log("audio: music %s (%.0f s)", filename.c_str(), double(bgm_clip_->size() / 2) / kMixRate);
|
||||
}
|
||||
|
||||
const std::vector<float>* NativeAudioEngine::get_clip(const std::string& vpath) {
|
||||
if (vpath.empty()) return nullptr;
|
||||
auto [it, inserted] = clips_.try_emplace(vpath);
|
||||
if (!inserted) return &it->second;
|
||||
std::vector<std::uint8_t> bytes;
|
||||
if (read_live_pack_texture(vpath, bytes) && !decode_audio(bytes.data(), bytes.size(), it->second))
|
||||
SDL_Log("audio: cannot decode %s (%zu bytes)", vpath.c_str(), bytes.size());
|
||||
return &it->second;
|
||||
if (trace_ && (trace_frames_ += frames_to_mix) >= std::size_t(kMixRate) * 2) {
|
||||
SDL_Log("audio: peak %.3f", trace_peak_);
|
||||
trace_peak_ = 0.0f;
|
||||
trace_frames_ = 0;
|
||||
}
|
||||
SDL_PutAudioStreamData(stream_, mix_buffer_.data(), static_cast<int>(mix_buffer_.size() * sizeof(float)));
|
||||
}
|
||||
|
||||
} // namespace mt_host
|
||||
|
||||
+8
-42
@@ -3,63 +3,29 @@
|
||||
#ifdef MT_NATIVE_HAS_LIVE_CLIENT
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace mt_host {
|
||||
|
||||
// Drains the MilesLib AudioCommand queue and mixes 2D/3D sounds and BGM into an SDL audio stream.
|
||||
// The audio device behind the MilesLib port: installs the .wav/.mp3 decoder of the Miles emulation
|
||||
// (platform/MilesLib/MilesMixer.h) and feeds its mix into an SDL audio stream. Constructed before
|
||||
// CSoundManager::Create, which opens the Miles driver only when a decoder is installed.
|
||||
class NativeAudioEngine {
|
||||
struct Voice {
|
||||
const std::vector<float>* samples = nullptr;
|
||||
std::size_t frame_cursor = 0;
|
||||
float volume = 1.0f;
|
||||
float target_volume = 1.0f;
|
||||
float fade_step_per_frame = 0.0f;
|
||||
bool stop_after_fade = false;
|
||||
bool loop = false;
|
||||
bool is_3d = false;
|
||||
int handle = 0;
|
||||
std::string filename;
|
||||
};
|
||||
|
||||
public:
|
||||
NativeAudioEngine();
|
||||
|
||||
~NativeAudioEngine();
|
||||
|
||||
// Tops the device queue up to ~100 ms with MtMilesMix.
|
||||
void pump();
|
||||
|
||||
private:
|
||||
using Clip = std::shared_ptr<const std::vector<float>>;
|
||||
|
||||
const std::vector<float>* get_clip(const std::string& vpath);
|
||||
void start_music(Clip clip, const std::string& filename, bool fade_in, float volume);
|
||||
|
||||
SDL_AudioStream* stream_ = nullptr;
|
||||
std::unordered_map<std::string, std::vector<float>> clips_;
|
||||
std::vector<Voice> voices_;
|
||||
Voice bgm_{};
|
||||
// BGM is not cached in clips_ (a 5-minute track is ~100 MB of float): only the playing track is kept, and
|
||||
// a new one decodes on a worker thread while the old one keeps playing.
|
||||
Clip bgm_clip_;
|
||||
std::future<Clip> pending_music_;
|
||||
std::vector<std::future<Clip>> superseded_music_; // a std::async future blocks in its destructor
|
||||
std::string pending_music_file_;
|
||||
bool pending_music_fade_in_ = false;
|
||||
float pending_music_volume_ = 1.0f;
|
||||
std::vector<float> mix_buffer_;
|
||||
float sound_volume_ = 0.8f;
|
||||
float music_volume_ = 0.5f;
|
||||
std::size_t commands_drained_ = 0;
|
||||
std::size_t played_2d_ = 0;
|
||||
std::size_t played_3d_ = 0;
|
||||
std::size_t played_music_ = 0;
|
||||
// MT_AUDIO_TRACE=1: logs the peak level of the mix every 2 s.
|
||||
bool trace_ = false;
|
||||
float trace_peak_ = 0.0f;
|
||||
std::size_t trace_frames_ = 0;
|
||||
};
|
||||
|
||||
} // namespace mt_host
|
||||
|
||||
@@ -252,6 +252,8 @@ bool VulkanWindow::poll(bool forward_to_live_client) {
|
||||
}
|
||||
#ifdef MT_NATIVE_HAS_LIVE_CLIENT
|
||||
if (forward_to_live_client) {
|
||||
if (event.type == SDL_EVENT_WINDOW_FOCUS_GAINED || event.type == SDL_EVENT_WINDOW_FOCUS_LOST)
|
||||
PythonBoot::UIActivate(event.type == SDL_EVENT_WINDOW_FOCUS_GAINED);
|
||||
if (!hardware_cursor_enabled_ &&
|
||||
(event.type == SDL_EVENT_WINDOW_MOUSE_ENTER || event.type == SDL_EVENT_WINDOW_FOCUS_GAINED)) {
|
||||
std::printf(">>> SDL MOUSE ENTER/FOCUS GAINED\n");
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "AudioCommands.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace
|
||||
{
|
||||
std::mutex g_audio_mutex;
|
||||
std::vector<AudioCommand> g_audio_commands;
|
||||
}
|
||||
|
||||
void PushAudioCommand(const AudioCommand& cmd)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_audio_mutex);
|
||||
g_audio_commands.push_back(cmd);
|
||||
}
|
||||
|
||||
std::vector<AudioCommand> DrainAudioCommands()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_audio_mutex);
|
||||
std::vector<AudioCommand> out;
|
||||
out.swap(g_audio_commands);
|
||||
return out;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct AudioCommand
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
PlaySound2D = 1,
|
||||
PlaySound3D = 2,
|
||||
StopSound3D = 3,
|
||||
StopAllSound3D = 4,
|
||||
PlayMusic = 5,
|
||||
FadeOutMusic = 6,
|
||||
FadeOutAllMusic = 7,
|
||||
SetSoundVolume = 8,
|
||||
SetMusicVolume = 9,
|
||||
FadeInMusic = 10,
|
||||
FadeLimitOutMusic = 11,
|
||||
SetSoundVolume3D = 12,
|
||||
};
|
||||
|
||||
Type type = PlaySound2D;
|
||||
std::string filename;
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
float volume = 1.0f;
|
||||
float speed = 0.0f;
|
||||
int play_count = 1;
|
||||
int id = 0;
|
||||
};
|
||||
|
||||
void PushAudioCommand(const AudioCommand& cmd);
|
||||
std::vector<AudioCommand> DrainAudioCommands();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
// Host side of the Miles emulation (MilesAil.cpp). The AIL_* calls MilesLib makes keep sample, 3D sample
|
||||
// and stream voices; the host decodes files and pulls the mixed output.
|
||||
//
|
||||
// Output format: interleaved stereo float at MT_MILES_MIX_RATE.
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
constexpr int MT_MILES_MIX_RATE = 44100;
|
||||
|
||||
// Decodes a whole .wav/.mp3 file image into interleaved stereo float at MT_MILES_MIX_RATE. Called on the
|
||||
// script thread for samples and on a worker thread for streams, so it must be thread-safe.
|
||||
typedef bool (*MtMilesDecoder)(const void* data, std::size_t size, std::vector<float>& out);
|
||||
void MtMilesSetDecoder(MtMilesDecoder decoder);
|
||||
|
||||
// Adds `frames` frames of every playing voice into `out` (2 * frames floats, not cleared or clamped) and
|
||||
// advances them; a voice that runs out of loops becomes SMP_DONE.
|
||||
void MtMilesMix(float* out, std::size_t frames);
|
||||
@@ -1,50 +1,70 @@
|
||||
// Platform skeleton for MilesLib/SoundBase.h (40250 MilesLib/SoundBase.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundBase.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
HDIGDRIVER CSoundBase::ms_DIGDriver = NULL;
|
||||
TSoundDataMap CSoundBase::ms_dataMap;
|
||||
TProvider * CSoundBase::ms_pProviderDefault = NULL;
|
||||
std::vector<TProvider> CSoundBase::ms_ProviderVector;
|
||||
bool CSoundBase::ms_bInitialized = false;
|
||||
int CSoundBase::ms_iRefCount = 0;
|
||||
|
||||
CSoundBase::CSoundBase()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundBase::~CSoundBase()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundBase::Initialize() -> void
|
||||
void CSoundBase::Destroy()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
if (ms_iRefCount > 1)
|
||||
{
|
||||
--ms_iRefCount;
|
||||
return;
|
||||
}
|
||||
|
||||
ms_iRefCount = 0;
|
||||
|
||||
if (!ms_dataMap.empty())
|
||||
{
|
||||
TSoundDataMap::iterator i;
|
||||
for (i = ms_dataMap.begin(); i != ms_dataMap.end(); ++i)
|
||||
{
|
||||
CSoundData * pSoundData = i->second;
|
||||
delete pSoundData;
|
||||
}
|
||||
|
||||
ms_dataMap.clear();
|
||||
}
|
||||
|
||||
AIL_shutdown();
|
||||
}
|
||||
|
||||
auto CSoundBase::Destroy() -> void
|
||||
void CSoundBase::Initialize()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
++ms_iRefCount;
|
||||
|
||||
if (ms_iRefCount > 1)
|
||||
return;
|
||||
|
||||
AIL_set_redist_directory("miles");
|
||||
AIL_startup();
|
||||
|
||||
ms_ProviderVector.clear();
|
||||
ms_dataMap.clear();
|
||||
|
||||
}
|
||||
|
||||
auto CSoundBase::AddFile(DWORD, const char *) -> CSoundData *
|
||||
DWORD CSoundBase::GetFileCRC(const char * filename)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<CSoundData *>();
|
||||
return GetCRC32(filename, strlen(filename));
|
||||
}
|
||||
|
||||
auto CSoundBase::GetFileCRC(const char *) -> DWORD
|
||||
CSoundData * CSoundBase::AddFile(DWORD dwFileCRC, const char* filename)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<DWORD>();
|
||||
CSoundData * pSoundData = new CSoundData;
|
||||
pSoundData->Assign(filename);
|
||||
ms_dataMap.insert(TSoundDataMap::value_type(dwFileCRC, pSoundData));
|
||||
return pSoundData;
|
||||
}
|
||||
|
||||
decltype(CSoundBase::ms_iRefCount) CSoundBase::ms_iRefCount{};
|
||||
|
||||
decltype(CSoundBase::ms_DIGDriver) CSoundBase::ms_DIGDriver{};
|
||||
|
||||
decltype(CSoundBase::ms_pProviderDefault) CSoundBase::ms_pProviderDefault{};
|
||||
|
||||
decltype(CSoundBase::ms_ProviderVector) CSoundBase::ms_ProviderVector{};
|
||||
|
||||
decltype(CSoundBase::ms_dataMap) CSoundBase::ms_dataMap{};
|
||||
|
||||
decltype(CSoundBase::ms_bInitialized) CSoundBase::ms_bInitialized{};
|
||||
|
||||
+198
-103
@@ -1,116 +1,211 @@
|
||||
// Platform skeleton for MilesLib/SoundData.h (40250 MilesLib/SoundData.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundData.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "EterBase/Timer.h"
|
||||
|
||||
auto CSoundData::SetPackMode() -> void
|
||||
bool CSoundData::ms_isSoundFile[SOUND_FILE_MAX_NUM];
|
||||
CMappedFile CSoundData::ms_SoundFile[SOUND_FILE_MAX_NUM];
|
||||
|
||||
const char * CSoundData::GetFileName()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
CSoundData::CSoundData()
|
||||
void CSoundData::Assign(const char* filename)
|
||||
{
|
||||
assert(m_assigned == false);
|
||||
|
||||
strncpy(m_filename, filename, sizeof(m_filename)-1);
|
||||
m_assigned = true;
|
||||
}
|
||||
|
||||
LPVOID CSoundData::Get()
|
||||
{
|
||||
++m_iRefCount;
|
||||
m_dwAccessTime = ELTimer_GetMSec();
|
||||
|
||||
if (!m_data)
|
||||
ReadFromDisk();
|
||||
|
||||
if (m_flag & FLAG_DATA_SIZE)
|
||||
return ((S32 *) m_data + 1);
|
||||
else
|
||||
return (m_data);
|
||||
}
|
||||
|
||||
ULONG CSoundData::GetSize()
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
void CSoundData::Release()
|
||||
{
|
||||
assert(m_iRefCount != 0);
|
||||
--m_iRefCount;
|
||||
m_dwAccessTime = ELTimer_GetMSec();
|
||||
}
|
||||
|
||||
DWORD CSoundData::GetPlayTime()
|
||||
{
|
||||
return m_dwPlayTime;
|
||||
}
|
||||
|
||||
void CSoundData::SetPlayTime(DWORD dwPlayTime)
|
||||
{
|
||||
m_dwPlayTime = dwPlayTime;
|
||||
}
|
||||
|
||||
DWORD CSoundData::GetAccessTime()
|
||||
{
|
||||
return m_dwAccessTime;
|
||||
}
|
||||
|
||||
bool CSoundData::ReadFromDisk()
|
||||
{
|
||||
assert(m_assigned == true);
|
||||
|
||||
// PORT: 40250 read QueryPerformanceCounter into an unused local here; dropped.
|
||||
|
||||
U32* s = (U32 *) AIL_file_read(m_filename, FILE_READ_WITH_SIZE);
|
||||
|
||||
if (s == NULL)
|
||||
return false;
|
||||
|
||||
S32 type = AIL_file_type(s + 1, s[0]);
|
||||
AILSOUNDINFO info;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case AILFILETYPE_PCM_WAV:
|
||||
{
|
||||
m_data = s;
|
||||
m_size = *((S32 *) s);
|
||||
m_flag |= FLAG_DATA_SIZE;
|
||||
}
|
||||
break;
|
||||
|
||||
case AILFILETYPE_ADPCM_WAV: // 3D 사운드는 decompress 해야 함.
|
||||
{
|
||||
AIL_WAV_info(s + 1, &info);
|
||||
AIL_decompress_ADPCM(&info, &m_data, &m_size);
|
||||
AIL_mem_free_lock(s);
|
||||
}
|
||||
break;
|
||||
|
||||
case AILFILETYPE_MPEG_L3_AUDIO:
|
||||
{
|
||||
AIL_decompress_ASI(s + 1, *((S32 *) s), m_filename, &m_data, &m_size, 0);
|
||||
AIL_mem_free_lock(s);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(!"Unknown File Type");
|
||||
AIL_mem_free_lock(s);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSoundData::isSlotIndex(DWORD dwIndex)
|
||||
{
|
||||
if (dwIndex >= SOUND_FILE_MAX_NUM)
|
||||
return false;
|
||||
|
||||
if (!ms_isSoundFile[dwIndex])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int CSoundData::GetEmptySlotIndex()
|
||||
{
|
||||
for (int i = 0; i < SOUND_FILE_MAX_NUM; ++i)
|
||||
{
|
||||
if (!ms_isSoundFile[i])
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
U32 AILCALLBACK CSoundData::open_callback(char const * filename, U32 *file_handle)
|
||||
{
|
||||
int iIndex = GetEmptySlotIndex();
|
||||
|
||||
if (-1 == iIndex)
|
||||
return 0;
|
||||
|
||||
LPCVOID pMap;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(ms_SoundFile[iIndex], filename, &pMap))
|
||||
return 0;
|
||||
|
||||
ms_isSoundFile[iIndex] = true;
|
||||
|
||||
*file_handle = iIndex;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void AILCALLBACK CSoundData::close_callback(U32 file_handle)
|
||||
{
|
||||
if (!isSlotIndex(file_handle))
|
||||
return;
|
||||
|
||||
ms_SoundFile[file_handle].Destroy();
|
||||
ms_isSoundFile[file_handle] = false;
|
||||
}
|
||||
|
||||
S32 AILCALLBACK CSoundData::seek_callback(U32 file_handle, S32 offset, U32 type)
|
||||
{
|
||||
if (!isSlotIndex(file_handle))
|
||||
return 0;
|
||||
|
||||
return ms_SoundFile[file_handle].Seek(offset, type);
|
||||
}
|
||||
|
||||
U32 AILCALLBACK CSoundData::read_callback(U32 file_handle, void * buffer, U32 bytes)
|
||||
{
|
||||
if (!isSlotIndex(file_handle))
|
||||
return 0;
|
||||
|
||||
DWORD dwRealSize = min(ms_SoundFile[file_handle].Size(), bytes);
|
||||
ms_SoundFile[file_handle].Read(buffer, dwRealSize);
|
||||
return dwRealSize;
|
||||
}
|
||||
|
||||
void CSoundData::SetPackMode()
|
||||
{
|
||||
// if sound data reads from pack file, the callbacks of the MSS should be changed.
|
||||
AIL_set_file_callbacks(open_callback, close_callback, seek_callback, read_callback);
|
||||
|
||||
for (int i = 0; i < SOUND_FILE_MAX_NUM; ++i)
|
||||
ms_isSoundFile[i] = false;
|
||||
}
|
||||
|
||||
void CSoundData::Destroy()
|
||||
{
|
||||
if (m_data)
|
||||
{
|
||||
AIL_mem_free_lock(m_data);
|
||||
m_data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CSoundData::CSoundData() :
|
||||
m_assigned(false),
|
||||
m_iRefCount(0),
|
||||
m_dwPlayTime(0),
|
||||
m_dwAccessTime(ELTimer_GetMSec()),
|
||||
m_size(0),
|
||||
m_data(NULL),
|
||||
m_flag(0)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundData::~CSoundData()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
auto CSoundData::Assign(const char *) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundData::Get() -> LPVOID
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<LPVOID>();
|
||||
}
|
||||
|
||||
auto CSoundData::GetSize() -> ULONG
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<ULONG>();
|
||||
}
|
||||
|
||||
auto CSoundData::Release() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundData::GetAccessTime() -> DWORD
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<DWORD>();
|
||||
}
|
||||
|
||||
auto CSoundData::GetFileName() -> const char *
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<const char *>();
|
||||
}
|
||||
|
||||
auto CSoundData::SetPlayTime(DWORD) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundData::GetPlayTime() -> DWORD
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<DWORD>();
|
||||
}
|
||||
|
||||
auto CSoundData::ReadFromDisk() -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundData::Destroy() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundData::open_callback(const char *, U32 *) -> U32
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<U32>();
|
||||
}
|
||||
|
||||
auto CSoundData::close_callback(U32) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundData::seek_callback(U32, S32, U32) -> S32
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<S32>();
|
||||
}
|
||||
|
||||
auto CSoundData::read_callback(U32, void *, U32) -> U32
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<U32>();
|
||||
}
|
||||
|
||||
auto CSoundData::isSlotIndex(DWORD) -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundData::GetEmptySlotIndex() -> int
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<int>();
|
||||
}
|
||||
|
||||
decltype(CSoundData::ms_isSoundFile) CSoundData::ms_isSoundFile{};
|
||||
|
||||
decltype(CSoundData::ms_SoundFile) CSoundData::ms_SoundFile{};
|
||||
|
||||
@@ -1,256 +0,0 @@
|
||||
// Platform skeleton for MilesLib/SoundInstance.h, generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundInstance.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
CSoundInstance2D::CSoundInstance2D()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundInstance2D::~CSoundInstance2D()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::Initialize() -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::Destroy() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::SetSound(CSoundData *) -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::Play(int, DWORD) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::Pause() const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::Resume() const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::Stop() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::GetVolume(float &) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::SetVolume(float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::IsDone() const -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::SetPosition(float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::SetOrientation(float, float, float, float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance2D::SetVelocity(float, float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundInstance3D::CSoundInstance3D()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundInstance3D::~CSoundInstance3D()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::Initialize() -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::Destroy() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::SetSound(CSoundData *) -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::Play(int, DWORD) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::Pause() const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::Resume() const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::Stop() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::GetVolume(float &) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::SetVolume(float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::IsDone() const -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::SetPosition(float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::SetOrientation(float, float, float, float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::SetVelocity(float, float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstance3D::UpdatePosition(float) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundInstanceStream::CSoundInstanceStream()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundInstanceStream::~CSoundInstanceStream()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::Initialize() -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::Destroy() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::SetStream(HSTREAM) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::SetSound(CSoundData *) -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::Play(int, DWORD) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::Pause() const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::Resume() const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::Stop() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::GetVolume(float &) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::SetVolume(float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::IsDone() const -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::IsData() const -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::SetPosition(float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::SetOrientation(float, float, float, float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundInstanceStream::SetVelocity(float, float, float, float) const -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundManager2D.h"
|
||||
|
||||
CSoundInstance2D::CSoundInstance2D() : m_sample(NULL), m_pSoundData(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CSoundInstance2D::~CSoundInstance2D()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void CSoundInstance2D::Destroy()
|
||||
{
|
||||
SAFE_RELEASE(m_pSoundData);
|
||||
|
||||
if (m_sample)
|
||||
{
|
||||
AIL_release_sample_handle(m_sample);
|
||||
m_sample = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool CSoundInstance2D::Initialize()
|
||||
{
|
||||
if (m_sample)
|
||||
return true;
|
||||
|
||||
m_sample = AIL_allocate_sample_handle(ms_DIGDriver);
|
||||
return m_sample ? true : false;
|
||||
}
|
||||
|
||||
bool CSoundInstance2D::SetSound(CSoundData * pSoundData)
|
||||
{
|
||||
assert(m_sample != NULL && pSoundData != NULL);
|
||||
|
||||
// 레퍼런스 카운트가 1이 될 때 로드를 해야 제대로 사이즈가 리턴
|
||||
// 되므로 반드시 Get을 호출 하고 진행해야 한다.
|
||||
// 또, m_pSoundData가 pSoundData와 같고 m_pSoundData의 레퍼런스
|
||||
// 카운터가 1일 경우, 불필요하게 로드가 일어나므로 미리 레퍼런스
|
||||
// 카운터를 올려놔야 한다.
|
||||
LPVOID lpData = pSoundData->Get();
|
||||
|
||||
AIL_init_sample(m_sample);
|
||||
|
||||
if (AIL_set_sample_file(m_sample, lpData, pSoundData->GetSize()) == NULL)
|
||||
{
|
||||
if (m_pSoundData != NULL)
|
||||
{
|
||||
m_pSoundData->Release();
|
||||
m_pSoundData = NULL;
|
||||
}
|
||||
|
||||
pSoundData->Release();
|
||||
TraceError("%s: %s", AIL_last_error(), pSoundData->GetFileName());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_pSoundData != NULL)
|
||||
{
|
||||
m_pSoundData->Release();
|
||||
m_pSoundData = NULL;
|
||||
}
|
||||
|
||||
m_pSoundData = pSoundData;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSoundInstance2D::IsDone() const
|
||||
{
|
||||
return AIL_sample_status(m_sample) == SMP_DONE;
|
||||
}
|
||||
|
||||
void CSoundInstance2D::Play(int iLoopCount, DWORD dwPlayCycleTimeLimit) const
|
||||
{
|
||||
AIL_set_sample_loop_count(m_sample, iLoopCount);
|
||||
AIL_start_sample(m_sample);
|
||||
}
|
||||
|
||||
void CSoundInstance2D::Pause() const
|
||||
{
|
||||
AIL_stop_sample(m_sample);
|
||||
}
|
||||
|
||||
void CSoundInstance2D::Resume() const
|
||||
{
|
||||
AIL_resume_sample(m_sample);
|
||||
}
|
||||
|
||||
void CSoundInstance2D::Stop()
|
||||
{
|
||||
AIL_end_sample(m_sample);
|
||||
m_sample = NULL;
|
||||
}
|
||||
|
||||
void CSoundInstance2D::GetVolume(float& rfVolume) const
|
||||
{
|
||||
AIL_sample_volume_pan(m_sample, &rfVolume, NULL);
|
||||
}
|
||||
|
||||
void CSoundInstance2D::SetVolume(float volume) const
|
||||
{
|
||||
volume = max(0.0f, min(1.0f, volume));
|
||||
AIL_set_sample_volume_pan(m_sample, volume, 0.5f);
|
||||
}
|
||||
|
||||
void CSoundInstance2D::SetPosition(float x, float y, float z) const
|
||||
{
|
||||
assert(!"must not call this method");
|
||||
}
|
||||
|
||||
void CSoundInstance2D::SetOrientation(float x_face, float y_face, float z_face,
|
||||
float x_normal, float y_normal, float z_normal) const
|
||||
{
|
||||
assert(!"must not call this method");
|
||||
}
|
||||
|
||||
void CSoundInstance2D::SetVelocity(float fx, float fy, float fz, float fMagnitude) const
|
||||
{
|
||||
assert(!"must not call this method");
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundManager3D.h"
|
||||
#include "EterBase/Timer.h"
|
||||
|
||||
CSoundInstance3D::CSoundInstance3D() : m_sample(NULL), m_pSoundData(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CSoundInstance3D::~CSoundInstance3D()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void CSoundInstance3D::Destroy()
|
||||
{
|
||||
SAFE_RELEASE(m_pSoundData);
|
||||
|
||||
if (m_sample)
|
||||
{
|
||||
AIL_release_3D_sample_handle(m_sample);
|
||||
m_sample = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool CSoundInstance3D::Initialize()
|
||||
{
|
||||
if (m_sample)
|
||||
return true;
|
||||
|
||||
m_sample = AIL_allocate_3D_sample_handle(ms_pProviderDefault->hProvider);
|
||||
return m_sample ? true : false;
|
||||
}
|
||||
|
||||
bool CSoundInstance3D::SetSound(CSoundData* pSoundData)
|
||||
{
|
||||
assert(m_sample != NULL && pSoundData != NULL);
|
||||
|
||||
// 레퍼런스 카운트가 1이 될 때 로드를 해야 제대로 사이즈가 리턴
|
||||
// 되므로 반드시 Get을 호출 하고 진행해야 한다.
|
||||
// 또, m_pSoundData가 pSoundData와 같고 m_pSoundData의 레퍼런스
|
||||
// 카운터가 1일 경우, 불필요하게 로드가 일어나므로 미리 레퍼런스
|
||||
// 카운터를 올려놔야 한다.
|
||||
LPVOID lpData = pSoundData->Get();
|
||||
|
||||
if (m_pSoundData != NULL)
|
||||
{
|
||||
m_pSoundData->Release();
|
||||
m_pSoundData = NULL;
|
||||
}
|
||||
|
||||
if (AIL_set_3D_sample_file(m_sample, lpData) == NULL)
|
||||
{
|
||||
TraceError("%s: %s", AIL_last_error(), pSoundData->GetFileName());
|
||||
pSoundData->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pSoundData = pSoundData;
|
||||
|
||||
AIL_set_3D_position(m_sample, 0.0F, 0.0F, 0.0F);
|
||||
AIL_auto_update_3D_position(m_sample, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSoundInstance3D::IsDone() const
|
||||
{
|
||||
return AIL_3D_sample_status(m_sample) == SMP_DONE;
|
||||
}
|
||||
|
||||
void CSoundInstance3D::Play(int iLoopCount, DWORD dwPlayCycleTimeLimit) const
|
||||
{
|
||||
if (!m_pSoundData)
|
||||
return;
|
||||
|
||||
DWORD dwCurTime = ELTimer_GetMSec();
|
||||
|
||||
if (dwCurTime - m_pSoundData->GetPlayTime() < dwPlayCycleTimeLimit)
|
||||
return;
|
||||
|
||||
m_pSoundData->SetPlayTime(dwCurTime);
|
||||
|
||||
AIL_set_3D_sample_loop_count(m_sample, iLoopCount);
|
||||
AIL_start_3D_sample(m_sample);
|
||||
}
|
||||
|
||||
void CSoundInstance3D::Pause() const
|
||||
{
|
||||
AIL_stop_3D_sample(m_sample);
|
||||
}
|
||||
|
||||
void CSoundInstance3D::Resume() const
|
||||
{
|
||||
AIL_resume_3D_sample(m_sample);
|
||||
}
|
||||
|
||||
void CSoundInstance3D::Stop()
|
||||
{
|
||||
AIL_end_3D_sample(m_sample);
|
||||
// m_sample = NULL;
|
||||
// NOTE : IsDone을 체크하려면 m_sample이 살아있어야 합니다 - [levites]
|
||||
}
|
||||
|
||||
void CSoundInstance3D::GetVolume(float& rfVolume) const
|
||||
{
|
||||
rfVolume = AIL_3D_sample_volume(m_sample);
|
||||
}
|
||||
|
||||
void CSoundInstance3D::SetVolume(float volume) const
|
||||
{
|
||||
volume = max(0.0f, min(1.0f, volume));
|
||||
AIL_set_3D_sample_volume(m_sample, volume);
|
||||
}
|
||||
|
||||
void CSoundInstance3D::SetPosition(float x, float y, float z) const
|
||||
{
|
||||
AIL_set_3D_position(m_sample, x, y, -z);
|
||||
}
|
||||
|
||||
void CSoundInstance3D::SetOrientation(float x_face, float y_face, float z_face,
|
||||
float x_normal, float y_normal, float z_normal) const
|
||||
{
|
||||
assert(!" CSoundInstance3D::SetOrientation - 사용 하지 않는 함수");
|
||||
// AIL_set_3D_orientation(m_sample,
|
||||
// x_face, y_face, z_face,
|
||||
// x_normal, y_normal, z_normal);
|
||||
}
|
||||
|
||||
void CSoundInstance3D::SetVelocity(float fDistanceX, float fDistanceY, float fDistanceZ, float fNagnitude) const
|
||||
{
|
||||
AIL_set_3D_velocity(m_sample, fDistanceX, fDistanceY, fDistanceZ, fNagnitude);
|
||||
AIL_auto_update_3D_position(m_sample, 1);
|
||||
}
|
||||
|
||||
void CSoundInstance3D::UpdatePosition(float fElapsedTime)
|
||||
{
|
||||
AIL_update_3D_position(m_sample, fElapsedTime);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundInstance.h"
|
||||
|
||||
CSoundInstanceStream::CSoundInstanceStream() : m_stream(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CSoundInstanceStream::~CSoundInstanceStream()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::Destroy()
|
||||
{
|
||||
if (m_stream != NULL)
|
||||
{
|
||||
AIL_close_stream(m_stream);
|
||||
m_stream = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool CSoundInstanceStream::Initialize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::SetStream(HSTREAM stream)
|
||||
{
|
||||
m_stream = stream;
|
||||
}
|
||||
|
||||
bool CSoundInstanceStream::IsDone() const
|
||||
{
|
||||
return AIL_stream_status(m_stream) == -1;
|
||||
}
|
||||
|
||||
bool CSoundInstanceStream::IsData() const
|
||||
{
|
||||
if (m_stream)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::Play(int count, DWORD dwPlayCycleTimeLimit) const
|
||||
{
|
||||
if (!IsData())
|
||||
return;
|
||||
|
||||
AIL_set_stream_loop_count(m_stream, count);
|
||||
AIL_start_stream(m_stream);
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::Pause() const
|
||||
{
|
||||
if (!IsData())
|
||||
return;
|
||||
|
||||
AIL_pause_stream(m_stream, 1);
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::Resume() const
|
||||
{
|
||||
if (!IsData())
|
||||
return;
|
||||
|
||||
AIL_pause_stream(m_stream, 0);
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::Stop()
|
||||
{
|
||||
if (!IsData())
|
||||
return;
|
||||
|
||||
AIL_close_stream(m_stream);
|
||||
m_stream = NULL;
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::GetVolume(float& rfVolume) const
|
||||
{
|
||||
float tmp;
|
||||
|
||||
if (!IsData())
|
||||
return;
|
||||
|
||||
AIL_stream_volume_levels(m_stream, &rfVolume, &tmp);
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::SetVolume(float volume) const
|
||||
{
|
||||
if (!IsData())
|
||||
return;
|
||||
|
||||
volume = max(0.0f, min(1.0f, volume));
|
||||
AIL_set_stream_volume_levels(m_stream, volume, volume);
|
||||
}
|
||||
|
||||
bool CSoundInstanceStream::SetSound(CSoundData* pSound)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::SetPosition(float x, float y, float z) const
|
||||
{
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::SetOrientation(float x_face, float y_face, float z_face,
|
||||
float x_normal, float y_normal, float z_normal) const
|
||||
{
|
||||
}
|
||||
|
||||
void CSoundInstanceStream::SetVelocity(float fx, float fy, float fz, float fMagnitude) const
|
||||
{
|
||||
}
|
||||
@@ -1,30 +1,29 @@
|
||||
// Platform implementation of MilesLib/SoundManager.h for port/headless execution.
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundManager.h"
|
||||
#include "AudioCommands.h"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
|
||||
decltype(CSoundManager::ms_SoundManager2D) CSoundManager::ms_SoundManager2D{};
|
||||
decltype(CSoundManager::ms_SoundManager3D) CSoundManager::ms_SoundManager3D{};
|
||||
decltype(CSoundManager::ms_SoundManagerStream) CSoundManager::ms_SoundManagerStream{};
|
||||
#include "MilesLib/SoundManager.h"
|
||||
#include "EterBase/Timer.h"
|
||||
|
||||
CSoundManager2D CSoundManager::ms_SoundManager2D;
|
||||
CSoundManager3D CSoundManager::ms_SoundManager3D;
|
||||
CSoundManagerStream CSoundManager::ms_SoundManagerStream;
|
||||
|
||||
CSoundManager::CSoundManager()
|
||||
{
|
||||
m_bInitialized = FALSE;
|
||||
m_isSoundDisable = FALSE;
|
||||
m_bInitialized = FALSE;
|
||||
m_isSoundDisable = FALSE;
|
||||
|
||||
m_fxPosition = 0.0f;
|
||||
m_fyPosition = 0.0f;
|
||||
m_fzPosition = 0.0f;
|
||||
m_fxPosition = 0.0f;
|
||||
m_fyPosition = 0.0f;
|
||||
m_fzPosition = 0.0f;
|
||||
|
||||
m_fSoundScale = 200.0f;
|
||||
m_fAmbienceSoundScale = 1000.0f;
|
||||
m_fSoundVolume = 1.0f;
|
||||
m_fMusicVolume = 1.0f;
|
||||
m_fSoundScale = 200.0f;
|
||||
m_fAmbienceSoundScale = 1000.0f;
|
||||
m_fSoundVolume = 1.0f;
|
||||
m_fMusicVolume = 1.0f;
|
||||
|
||||
m_fBackupMusicVolume = 0.0f;
|
||||
m_fBackupSoundVolume = 0.0f;
|
||||
m_fBackupMusicVolume = 0.0f;
|
||||
m_fBackupSoundVolume = 0.0f;
|
||||
|
||||
for (int i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i)
|
||||
{
|
||||
@@ -32,7 +31,6 @@ CSoundManager::CSoundManager()
|
||||
rInstance.dwMusicFileNameCRC = 0;
|
||||
rInstance.MusicState = MUSIC_STATE_OFF;
|
||||
rInstance.fVolume = 0.0f;
|
||||
rInstance.fLimitVolume = 0.0f;
|
||||
rInstance.fVolumeSpeed = 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -43,14 +41,32 @@ CSoundManager::~CSoundManager()
|
||||
|
||||
BOOL CSoundManager::Create()
|
||||
{
|
||||
m_bInitialized = TRUE;
|
||||
if (!ms_SoundManager2D.Initialize()) {
|
||||
Tracen("CSoundManager::Create - Sound2D::Initialize - FAILURE");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!ms_SoundManagerStream.Initialize())
|
||||
{
|
||||
Tracen("CSoundManager::Create - SoundStream::Initialize - FAILURE");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!ms_SoundManager3D.Initialize())
|
||||
{
|
||||
Tracen("CSoundManager::Create - Sound3D::Initialize - FAILURE");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CSoundManager::Destroy()
|
||||
{
|
||||
m_PlaySoundHistoryMap.clear();
|
||||
m_bInitialized = FALSE;
|
||||
ms_SoundManagerStream.Destroy();
|
||||
ms_SoundManager3D.Destroy();
|
||||
ms_SoundManager2D.Destroy();
|
||||
m_PlaySoundHistoryMap.clear(); // Fix
|
||||
}
|
||||
|
||||
void CSoundManager::SetPosition(float fx, float fy, float fz)
|
||||
@@ -60,12 +76,109 @@ void CSoundManager::SetPosition(float fx, float fy, float fz)
|
||||
m_fzPosition = fz;
|
||||
}
|
||||
|
||||
void CSoundManager::SetDirection(float, float, float, float, float, float)
|
||||
void CSoundManager::SetDirection(float fxDir, float fyDir, float fzDir, float fxUp, float fyUp, float fzUp)
|
||||
{
|
||||
ms_SoundManager3D.SetListenerDirection(fxDir, fyDir, fzDir, fxUp, fyUp, fzUp);
|
||||
}
|
||||
|
||||
void CSoundManager::Update()
|
||||
{
|
||||
// Update Information about 3D Sound
|
||||
ms_SoundManager3D.SetListenerPosition(0.0f, 0.0f, 0.0f);
|
||||
|
||||
for (int i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i)
|
||||
{
|
||||
TMusicInstance & rMusicInstance = m_MusicInstances[i];
|
||||
if (MUSIC_STATE_OFF == rMusicInstance.MusicState)
|
||||
continue;
|
||||
|
||||
switch (rMusicInstance.MusicState)
|
||||
{
|
||||
case MUSIC_STATE_FADE_IN:
|
||||
rMusicInstance.fVolume += rMusicInstance.fVolumeSpeed;
|
||||
|
||||
if (rMusicInstance.fVolume >= GetMusicVolume())
|
||||
{
|
||||
rMusicInstance.fVolume = GetMusicVolume();
|
||||
rMusicInstance.fVolumeSpeed = 0.0f;
|
||||
rMusicInstance.MusicState = MUSIC_STATE_PLAY;
|
||||
}
|
||||
|
||||
{
|
||||
CSoundInstanceStream * pInstance = ms_SoundManagerStream.GetInstance(i);
|
||||
if (pInstance)
|
||||
pInstance->SetVolume(rMusicInstance.fVolume);
|
||||
}
|
||||
break;
|
||||
|
||||
case MUSIC_STATE_FADE_LIMIT_OUT:
|
||||
rMusicInstance.fVolume -= rMusicInstance.fVolumeSpeed;
|
||||
if (rMusicInstance.fVolume <= rMusicInstance.fLimitVolume)
|
||||
{
|
||||
rMusicInstance.fVolume = rMusicInstance.fLimitVolume;
|
||||
rMusicInstance.fVolumeSpeed = 0.0f;
|
||||
rMusicInstance.MusicState = MUSIC_STATE_PLAY;
|
||||
}
|
||||
{
|
||||
CSoundInstanceStream * pInstance = ms_SoundManagerStream.GetInstance(i);
|
||||
if (pInstance)
|
||||
pInstance->SetVolume(rMusicInstance.fVolume);
|
||||
}
|
||||
break;
|
||||
case MUSIC_STATE_FADE_OUT:
|
||||
rMusicInstance.fVolume -= rMusicInstance.fVolumeSpeed;
|
||||
if (rMusicInstance.fVolume <= 0.0f)
|
||||
{
|
||||
rMusicInstance.fVolume = 0.0f;
|
||||
rMusicInstance.fVolumeSpeed = 0.0f;
|
||||
rMusicInstance.MusicState = MUSIC_STATE_OFF;
|
||||
|
||||
StopMusic(i);
|
||||
}
|
||||
{
|
||||
CSoundInstanceStream * pInstance = ms_SoundManagerStream.GetInstance(i);
|
||||
if (pInstance)
|
||||
pInstance->SetVolume(rMusicInstance.fVolume);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSoundManager::UpdateSoundData(DWORD dwcurTime, const NSound::TSoundDataVector * c_pSoundDataVector)
|
||||
{
|
||||
assert(!"CSoundManager::UpdateSoundData");
|
||||
}
|
||||
|
||||
void CSoundManager::UpdateSoundData(float fx, float fy, float fz, DWORD dwcurTime, const NSound::TSoundDataVector * c_pSoundDataVector)
|
||||
{
|
||||
assert(!"CSoundManager::UpdateSoundData");
|
||||
}
|
||||
|
||||
void CSoundManager::UpdateSoundInstance(float fx, float fy, float fz, DWORD dwcurFrame, const NSound::TSoundInstanceVector * c_pSoundInstanceVector, BOOL bCheckFrequency)
|
||||
{
|
||||
for (DWORD i = 0; i < c_pSoundInstanceVector->size(); ++i)
|
||||
{
|
||||
const NSound::TSoundInstance & c_rSoundInstance = c_pSoundInstanceVector->at(i);
|
||||
if (c_rSoundInstance.dwFrame == dwcurFrame)
|
||||
{
|
||||
//Tracenf("PLAY SOUND %s", c_rSoundInstance.strSoundFileName.c_str());
|
||||
PlayCharacterSound3D(fx, fy, fz, c_rSoundInstance.strSoundFileName.c_str(), bCheckFrequency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSoundManager::UpdateSoundInstance(DWORD dwcurFrame, const NSound::TSoundInstanceVector * c_pSoundInstanceVector)
|
||||
{
|
||||
for (DWORD i = 0; i < c_pSoundInstanceVector->size(); ++i)
|
||||
{
|
||||
const NSound::TSoundInstance & c_rSoundInstance = c_pSoundInstanceVector->at(i);
|
||||
|
||||
if (c_rSoundInstance.dwFrame == dwcurFrame)
|
||||
{
|
||||
PlaySound2D(c_rSoundInstance.strSoundFileName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float CSoundManager::GetSoundScale()
|
||||
@@ -83,19 +196,6 @@ void CSoundManager::SetAmbienceSoundScale(float fScale)
|
||||
m_fAmbienceSoundScale = fScale;
|
||||
}
|
||||
|
||||
float CSoundManager::__ConvertRatioVolumeToApplyVolume(float fRatioVolume)
|
||||
{
|
||||
if (0.1f > fRatioVolume)
|
||||
return fRatioVolume;
|
||||
|
||||
return (float)pow(10.0f, (-1.0f + fRatioVolume));
|
||||
}
|
||||
|
||||
float CSoundManager::__ConvertGradeVolumeToApplyVolume(int nGradeVolume)
|
||||
{
|
||||
return __ConvertRatioVolumeToApplyVolume(nGradeVolume / 5.0f);
|
||||
}
|
||||
|
||||
void CSoundManager::SetSoundVolume(float fVolume)
|
||||
{
|
||||
if (m_isSoundDisable)
|
||||
@@ -104,30 +204,14 @@ void CSoundManager::SetSoundVolume(float fVolume)
|
||||
return;
|
||||
}
|
||||
|
||||
if (fVolume < 0.0f) fVolume = 0.0f;
|
||||
if (fVolume > 1.0f) fVolume = 1.0f;
|
||||
fVolume = fMAX(fVolume, 0.0f);
|
||||
fVolume = fMIN(fVolume, 1.0f);
|
||||
m_fSoundVolume = fVolume;
|
||||
|
||||
if (!m_isSoundDisable)
|
||||
{
|
||||
m_fBackupSoundVolume = fVolume;
|
||||
}
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::SetSoundVolume;
|
||||
cmd.volume = m_fSoundVolume;
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
|
||||
void CSoundManager::SetSoundVolumeRatio(float fRatio)
|
||||
{
|
||||
float fVolume = __ConvertRatioVolumeToApplyVolume(fRatio);
|
||||
SetSoundVolume(fVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::SetSoundVolumeGrade(int iGrade)
|
||||
{
|
||||
float fVolume = __ConvertGradeVolumeToApplyVolume(iGrade);
|
||||
SetSoundVolume(fVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::__SetMusicVolume(float fVolume)
|
||||
@@ -138,57 +222,69 @@ void CSoundManager::__SetMusicVolume(float fVolume)
|
||||
return;
|
||||
}
|
||||
|
||||
if (fVolume < 0.0f) fVolume = 0.0f;
|
||||
if (fVolume > 1.0f) fVolume = 1.0f;
|
||||
fVolume = fMAX(fVolume, 0.0f);
|
||||
fVolume = fMIN(fVolume, 1.0f);
|
||||
m_fMusicVolume = fVolume;
|
||||
|
||||
if (!m_isSoundDisable)
|
||||
{
|
||||
m_fBackupMusicVolume = fVolume;
|
||||
}
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::SetMusicVolume;
|
||||
cmd.volume = m_fMusicVolume;
|
||||
PushAudioCommand(cmd);
|
||||
|
||||
for (int i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i)
|
||||
{
|
||||
TMusicInstance & rMusicInstance = m_MusicInstances[i];
|
||||
if (MUSIC_STATE_OFF == rMusicInstance.MusicState)
|
||||
continue;
|
||||
if (MUSIC_STATE_FADE_OUT == rMusicInstance.MusicState)
|
||||
continue;
|
||||
|
||||
rMusicInstance.fVolume = fVolume;
|
||||
|
||||
CSoundInstanceStream * pInstance = ms_SoundManagerStream.GetInstance(i);
|
||||
if (pInstance)
|
||||
pInstance->SetVolume(fVolume);
|
||||
}
|
||||
}
|
||||
|
||||
float CSoundManager::__ConvertRatioVolumeToApplyVolume(float fRatioVolume)
|
||||
{
|
||||
if (0.1f>fRatioVolume)
|
||||
return fRatioVolume;
|
||||
|
||||
return (float)pow(10.0f, (-1.0f + fRatioVolume));
|
||||
}
|
||||
|
||||
float CSoundManager::__ConvertGradeVolumeToApplyVolume(int nGradeVolume)
|
||||
{
|
||||
return __ConvertRatioVolumeToApplyVolume(nGradeVolume/5.0f);
|
||||
}
|
||||
|
||||
|
||||
void CSoundManager::SetSoundVolumeGrade(int iGrade)
|
||||
{
|
||||
float fVolume=__ConvertGradeVolumeToApplyVolume(iGrade);
|
||||
SetSoundVolume(fVolume);
|
||||
}
|
||||
|
||||
//void CSoundManager::SetMusicVolumeGrade(int iGrade)
|
||||
//{
|
||||
// float fVolume=__ConvertGradeVolumeToApplyVolume(iGrade);
|
||||
// __SetMusicVolume(fVolume);
|
||||
//}
|
||||
|
||||
void CSoundManager::SetSoundVolumeRatio(float fRatio)
|
||||
{
|
||||
float fVolume = __ConvertRatioVolumeToApplyVolume(fRatio);
|
||||
SetSoundVolume(fVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::SetMusicVolume(float fVolume)
|
||||
{
|
||||
{
|
||||
//float fVolume = __ConvertRatioVolumeToApplyVolume(fRatio);
|
||||
__SetMusicVolume(fVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::SetMusicVolumeRatio(float fRatio)
|
||||
{
|
||||
float fVolume = __ConvertRatioVolumeToApplyVolume(fRatio);
|
||||
SetMusicVolume(fVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::SetMusicVolumeGrade(int iGrade)
|
||||
{
|
||||
float fVolume = __ConvertGradeVolumeToApplyVolume(iGrade);
|
||||
SetMusicVolume(fVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::SaveVolume()
|
||||
{
|
||||
if (m_isSoundDisable)
|
||||
return;
|
||||
const float musicVolume = m_fMusicVolume;
|
||||
const float soundVolume = m_fSoundVolume;
|
||||
SetMusicVolume(0.0f);
|
||||
SetSoundVolume(0.0f);
|
||||
m_fBackupMusicVolume = musicVolume;
|
||||
m_fBackupSoundVolume = soundVolume;
|
||||
m_isSoundDisable = TRUE;
|
||||
}
|
||||
|
||||
void CSoundManager::RestoreVolume()
|
||||
{
|
||||
m_isSoundDisable = FALSE;
|
||||
SetMusicVolume(m_fBackupMusicVolume);
|
||||
SetSoundVolume(m_fBackupSoundVolume);
|
||||
}
|
||||
|
||||
float CSoundManager::GetSoundVolume()
|
||||
{
|
||||
return m_fSoundVolume;
|
||||
@@ -199,170 +295,352 @@ float CSoundManager::GetMusicVolume()
|
||||
return m_fMusicVolume;
|
||||
}
|
||||
|
||||
BOOL CSoundManager::GetSoundInstance2D(const char * c_szSoundFileName, ISoundInstance ** ppInstance)
|
||||
{
|
||||
*ppInstance = ms_SoundManager2D.GetInstance(c_szSoundFileName);
|
||||
|
||||
if (!*ppInstance)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CSoundManager::GetSoundInstance3D(const char * c_szFileName, ISoundInstance ** ppInstance)
|
||||
{
|
||||
int iIndex = ms_SoundManager3D.SetInstance(c_szFileName);
|
||||
|
||||
if (-1 == iIndex)
|
||||
return FALSE;
|
||||
|
||||
*ppInstance = ms_SoundManager3D.GetInstance(iIndex);
|
||||
|
||||
if (!*ppInstance)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CSoundManager::PlaySound2D(const char * c_szFileName)
|
||||
{
|
||||
if (m_isSoundDisable || !c_szFileName || !c_szFileName[0])
|
||||
if (0.0f == GetSoundVolume())
|
||||
return;
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::PlaySound2D;
|
||||
cmd.filename = c_szFileName;
|
||||
cmd.volume = m_fSoundVolume;
|
||||
PushAudioCommand(cmd);
|
||||
|
||||
ISoundInstance * pInstance;
|
||||
if (!GetSoundInstance2D(c_szFileName, &pInstance))
|
||||
return;
|
||||
|
||||
pInstance->SetVolume(GetSoundVolume());
|
||||
pInstance->Play(1);
|
||||
}
|
||||
|
||||
void CSoundManager::PlaySound3D(float fx, float fy, float fz, const char * c_szFileName, int iPlayCount)
|
||||
{
|
||||
if (m_isSoundDisable || !c_szFileName || !c_szFileName[0])
|
||||
if (0.0f == GetSoundVolume())
|
||||
return;
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::PlaySound3D;
|
||||
cmd.filename = c_szFileName;
|
||||
cmd.x = fx;
|
||||
cmd.y = fy;
|
||||
cmd.z = fz;
|
||||
cmd.play_count = iPlayCount;
|
||||
cmd.volume = m_fSoundVolume;
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
|
||||
void CSoundManager::StopSound3D(int iIndex)
|
||||
{
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::StopSound3D;
|
||||
cmd.id = iIndex;
|
||||
PushAudioCommand(cmd);
|
||||
int iIndex = ms_SoundManager3D.SetInstance(c_szFileName);
|
||||
if (-1 == iIndex)
|
||||
return;
|
||||
|
||||
ISoundInstance * pInstance = ms_SoundManager3D.GetInstance(iIndex);
|
||||
if (!pInstance)
|
||||
return;
|
||||
|
||||
pInstance->SetPosition((fx - m_fxPosition) / m_fSoundScale,
|
||||
(fy - m_fyPosition) / m_fSoundScale,
|
||||
(fz - m_fzPosition) / m_fSoundScale);
|
||||
|
||||
pInstance->SetVolume(GetSoundVolume());
|
||||
pInstance->Play(iPlayCount);
|
||||
}
|
||||
|
||||
int CSoundManager::PlayAmbienceSound3D(float fx, float fy, float fz, const char * c_szFileName, int iPlayCount)
|
||||
{
|
||||
if (m_isSoundDisable || !c_szFileName || !c_szFileName[0])
|
||||
if (0.0f == GetSoundVolume())
|
||||
return -1;
|
||||
static int s_next_id = 1;
|
||||
int id = s_next_id++;
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::PlaySound3D;
|
||||
cmd.filename = c_szFileName;
|
||||
cmd.x = fx;
|
||||
cmd.y = fy;
|
||||
cmd.z = fz;
|
||||
cmd.play_count = iPlayCount;
|
||||
cmd.volume = m_fSoundVolume;
|
||||
cmd.id = id;
|
||||
PushAudioCommand(cmd);
|
||||
return id;
|
||||
|
||||
int iIndex = ms_SoundManager3D.SetInstance(c_szFileName);
|
||||
if (-1 == iIndex)
|
||||
return -1;
|
||||
|
||||
ISoundInstance * pInstance = ms_SoundManager3D.GetInstance(iIndex);
|
||||
if (!pInstance)
|
||||
return -1;
|
||||
|
||||
pInstance->SetPosition((fx - m_fxPosition) / m_fAmbienceSoundScale,
|
||||
(fy - m_fyPosition) / m_fAmbienceSoundScale,
|
||||
(fz - m_fzPosition) / m_fAmbienceSoundScale);
|
||||
|
||||
pInstance->SetVolume(GetSoundVolume());
|
||||
pInstance->Play(iPlayCount);
|
||||
|
||||
return iIndex;
|
||||
}
|
||||
|
||||
void CSoundManager::PlayCharacterSound3D(float fx, float fy, float fz, const char * c_szFileName, BOOL)
|
||||
void CSoundManager::PlayCharacterSound3D(float fx, float fy, float fz, const char * c_szFileName, BOOL bCheckFrequency)
|
||||
{
|
||||
PlaySound3D(fx, fy, fz, c_szFileName, 1);
|
||||
if (0.0f == GetSoundVolume())
|
||||
return;
|
||||
|
||||
// 어느 정도의 최적화가 필요할 수도 있다 - [levites]
|
||||
if (bCheckFrequency)
|
||||
{
|
||||
static float s_fLimitDistance = 5000*5000;
|
||||
float fdx = (fx - m_fxPosition) * (fx - m_fxPosition);
|
||||
float fdy = (fy - m_fyPosition) * (fy - m_fyPosition);
|
||||
|
||||
if (fdx+fdy > s_fLimitDistance)
|
||||
return;
|
||||
|
||||
std::map<std::string, float>::iterator itor = m_PlaySoundHistoryMap.find(c_szFileName);
|
||||
if (m_PlaySoundHistoryMap.end() != itor)
|
||||
{
|
||||
float fTime = itor->second;
|
||||
if (CTimer::Instance().GetCurrentSecond() - fTime < 0.3f)
|
||||
{
|
||||
//Tracef("똑같은 소리가 0.3초 내에 다시 플레이 %s\n", c_szFileName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_PlaySoundHistoryMap.erase(c_szFileName);
|
||||
m_PlaySoundHistoryMap.insert(std::map<std::string, float>::value_type(c_szFileName, CTimer::Instance().GetCurrentSecond()));
|
||||
}
|
||||
|
||||
ISoundInstance * pInstance;
|
||||
|
||||
if (!GetSoundInstance3D(c_szFileName, &pInstance))
|
||||
return;
|
||||
|
||||
pInstance->SetPosition((fx - m_fxPosition) / m_fSoundScale,
|
||||
(fy - m_fyPosition) / m_fSoundScale,
|
||||
(fz - m_fzPosition) / m_fSoundScale);
|
||||
|
||||
pInstance->SetVolume(GetSoundVolume());
|
||||
pInstance->Play(1);
|
||||
}
|
||||
|
||||
void CSoundManager::SetSoundVolume3D(int index, float volume)
|
||||
void CSoundManager::StopSound3D(int iIndex)
|
||||
{
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::SetSoundVolume3D;
|
||||
cmd.id = index;
|
||||
cmd.volume = volume;
|
||||
PushAudioCommand(cmd);
|
||||
ISoundInstance * pInstance = ms_SoundManager3D.GetInstance(iIndex);
|
||||
|
||||
if (!pInstance)
|
||||
return;
|
||||
|
||||
pInstance->Stop();
|
||||
//bool bisDone = pInstance->IsDone();
|
||||
}
|
||||
|
||||
void CSoundManager::SetSoundVolume3D(int iIndex, float fVolume)
|
||||
{
|
||||
ISoundInstance * pInstance = ms_SoundManager3D.GetInstance(iIndex);
|
||||
|
||||
if (!pInstance)
|
||||
return;
|
||||
|
||||
pInstance->SetVolume(fVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::StopAllSound3D()
|
||||
{
|
||||
m_PlaySoundHistoryMap.clear();
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::StopAllSound3D;
|
||||
PushAudioCommand(cmd);
|
||||
for (int i = 0; i < CSoundManager3D::INSTANCE_MAX_COUNT; ++i)
|
||||
{
|
||||
StopSound3D(i);
|
||||
}
|
||||
|
||||
m_PlaySoundHistoryMap.clear(); // Fix
|
||||
}
|
||||
|
||||
void CSoundManager::PlayMusic(const char * c_szFileName)
|
||||
{
|
||||
if (!c_szFileName || !c_szFileName[0])
|
||||
PlayMusic(0, c_szFileName, GetMusicVolume(), 0.0f);
|
||||
}
|
||||
|
||||
void CSoundManager::FadeInMusic(const char * c_szFileName, float fVolumeSpeed)
|
||||
{
|
||||
DWORD dwIndex;
|
||||
if (GetMusicIndex(c_szFileName, &dwIndex))
|
||||
{
|
||||
m_MusicInstances[dwIndex].MusicState = MUSIC_STATE_FADE_IN;
|
||||
m_MusicInstances[dwIndex].fVolumeSpeed = fVolumeSpeed;
|
||||
return;
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::PlayMusic;
|
||||
cmd.filename = c_szFileName;
|
||||
cmd.volume = m_fMusicVolume;
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void CSoundManager::FadeInMusic(const char * c_szFileName, float speed)
|
||||
{
|
||||
if (!c_szFileName || !c_szFileName[0])
|
||||
FadeOutAllMusic();
|
||||
|
||||
//Tracenf("FadeInMusic: %s", c_szFileName);
|
||||
|
||||
for (int i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i)
|
||||
{
|
||||
TMusicInstance & rMusicInstance = m_MusicInstances[i];
|
||||
if (MUSIC_STATE_OFF != rMusicInstance.MusicState)
|
||||
continue;
|
||||
|
||||
PlayMusic(i, c_szFileName, 0.0f, fVolumeSpeed);
|
||||
return;
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::FadeInMusic;
|
||||
cmd.filename = c_szFileName;
|
||||
cmd.volume = m_fMusicVolume;
|
||||
cmd.speed = speed;
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
// If there is no empty music slot, then play music on slot 0.
|
||||
/*
|
||||
StopMusic(0);
|
||||
PlayMusic(0, c_szFileName, 0.0f, fVolumeSpeed);
|
||||
*/
|
||||
}
|
||||
|
||||
void CSoundManager::FadeOutMusic(const char * c_szFileName, float fSpeed)
|
||||
void CSoundManager::FadeLimitOutMusic(const char * c_szFileName, float fLimitVolume, float fVolumeSpeed)
|
||||
{
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::FadeOutMusic;
|
||||
cmd.filename = c_szFileName ? c_szFileName : "";
|
||||
cmd.speed = fSpeed;
|
||||
PushAudioCommand(cmd);
|
||||
//Tracenf("FadeLimitOutMusic: %s", c_szFileName);
|
||||
|
||||
DWORD dwIndex;
|
||||
if (!GetMusicIndex(c_szFileName, &dwIndex))
|
||||
{
|
||||
Tracenf("FadeOutMusic: %s - ERROR NOT EXIST", c_szFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dwIndex >= CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM)
|
||||
{
|
||||
Tracenf("FadeOutMusic: %s - ERROR OUT OF RANGE", c_szFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
SMusicInstance& rkMusicInst=m_MusicInstances[dwIndex];
|
||||
rkMusicInst.MusicState = MUSIC_STATE_FADE_LIMIT_OUT;
|
||||
rkMusicInst.fVolumeSpeed = fVolumeSpeed;
|
||||
rkMusicInst.fLimitVolume = __ConvertRatioVolumeToApplyVolume(fLimitVolume);
|
||||
|
||||
//Tracenf("LimitVolume %f(%f)", fLimitVolume, rkMusicInst.fLimitVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::FadeLimitOutMusic(const char * c_szFileName, float limit, float speed)
|
||||
void CSoundManager::FadeOutMusic(const char * c_szFileName, float fVolumeSpeed)
|
||||
{
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::FadeLimitOutMusic;
|
||||
cmd.filename = c_szFileName ? c_szFileName : "";
|
||||
cmd.volume = __ConvertRatioVolumeToApplyVolume(limit);
|
||||
cmd.speed = speed;
|
||||
PushAudioCommand(cmd);
|
||||
//Tracenf("FadeOutMusic: %s", c_szFileName);
|
||||
|
||||
DWORD dwIndex;
|
||||
if (!GetMusicIndex(c_szFileName, &dwIndex))
|
||||
{
|
||||
Tracenf("FadeOutMusic: %s - ERROR NOT EXIST", c_szFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dwIndex >= CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM)
|
||||
{
|
||||
Tracenf("FadeOutMusic: %s - ERROR OUT OF RANGE", c_szFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
m_MusicInstances[dwIndex].MusicState = MUSIC_STATE_FADE_OUT;
|
||||
m_MusicInstances[dwIndex].fVolumeSpeed = fVolumeSpeed;
|
||||
}
|
||||
|
||||
void CSoundManager::FadeOutAllMusic()
|
||||
{
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::FadeOutAllMusic;
|
||||
PushAudioCommand(cmd);
|
||||
//Tracenf("FadeOutAllMusic");
|
||||
|
||||
for (int i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i)
|
||||
{
|
||||
if (MUSIC_STATE_OFF == m_MusicInstances[i].MusicState)
|
||||
continue;
|
||||
|
||||
m_MusicInstances[i].MusicState = MUSIC_STATE_FADE_OUT;
|
||||
m_MusicInstances[i].fVolumeSpeed = 0.01f;
|
||||
}
|
||||
}
|
||||
|
||||
void CSoundManager::SaveVolume()
|
||||
{
|
||||
// NOTE : 두번 이상 Save를 시도할때는 그냥 Return
|
||||
if (m_isSoundDisable)
|
||||
return;
|
||||
|
||||
float fBackupMusicVolume = m_fMusicVolume;
|
||||
float fBackupSoundVolume = m_fSoundVolume;
|
||||
__SetMusicVolume(0.0f);
|
||||
SetSoundVolume(0.0f);
|
||||
m_fBackupMusicVolume = fBackupMusicVolume;
|
||||
m_fBackupSoundVolume = fBackupSoundVolume;
|
||||
m_isSoundDisable = TRUE;
|
||||
}
|
||||
|
||||
void CSoundManager::RestoreVolume()
|
||||
{
|
||||
m_isSoundDisable = FALSE;
|
||||
__SetMusicVolume(m_fBackupMusicVolume);
|
||||
SetSoundVolume(m_fBackupSoundVolume);
|
||||
}
|
||||
|
||||
void CSoundManager::PlayMusic(DWORD dwIndex, const char * c_szFileName, float fVolume, float fVolumeSpeed)
|
||||
{
|
||||
if (dwIndex >= CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM)
|
||||
return;
|
||||
|
||||
if (!ms_SoundManagerStream.SetInstance(dwIndex, c_szFileName))
|
||||
{
|
||||
TraceError("CSoundManager::PlayMusic - Failed to load stream sound : %s", c_szFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
CSoundInstanceStream * pInstance = ms_SoundManagerStream.GetInstance(dwIndex);
|
||||
if (!pInstance)
|
||||
{
|
||||
TraceError("CSoundManager::PlayMusic - There is no stream sound instance : %s", c_szFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
pInstance->SetVolume(fVolume);
|
||||
pInstance->Play(0);
|
||||
|
||||
TMusicInstance & rMusicInstance = m_MusicInstances[dwIndex];
|
||||
rMusicInstance.fVolume = fVolume;
|
||||
rMusicInstance.fVolumeSpeed = fVolumeSpeed;
|
||||
rMusicInstance.MusicState = MUSIC_STATE_FADE_IN;
|
||||
|
||||
std::string strFileName;
|
||||
StringPath(c_szFileName, strFileName);
|
||||
rMusicInstance.dwMusicFileNameCRC = GetCaseCRC32(strFileName.c_str(), strFileName.length());
|
||||
}
|
||||
|
||||
void CSoundManager::StopMusic(DWORD dwIndex)
|
||||
{
|
||||
if (dwIndex >= CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM)
|
||||
return;
|
||||
|
||||
CSoundInstanceStream * pInstance = ms_SoundManagerStream.GetInstance(dwIndex);
|
||||
if (!pInstance)
|
||||
return;
|
||||
|
||||
pInstance->Stop();
|
||||
|
||||
TMusicInstance & rMusicInstance = m_MusicInstances[dwIndex];
|
||||
rMusicInstance.fVolume = 0.0f;
|
||||
rMusicInstance.fVolumeSpeed = 0.0f;
|
||||
rMusicInstance.MusicState = MUSIC_STATE_OFF;
|
||||
rMusicInstance.dwMusicFileNameCRC = 0;
|
||||
}
|
||||
|
||||
BOOL CSoundManager::GetMusicIndex(const char * c_szFileName, DWORD * pdwIndex)
|
||||
{
|
||||
std::string strFileName;
|
||||
StringPath(c_szFileName, strFileName);
|
||||
DWORD dwCRC = GetCaseCRC32(strFileName.c_str(), strFileName.length());
|
||||
|
||||
for (int i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i)
|
||||
{
|
||||
const TMusicInstance & c_rMusicInstance = m_MusicInstances[i];
|
||||
if (MUSIC_STATE_OFF != c_rMusicInstance.MusicState)
|
||||
if (c_rMusicInstance.dwMusicFileNameCRC == dwCRC)
|
||||
{
|
||||
*pdwIndex = i;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CSoundManager::FadeAll()
|
||||
{
|
||||
FadeOutAllMusic();
|
||||
}
|
||||
|
||||
void CSoundManager::UpdateSoundData(DWORD, const NSound::TSoundDataVector *)
|
||||
{
|
||||
}
|
||||
|
||||
void CSoundManager::UpdateSoundData(float, float, float, DWORD, const NSound::TSoundDataVector *)
|
||||
{
|
||||
}
|
||||
|
||||
void CSoundManager::UpdateSoundInstance(float, float, float, DWORD, const NSound::TSoundInstanceVector *, BOOL)
|
||||
{
|
||||
}
|
||||
|
||||
void CSoundManager::UpdateSoundInstance(DWORD, const NSound::TSoundInstanceVector *)
|
||||
{
|
||||
}
|
||||
|
||||
void CSoundManager::PlayMusic(DWORD, const char *, float, float)
|
||||
{
|
||||
}
|
||||
|
||||
void CSoundManager::StopMusic(DWORD)
|
||||
{
|
||||
}
|
||||
|
||||
BOOL CSoundManager::GetMusicIndex(const char *, DWORD *)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CSoundManager::GetSoundInstance2D(const char *, ISoundInstance **)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CSoundManager::GetSoundInstance3D(const char *, ISoundInstance **)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,79 @@
|
||||
// Platform skeleton for MilesLib/SoundManager2D.h (40250 MilesLib/SoundManager2D.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundManager2D.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
CSoundManager2D::CSoundManager2D()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundManager2D::~CSoundManager2D()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
{
|
||||
}
|
||||
|
||||
auto CSoundManager2D::Initialize() -> bool
|
||||
bool CSoundManager2D::Initialize()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
CSoundBase::Initialize();
|
||||
|
||||
if (ms_DIGDriver)
|
||||
return true;
|
||||
|
||||
ms_DIGDriver = AIL_open_digital_driver(44100, 16, 2, 0);
|
||||
|
||||
for (int i = 0; i < INSTANCE_MAX_COUNT; ++i)
|
||||
ms_Instances[i].Initialize();
|
||||
/* ms_DIGDriver = AIL_open_digital_driver(44100,
|
||||
(DIG_F_STEREO_16 & DIG_F_16BITS_MASK) ? 16 : 8,
|
||||
(DIG_F_STEREO_16 & DIG_F_16BITS_MASK) ? 2 : 1,
|
||||
0);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CSoundManager2D::Destroy() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
void CSoundManager2D::Destroy()
|
||||
{
|
||||
for (int i = 0; i < INSTANCE_MAX_COUNT; ++i)
|
||||
ms_Instances[i].Destroy();
|
||||
|
||||
if (ms_DIGDriver != NULL)
|
||||
{
|
||||
AIL_close_digital_driver(ms_DIGDriver);
|
||||
ms_DIGDriver = NULL;
|
||||
}
|
||||
|
||||
CSoundBase::Destroy();
|
||||
}
|
||||
|
||||
auto CSoundManager2D::GetInstance(const char *) -> ISoundInstance *
|
||||
ISoundInstance * CSoundManager2D::GetInstance(const char * c_pszFileName)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<ISoundInstance *>();
|
||||
DWORD dwFileCRC = GetFileCRC(c_pszFileName);
|
||||
TSoundDataMap::iterator itor = ms_dataMap.find(dwFileCRC);
|
||||
|
||||
CSoundData * pkSoundData;
|
||||
|
||||
if (itor == ms_dataMap.end())
|
||||
pkSoundData = AddFile(dwFileCRC, c_pszFileName); // CSoundBase::AddFile
|
||||
else
|
||||
pkSoundData = itor->second;
|
||||
|
||||
assert(pkSoundData != NULL);
|
||||
|
||||
static DWORD k = 0;
|
||||
|
||||
DWORD start = k++;
|
||||
DWORD end = start + INSTANCE_MAX_COUNT;
|
||||
|
||||
while (start < end)
|
||||
{
|
||||
CSoundInstance2D * pkInst = &ms_Instances[start % INSTANCE_MAX_COUNT];
|
||||
|
||||
if (pkInst->IsDone())
|
||||
{
|
||||
if (!pkInst->SetSound(pkSoundData))
|
||||
TraceError("CSoundManager2D::GetInstance (filename: %s)", c_pszFileName);
|
||||
return (pkInst);
|
||||
}
|
||||
|
||||
++start;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,76 +1,205 @@
|
||||
// Platform skeleton for MilesLib/SoundManager3D.h (40250 MilesLib/SoundManager3D.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundManager3D.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
CSoundManager3D::CSoundManager3D()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
m_bInit = false;
|
||||
}
|
||||
|
||||
CSoundManager3D::~CSoundManager3D()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CSoundManager3D::Initialize() -> bool
|
||||
bool CSoundManager3D::Initialize()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
CSoundBase::Initialize();
|
||||
|
||||
if (ms_pProviderDefault)
|
||||
return true;
|
||||
|
||||
ms_ProviderVector.resize(MAX_PROVIDERS);
|
||||
|
||||
HPROENUM enum3D = HPROENUM_FIRST;
|
||||
int i = 0;
|
||||
|
||||
while (AIL_enumerate_3D_providers(&enum3D,
|
||||
&ms_ProviderVector[i].hProvider,
|
||||
&ms_ProviderVector[i].name) && (i < MAX_PROVIDERS))
|
||||
{
|
||||
TProvider * provider = &ms_ProviderVector[i];
|
||||
|
||||
//if (strcmp(provider->name, "DirectSound3D Software Emulation") == 0)
|
||||
//if (strcmp(provider->name, "DirectSound3D Hardware Support") == 0)
|
||||
//if (strcmp(provider->name, "DirectSound3D 7+ Software - Pan and Volume") == 0)
|
||||
//if (strcmp(provider->name, "DirectSound3D 7+ Software - Light HRTF") == 0)
|
||||
//if (strcmp(provider->name, "DirectSound3D 7+ Software - Full HRTF") == 0)
|
||||
//if (strcmp(provider->name, "RAD Game Tools RSX 3D Audio") == 0)
|
||||
//if (strcmp(provider->name, "Dolby Surround") == 0)
|
||||
if (strcmp(provider->name, "Miles Fast 2D Positional Audio") == 0)
|
||||
ms_pProviderDefault = provider;
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
if (!ms_pProviderDefault)
|
||||
{
|
||||
CSoundBase::Destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(ms_pProviderDefault != NULL);
|
||||
|
||||
if (M3D_NOERR != AIL_open_3D_provider(ms_pProviderDefault->hProvider))
|
||||
{
|
||||
// assert(!"AIL_open_3D_provider error");
|
||||
// char buf[64];
|
||||
// sprintf(buf, "Error AIL_open_3D_provider: %s\n", AIL_last_error());
|
||||
// OutputDebugString(buf);
|
||||
|
||||
CSoundBase::Destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pListener = AIL_open_3D_listener(ms_pProviderDefault->hProvider);
|
||||
|
||||
SetListenerPosition(0.0f, 0.0f, 0.0f);
|
||||
|
||||
for (i = 0; i < INSTANCE_MAX_COUNT; ++i)
|
||||
{
|
||||
m_Instances[i].Initialize();
|
||||
m_bLockingFlag[i] = false;
|
||||
}
|
||||
|
||||
m_bInit = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CSoundManager3D::Destroy() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
|
||||
void CSoundManager3D::Destroy()
|
||||
{
|
||||
if (!m_bInit)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < INSTANCE_MAX_COUNT; ++i)
|
||||
m_Instances[i].Destroy();
|
||||
|
||||
if (m_pListener)
|
||||
{
|
||||
AIL_close_3D_listener(m_pListener);
|
||||
m_pListener = NULL;
|
||||
}
|
||||
|
||||
if (ms_pProviderDefault)
|
||||
{
|
||||
AIL_close_3D_provider(ms_pProviderDefault->hProvider);
|
||||
ms_pProviderDefault = NULL;
|
||||
}
|
||||
|
||||
CSoundBase::Destroy();
|
||||
m_bInit = false;
|
||||
}
|
||||
|
||||
auto CSoundManager3D::GetEmptyInstanceIndex() -> int
|
||||
void CSoundManager3D::SetListenerDirection(float fxDir, float fyDir, float fzDir, float fxUp, float fyUp, float fzUp)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<int>();
|
||||
if (NULL == m_pListener)
|
||||
return;
|
||||
AIL_set_3D_orientation(m_pListener, fxDir, fyDir, -fzDir, fxUp, fyUp, -fzUp);
|
||||
}
|
||||
|
||||
auto CSoundManager3D::SetInstance(const char *) -> int
|
||||
void CSoundManager3D::SetListenerPosition(float fX, float fY, float fZ)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<int>();
|
||||
// assert(m_pListener != NULL);
|
||||
if (NULL == m_pListener)
|
||||
return;
|
||||
AIL_set_3D_position(m_pListener, fX, fY, -fZ);
|
||||
}
|
||||
|
||||
auto CSoundManager3D::GetInstance(DWORD) -> ISoundInstance *
|
||||
void CSoundManager3D::SetListenerVelocity(float fDistanceX, float fDistanceY, float fDistanceZ, float fNagnitude)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<ISoundInstance *>();
|
||||
// assert(m_pListener != NULL);
|
||||
if (NULL == m_pListener)
|
||||
return;
|
||||
AIL_set_3D_velocity(m_pListener, fDistanceX, fDistanceY, -fDistanceZ, fNagnitude);
|
||||
}
|
||||
|
||||
auto CSoundManager3D::SetListenerDirection(float, float, float, float, float, float) -> void
|
||||
int CSoundManager3D::SetInstance(const char * c_pszFileName)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
DWORD dwFileCRC = GetFileCRC(c_pszFileName);
|
||||
TSoundDataMap::iterator itor = ms_dataMap.find(dwFileCRC);
|
||||
|
||||
CSoundData * pkSoundData;
|
||||
|
||||
if (itor == ms_dataMap.end())
|
||||
pkSoundData = AddFile(dwFileCRC, c_pszFileName); // CSoundBase::AddFile
|
||||
else
|
||||
pkSoundData = itor->second;
|
||||
|
||||
assert(pkSoundData != NULL);
|
||||
|
||||
static DWORD k = 0;
|
||||
|
||||
DWORD start = k++;
|
||||
DWORD end = start + INSTANCE_MAX_COUNT;
|
||||
|
||||
while (start < end)
|
||||
{
|
||||
CSoundInstance3D * pkInst = &m_Instances[start % INSTANCE_MAX_COUNT];
|
||||
|
||||
if (pkInst->IsDone())
|
||||
{
|
||||
if (!pkInst->SetSound(pkSoundData))
|
||||
{
|
||||
TraceError("CSoundManager3D::GetInstance (filename: %s)", c_pszFileName);
|
||||
// NOTE : 사운드가 없을 경우 Failed to set. return NULL. - [levites]
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (start % INSTANCE_MAX_COUNT);
|
||||
}
|
||||
|
||||
++start;
|
||||
|
||||
// 설마 DWORD 한계값을 넘어갈리야 없겠지만.. 그래도.. 혹시나.. - [levites]
|
||||
if (start > 50000)
|
||||
{
|
||||
start = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto CSoundManager3D::SetListenerPosition(float, float, float) -> void
|
||||
ISoundInstance * CSoundManager3D::GetInstance(DWORD dwIndex)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
if (dwIndex >= INSTANCE_MAX_COUNT)
|
||||
{
|
||||
assert(dwIndex < INSTANCE_MAX_COUNT);
|
||||
return NULL;
|
||||
}
|
||||
return &m_Instances[dwIndex];
|
||||
}
|
||||
|
||||
auto CSoundManager3D::SetListenerVelocity(float, float, float, float) -> void
|
||||
__forceinline bool CSoundManager3D::IsValidInstanceIndex(int iIndex)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
if (iIndex >= 0 && iIndex < INSTANCE_MAX_COUNT)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
auto CSoundManager3D::Lock(int) -> void
|
||||
void CSoundManager3D::Lock(int iIndex)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
if (!IsValidInstanceIndex(iIndex))
|
||||
return;
|
||||
|
||||
m_bLockingFlag[iIndex] = true;
|
||||
}
|
||||
|
||||
auto CSoundManager3D::Unlock(int) -> void
|
||||
void CSoundManager3D::Unlock(int iIndex)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
if (!IsValidInstanceIndex(iIndex))
|
||||
return;
|
||||
|
||||
auto CSoundManager3D::IsValidInstanceIndex(int) -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
m_bLockingFlag[iIndex] = false;
|
||||
}
|
||||
|
||||
@@ -1,45 +1,64 @@
|
||||
// Platform skeleton for MilesLib/SoundManagerStream.h (40250 MilesLib/SoundManagerStream.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/SoundManagerStream.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
CSoundManagerStream::CSoundManagerStream()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CSoundManagerStream::~CSoundManagerStream()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
{
|
||||
}
|
||||
|
||||
auto CSoundManagerStream::Initialize() -> bool
|
||||
bool CSoundManagerStream::Initialize()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
CSoundBase::Initialize();
|
||||
|
||||
if (ms_DIGDriver)
|
||||
return true;
|
||||
|
||||
ms_DIGDriver = AIL_open_digital_driver(44100, 16, 2, 0);
|
||||
|
||||
for (int i = 0; i < MUSIC_INSTANCE_MAX_NUM; ++i)
|
||||
m_Instances[i].Initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CSoundManagerStream::Destroy() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
void CSoundManagerStream::Destroy()
|
||||
{
|
||||
for (int i=0; i<MUSIC_INSTANCE_MAX_NUM; ++i)
|
||||
m_Instances[i].Stop();
|
||||
|
||||
CSoundBase::Destroy();
|
||||
}
|
||||
|
||||
auto CSoundManagerStream::SetInstance(DWORD, const char *) -> bool
|
||||
bool CSoundManagerStream::SetInstance(DWORD dwIndex, const char* filename)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
if (!CheckInstanceIndex(dwIndex))
|
||||
return false;
|
||||
|
||||
HSTREAM hStream = AIL_open_stream(ms_DIGDriver, filename, 0);
|
||||
|
||||
if (NULL == hStream)
|
||||
return false;
|
||||
|
||||
m_Instances[dwIndex].SetStream(hStream);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CSoundManagerStream::GetInstance(DWORD) -> CSoundInstanceStream *
|
||||
CSoundInstanceStream * CSoundManagerStream::GetInstance(DWORD dwIndex)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<CSoundInstanceStream *>();
|
||||
if (!CheckInstanceIndex(dwIndex))
|
||||
return NULL;
|
||||
|
||||
return &m_Instances[dwIndex];
|
||||
}
|
||||
|
||||
auto CSoundManagerStream::CheckInstanceIndex(DWORD) -> bool
|
||||
bool CSoundManagerStream::CheckInstanceIndex(DWORD dwIndex)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
if (dwIndex >= DWORD(MUSIC_INSTANCE_MAX_NUM))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
+119
-17
@@ -1,34 +1,136 @@
|
||||
// Platform skeleton for MilesLib/Type.h (40250 MilesLib/Type.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
#include "MilesLib/Stdafx.h"
|
||||
#include "MilesLib/Type.h"
|
||||
#include "EterLib/TextFileLoader.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
std::string NSound::strResult;
|
||||
|
||||
auto NSound::LoadSoundInformationPiece(const char *, TSoundDataVector &, const char *) -> bool
|
||||
const char * NSound::GetResultString()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
return strResult.c_str();
|
||||
}
|
||||
|
||||
auto NSound::SaveSoundInformationPiece(const char *, TSoundDataVector &) -> bool
|
||||
void NSound::SetResultString(const char * c_pszStr)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
strResult.assign(c_pszStr);
|
||||
}
|
||||
|
||||
auto NSound::DataToInstance(const TSoundDataVector &, TSoundInstanceVector *) -> void
|
||||
bool NSound::LoadSoundInformationPiece(const char * c_szFileName, NSound::TSoundDataVector & rSoundDataVector, const char * c_szPathHeader)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
std::string strResult;
|
||||
strResult = c_szFileName;
|
||||
|
||||
CTextFileLoader* pkTextFileLoader=CTextFileLoader::Cache(c_szFileName);
|
||||
if (!pkTextFileLoader)
|
||||
return false;
|
||||
|
||||
CTextFileLoader& rkTextFileLoader=*pkTextFileLoader;
|
||||
if (rkTextFileLoader.IsEmpty())
|
||||
{
|
||||
SetResultString((strResult + " 읽기용 파일을 열 수 없음").c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
rkTextFileLoader.SetTop();
|
||||
|
||||
int iCount;
|
||||
if (!rkTextFileLoader.GetTokenInteger("sounddatacount", &iCount))
|
||||
{
|
||||
SetResultString((strResult + " 파일 포멧 에러, SoundDataCount를 찾을 수 없음").c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
rSoundDataVector.clear();
|
||||
rSoundDataVector.resize(iCount);
|
||||
|
||||
char szSoundDataHeader[32+1];
|
||||
for (DWORD i = 0; i < rSoundDataVector.size(); ++i)
|
||||
{
|
||||
_snprintf(szSoundDataHeader, sizeof(szSoundDataHeader), "sounddata%02d", i);
|
||||
CTokenVector * pTokenVector;
|
||||
if (!rkTextFileLoader.GetTokenVector(szSoundDataHeader, &pTokenVector))
|
||||
{
|
||||
SetResultString((strResult + " 파일 포멧 에러: " + szSoundDataHeader + " 를 찾을 수 없음").c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (2 != pTokenVector->size())
|
||||
{
|
||||
SetResultString((strResult + " 파일 포멧 에러: 벡터 크기가 2가 아님").c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
rSoundDataVector[i].fTime = (float) atof(pTokenVector->at(0).c_str());
|
||||
if (c_szPathHeader)
|
||||
{
|
||||
rSoundDataVector[i].strSoundFileName = c_szPathHeader;
|
||||
rSoundDataVector[i].strSoundFileName += pTokenVector->at(1).c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
rSoundDataVector[i].strSoundFileName = pTokenVector->at(1).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
SetResultString((strResult + " 불러옴").c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
auto NSound::GetResultString() -> const char *
|
||||
bool NSound::SaveSoundInformationPiece(const char * c_szFileName, NSound::TSoundDataVector & rSoundDataVector)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<const char *>();
|
||||
if (rSoundDataVector.empty()) // 데이터가 없으면 성공으로 간주
|
||||
{
|
||||
if (IsFile(c_szFileName)) // 데이터는 비어있는데 파일이 있다면
|
||||
{
|
||||
_unlink(c_szFileName); // 지운다.
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string strResult;
|
||||
strResult = c_szFileName;
|
||||
|
||||
FILE * File = fopen(c_szFileName, "wt");
|
||||
|
||||
if (!File)
|
||||
{
|
||||
char szErrorText[256+1];
|
||||
_snprintf(szErrorText, sizeof(szErrorText), "Failed to save file (%s).\nPlease check if it is read-only or you have no space on the disk.\n", c_szFileName);
|
||||
LogBox(szErrorText, "에러");
|
||||
SetResultString((strResult + " 쓰기용 파일을 열 수 없음").c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
fprintf(File, "ScriptType CharacterSoundInformation\n");
|
||||
fprintf(File, "\n");
|
||||
|
||||
fprintf(File, "SoundDataCount %d\n", rSoundDataVector.size());
|
||||
|
||||
for (DWORD i = 0; i < rSoundDataVector.size(); ++i)
|
||||
{
|
||||
NSound::TSoundData & rSoundData = rSoundDataVector[i];
|
||||
fprintf(File, "SoundData%02d %f \"%s\"\n", i, rSoundData.fTime, rSoundData.strSoundFileName.c_str());
|
||||
}
|
||||
|
||||
fclose(File);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto NSound::SetResultString(const char *) -> void
|
||||
void NSound::DataToInstance(const TSoundDataVector & c_rSoundDataVector, TSoundInstanceVector * pSoundInstanceVector)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
if (c_rSoundDataVector.empty())
|
||||
return;
|
||||
|
||||
DWORD dwFPS = 60;
|
||||
const float c_fFrameTime = 1.0f / float(dwFPS);
|
||||
|
||||
pSoundInstanceVector->clear();
|
||||
pSoundInstanceVector->resize(c_rSoundDataVector.size());
|
||||
for (DWORD i = 0; i < c_rSoundDataVector.size(); ++i)
|
||||
{
|
||||
const TSoundData & c_rSoundData = c_rSoundDataVector[i];
|
||||
TSoundInstance & rSoundInstance = pSoundInstanceVector->at(i);
|
||||
|
||||
rSoundInstance.dwFrame = (DWORD) (c_rSoundData.fTime / c_fFrameTime);
|
||||
rSoundInstance.strSoundFileName = c_rSoundData.strSoundFileName;
|
||||
}
|
||||
}
|
||||
@@ -401,6 +401,17 @@ void UIMouseWheel(int nLen)
|
||||
pkCmrCur->Wheel(nLen);
|
||||
}
|
||||
|
||||
// 40250 CPythonApplication::WindowProcedure WM_ACTIVATEAPP (PythonApplicationProcedure.cpp:58): the sound
|
||||
// is muted while the window is inactive.
|
||||
void UIActivate(bool active)
|
||||
{
|
||||
if (!g_sound_manager) return;
|
||||
if (active)
|
||||
g_sound_manager->RestoreVolume();
|
||||
else
|
||||
g_sound_manager->SaveVolume();
|
||||
}
|
||||
|
||||
// 40250 CPythonApplication::OnKeyDown/OnKeyUp (PythonApplicationEvent.cpp:130-146): ESC first goes
|
||||
// to RunPressEscapeKey (the OnPressEscapeKey chain every dialog closes on), then to RunKeyDown.
|
||||
void UIKey(int key, bool pressed)
|
||||
@@ -757,6 +768,9 @@ bool Start(const char* stdlib_path, std::string* error)
|
||||
g_game_singletons->pySystem.GetConfig()->width = ui_w;
|
||||
g_game_singletons->pySystem.GetConfig()->height = ui_h;
|
||||
}
|
||||
// 40250 CPythonApplication::Create (PythonApplication.cpp:1186): no warning box when it fails.
|
||||
if (!g_game_singletons->pySystem.IsNoSoundCard())
|
||||
g_sound_manager->Create();
|
||||
g_game_singletons->pySystem.GetDisplaySettings(); // 40250 CPythonApplication::Create (PythonApplication.cpp:1233)
|
||||
g_flying_manager->SetMapManagerPtr(&g_game_singletons->pyBackground); // 40250 CPythonApplication ctor (PythonApplication.cpp:82)
|
||||
return true;
|
||||
@@ -1049,6 +1063,7 @@ void Stop()
|
||||
g_race_manager.reset();
|
||||
g_server_state_checker.reset();
|
||||
g_flying_manager.reset();
|
||||
g_sound_manager->Destroy(); // 40250 CPythonApplication::Destroy (PythonApplication.cpp:1442)
|
||||
g_sound_manager.reset();
|
||||
g_player.reset();
|
||||
g_account_connector.reset();
|
||||
|
||||
@@ -70,6 +70,8 @@ void UIMouseMove(int x, int y);
|
||||
void UIMouseButton(int button, bool pressed, int x, int y);
|
||||
void UIMouseWheel(int nLen);
|
||||
void UIKey(int key, bool pressed);
|
||||
// WM_ACTIVATEAPP: the window gained (true) or lost the focus.
|
||||
void UIActivate(bool active);
|
||||
// Mobile touch & joystick controls
|
||||
void SetMoveDirection(float angleDeg, bool moving);
|
||||
void SetAttackKey(bool pressed);
|
||||
|
||||
@@ -132,8 +132,17 @@ void CPythonApplication::__UpdateCamera()
|
||||
if (0.0f != s_app.m_kCmrPos.m_fUpDir)
|
||||
pMainCamera->MoveVertical(s_app.m_kCmrPos.m_fUpDir);
|
||||
|
||||
// PORT: SkipRenderBuffering while dragging and the listener update of m_SoundManager follow here in
|
||||
// 40250; there is no render buffering and sound is not ported (2V4).
|
||||
// PORT: SkipRenderBuffering while dragging follows here in 40250; there is no render buffering.
|
||||
|
||||
//////////////////////
|
||||
// Sound Setting
|
||||
// PORT: m_SoundManager is the CSoundManager singleton (PythonBoot's g_sound_manager).
|
||||
const D3DXVECTOR3 & c_rv3CameraDirection = pMainCamera->GetView();
|
||||
const D3DXVECTOR3 & c_rv3CameraUp = pMainCamera->GetUp();
|
||||
CSoundManager::Instance().SetPosition(s_app.m_v3CenterPosition.x, s_app.m_v3CenterPosition.y, s_app.m_v3CenterPosition.z); // Listener - character position
|
||||
CSoundManager::Instance().SetDirection(c_rv3CameraDirection.x, c_rv3CameraDirection.y, c_rv3CameraDirection.z, c_rv3CameraUp.x, c_rv3CameraUp.y, c_rv3CameraUp.z);
|
||||
CSoundManager::Instance().Update();
|
||||
//////////////////////
|
||||
}
|
||||
|
||||
void CPythonApplication::SetViewDirCameraSpeed(float fSpeed)
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
// Platform implementation of the pack bootstrap from 40250 UserInterface/UserInterface.cpp. PackInitialize is the 40250
|
||||
// function with three platform differences:
|
||||
// function with two platform differences:
|
||||
// - pack names in Index are matched to the on-disk .eix/.epk case-insensitively ("Etc" is ETC.eix on NTFS, and
|
||||
// CEterPack::CreateIndexFile fopens the name as given), so the registered dbname carries the on-disk spelling;
|
||||
// - no LogBoxf (a Win32 message box), only the TraceError next to it;
|
||||
// - CTextFileLoader::SetCacheMode and CSoundData::SetPackMode are not called: EterLib/TextFileLoader and MilesLib
|
||||
// are not ported yet, and neither affects which files the pack manager registers or returns.
|
||||
// - no LogBoxf (a Win32 message box), only the TraceError next to it.
|
||||
// Built as in the Distribute configuration (_DISTRIBUTE): pack first.
|
||||
#include "EterBase/StdAfx.h"
|
||||
#include "EterBase/FileLoader.h"
|
||||
@@ -12,6 +10,8 @@
|
||||
#include "EterBase/Debug.h"
|
||||
#include "EterBase/lzo.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "EterLib/TextFileLoader.h"
|
||||
#include "MilesLib/SoundData.h"
|
||||
#include "UserInterface.h"
|
||||
|
||||
#include <map>
|
||||
@@ -147,9 +147,12 @@ bool PackInitialize(const char * c_pszFolder)
|
||||
return false;
|
||||
}
|
||||
|
||||
CTextFileLoader::SetCacheMode();
|
||||
CEterPackManager::Instance().SetCacheMode();
|
||||
CEterPackManager::Instance().SetSearchMode(bPackFirst);
|
||||
|
||||
CSoundData::SetPackMode(); // Miles file callbacks
|
||||
|
||||
const std::map<std::string, std::string> names = list_folder(stFolder);
|
||||
|
||||
std::string strPackName, strTexCachePackName;
|
||||
|
||||
@@ -195,6 +195,11 @@ if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
|
||||
add_test(NAME port.text COMMAND $<TARGET_FILE:port_text_test>)
|
||||
set_tests_properties(port.text PROPERTIES SKIP_RETURN_CODE 77)
|
||||
|
||||
# MilesLib: the 40250 sound managers over the Miles emulation (platform/MilesLib/MilesAil.cpp).
|
||||
add_executable(port_miles_test ${PROJECT_SOURCE_DIR}/tests/port/port_miles_test.cpp)
|
||||
target_link_libraries(port_miles_test PRIVATE port_platform)
|
||||
add_test(NAME port.miles COMMAND $<TARGET_FILE:port_miles_test>)
|
||||
|
||||
# 批次 2V1: Packet.h struct sizes against the classic wire layouts.
|
||||
add_executable(port_packet_test ${PROJECT_SOURCE_DIR}/tests/port/port_packet_test.cpp
|
||||
${PROJECT_SOURCE_DIR}/tests/port/port_packet_test_wire.cpp)
|
||||
|
||||
@@ -52,6 +52,11 @@ int _access(const char* path, int mode)
|
||||
return access(path, m);
|
||||
}
|
||||
|
||||
int _unlink(const char* path)
|
||||
{
|
||||
return unlink(path);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct FindState
|
||||
|
||||
@@ -58,11 +58,12 @@ int _snprintf(char* buf, size_t count, const char* fmt, ...)
|
||||
;
|
||||
|
||||
// kernel32 file-system calls (ANSI). CreateDirectory ignores the security attributes; _access takes
|
||||
// the MSVC modes 0 (exists), 2 (write), 4 (read), 6 (read/write).
|
||||
// the MSVC modes 0 (exists), 2 (write), 4 (read), 6 (read/write). _unlink is the <io.h> one.
|
||||
BOOL CreateDirectory(LPCSTR path, void* security_attributes);
|
||||
BOOL DeleteFile(LPCSTR path);
|
||||
BOOL CopyFile(LPCSTR existing_path, LPCSTR new_path, BOOL fail_if_exists);
|
||||
int _access(const char* path, int mode);
|
||||
int _unlink(const char* path);
|
||||
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
|
||||
#define FILE_ATTRIBUTE_NORMAL 0x00000080
|
||||
struct WIN32_FIND_DATA { DWORD dwFileAttributes; char cFileName[MAX_PATH]; };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
// Shim for Miles Sound System <mss.h>: the scalar types and opaque handles 40250's MilesLib
|
||||
// headers name. Playback goes through platform/, never through these declarations.
|
||||
// Shim for Miles Sound System <mss.h>: the scalar types, opaque handles, constants and the AIL_* calls
|
||||
// 40250's MilesLib makes. The calls are implemented by platform/MilesLib/MilesAil.cpp, a small software
|
||||
// mixer the host drains into its SDL audio stream (platform/MilesLib/MilesMixer.h).
|
||||
#include "../../Win32Types.h"
|
||||
|
||||
typedef int32_t S32;
|
||||
@@ -24,3 +25,123 @@ typedef _DIG_DRIVER* HDIGDRIVER;
|
||||
typedef void* H3DPOBJECT;
|
||||
typedef H3DPOBJECT H3DSAMPLE;
|
||||
typedef U32 HPROVIDER;
|
||||
typedef U32 HPROENUM;
|
||||
typedef S32 M3DRESULT;
|
||||
|
||||
#define HPROENUM_FIRST 0
|
||||
#define M3D_NOERR 0
|
||||
|
||||
// Sample/stream status (AIL_sample_status, AIL_3D_sample_status, AIL_stream_status).
|
||||
#define SMP_FREE 0x0001
|
||||
#define SMP_DONE 0x0002
|
||||
#define SMP_PLAYING 0x0004
|
||||
#define SMP_STOPPED 0x0008
|
||||
#define SMP_PLAYINGBUTRELEASED 0x0010
|
||||
|
||||
// AIL_file_type results.
|
||||
#define AILFILETYPE_UNKNOWN 0
|
||||
#define AILFILETYPE_PCM_WAV 1
|
||||
#define AILFILETYPE_ADPCM_WAV 2
|
||||
#define AILFILETYPE_OTHER_WAV 3
|
||||
#define AILFILETYPE_VOC 4
|
||||
#define AILFILETYPE_MIDI 5
|
||||
#define AILFILETYPE_XMIDI 6
|
||||
#define AILFILETYPE_XMIDI_DLS 7
|
||||
#define AILFILETYPE_XMIDI_MLS 8
|
||||
#define AILFILETYPE_DLS 9
|
||||
#define AILFILETYPE_MLS 10
|
||||
#define AILFILETYPE_MPEG_L1_AUDIO 11
|
||||
#define AILFILETYPE_MPEG_L2_AUDIO 12
|
||||
#define AILFILETYPE_MPEG_L3_AUDIO 13
|
||||
|
||||
// AIL_file_read(filename, FILE_READ_WITH_SIZE): the returned block starts with the file size as a U32.
|
||||
#define FILE_READ_WITH_SIZE ((void*)(intptr_t)-1)
|
||||
|
||||
#define AIL_FILE_SEEK_BEGIN 0
|
||||
#define AIL_FILE_SEEK_CURRENT 1
|
||||
#define AIL_FILE_SEEK_END 2
|
||||
|
||||
typedef struct _AILSOUNDINFO
|
||||
{
|
||||
S32 format;
|
||||
void const* data_ptr;
|
||||
U32 data_len;
|
||||
U32 rate;
|
||||
S32 bits;
|
||||
S32 channels;
|
||||
U32 samples;
|
||||
U32 block_size;
|
||||
void const* initial_ptr;
|
||||
} AILSOUNDINFO;
|
||||
|
||||
typedef U32 (AILCALLBACK* AIL_file_open_callback)(char const* filename, U32* file_handle);
|
||||
typedef void (AILCALLBACK* AIL_file_close_callback)(U32 file_handle);
|
||||
typedef S32 (AILCALLBACK* AIL_file_seek_callback)(U32 file_handle, S32 offset, U32 type);
|
||||
typedef U32 (AILCALLBACK* AIL_file_read_callback)(U32 file_handle, void* buffer, U32 bytes);
|
||||
typedef S32 (AILCALLBACK* AILLENGTHYCB)(U32 state, uintptr_t user);
|
||||
|
||||
// System
|
||||
S32 AIL_startup();
|
||||
void AIL_shutdown();
|
||||
char* AIL_set_redist_directory(char const* dir);
|
||||
char* AIL_last_error();
|
||||
HDIGDRIVER AIL_open_digital_driver(U32 frequency, S32 bits, S32 channel, U32 flags);
|
||||
void AIL_close_digital_driver(HDIGDRIVER dig);
|
||||
|
||||
// Files and memory
|
||||
void AIL_set_file_callbacks(AIL_file_open_callback opencb, AIL_file_close_callback closecb,
|
||||
AIL_file_seek_callback seekcb, AIL_file_read_callback readcb);
|
||||
void* AIL_file_read(char const* filename, void* dest);
|
||||
S32 AIL_file_type(void const* data, U32 size);
|
||||
S32 AIL_WAV_info(void const* data, AILSOUNDINFO* info);
|
||||
S32 AIL_decompress_ADPCM(AILSOUNDINFO const* info, void** outdata, U32* outsize);
|
||||
S32 AIL_decompress_ASI(void const* indata, U32 insize, char const* filename_ext, void** outdata, U32* outsize,
|
||||
AILLENGTHYCB callback);
|
||||
void AIL_mem_free_lock(void* ptr);
|
||||
|
||||
// 2D samples
|
||||
HSAMPLE AIL_allocate_sample_handle(HDIGDRIVER dig);
|
||||
void AIL_release_sample_handle(HSAMPLE s);
|
||||
void AIL_init_sample(HSAMPLE s);
|
||||
S32 AIL_set_sample_file(HSAMPLE s, void const* file_image, S32 block);
|
||||
U32 AIL_sample_status(HSAMPLE s);
|
||||
void AIL_set_sample_loop_count(HSAMPLE s, S32 loop_count);
|
||||
void AIL_start_sample(HSAMPLE s);
|
||||
void AIL_stop_sample(HSAMPLE s);
|
||||
void AIL_resume_sample(HSAMPLE s);
|
||||
void AIL_end_sample(HSAMPLE s);
|
||||
void AIL_sample_volume_pan(HSAMPLE s, F32* volume, F32* pan);
|
||||
void AIL_set_sample_volume_pan(HSAMPLE s, F32 volume, F32 pan);
|
||||
|
||||
// 3D providers, listener and samples
|
||||
S32 AIL_enumerate_3D_providers(HPROENUM* next, HPROVIDER* dest, char** name);
|
||||
M3DRESULT AIL_open_3D_provider(HPROVIDER lib);
|
||||
void AIL_close_3D_provider(HPROVIDER lib);
|
||||
H3DPOBJECT AIL_open_3D_listener(HPROVIDER lib);
|
||||
void AIL_close_3D_listener(H3DPOBJECT listener);
|
||||
H3DSAMPLE AIL_allocate_3D_sample_handle(HPROVIDER lib);
|
||||
void AIL_release_3D_sample_handle(H3DSAMPLE s);
|
||||
S32 AIL_set_3D_sample_file(H3DSAMPLE s, void const* file_image);
|
||||
U32 AIL_3D_sample_status(H3DSAMPLE s);
|
||||
void AIL_set_3D_sample_loop_count(H3DSAMPLE s, U32 loops);
|
||||
void AIL_start_3D_sample(H3DSAMPLE s);
|
||||
void AIL_stop_3D_sample(H3DSAMPLE s);
|
||||
void AIL_resume_3D_sample(H3DSAMPLE s);
|
||||
void AIL_end_3D_sample(H3DSAMPLE s);
|
||||
F32 AIL_3D_sample_volume(H3DSAMPLE s);
|
||||
void AIL_set_3D_sample_volume(H3DSAMPLE s, F32 volume);
|
||||
void AIL_set_3D_position(H3DPOBJECT obj, F32 X, F32 Y, F32 Z);
|
||||
void AIL_set_3D_orientation(H3DPOBJECT obj, F32 X_face, F32 Y_face, F32 Z_face, F32 X_up, F32 Y_up, F32 Z_up);
|
||||
void AIL_set_3D_velocity(H3DPOBJECT obj, F32 dx_per_ms, F32 dy_per_ms, F32 dz_per_ms, F32 magnitude);
|
||||
void AIL_auto_update_3D_position(H3DPOBJECT obj, S32 enable);
|
||||
void AIL_update_3D_position(H3DPOBJECT obj, F32 dt_milliseconds);
|
||||
|
||||
// Streams
|
||||
HSTREAM AIL_open_stream(HDIGDRIVER dig, char const* filename, S32 stream_mem);
|
||||
void AIL_close_stream(HSTREAM stream);
|
||||
S32 AIL_stream_status(HSTREAM stream);
|
||||
void AIL_set_stream_loop_count(HSTREAM stream, S32 count);
|
||||
void AIL_start_stream(HSTREAM stream);
|
||||
void AIL_pause_stream(HSTREAM stream, S32 onoff);
|
||||
void AIL_stream_volume_levels(HSTREAM stream, F32* left_level, F32* right_level);
|
||||
void AIL_set_stream_volume_levels(HSTREAM stream, F32 left_level, F32 right_level);
|
||||
|
||||
Reference in New Issue
Block a user