89 lines
2.3 KiB
C++
89 lines
2.3 KiB
C++
#pragma once
|
|
#include <string>
|
|
#include <dirent.h>
|
|
#include <map>
|
|
#include <stdio.h>
|
|
#include <SDL.h>
|
|
#include <SDL_mixer.h>
|
|
#include "Tool/Ifstream_NPK.h"
|
|
#include "Asset/Asset_Audio.hpp"
|
|
|
|
class Asset_SoundPack
|
|
{
|
|
public:
|
|
struct WAV
|
|
{
|
|
unsigned int offset; // 偏移
|
|
unsigned int size; // 大小
|
|
std::string lpWavName; // img文件的路径
|
|
std::string lpBelongsFile; // 这个img属于哪个npk文件
|
|
int img_index; // img文件在npk文件里的序号
|
|
};
|
|
|
|
struct NpkInfo
|
|
{
|
|
int Offset;
|
|
int Length;
|
|
std::string Path;
|
|
};
|
|
|
|
struct MusicInfo
|
|
{
|
|
/**上次使用时间 */
|
|
Uint64 LastUseTime;
|
|
/**音频指针 */
|
|
Mix_Chunk *lpMusic;
|
|
};
|
|
|
|
public:
|
|
Asset_SoundPack(const Asset_SoundPack &) = delete;
|
|
Asset_SoundPack &operator=(const Asset_SoundPack &) = delete;
|
|
Asset_SoundPack(Asset_SoundPack &&) = delete;
|
|
Asset_SoundPack &operator=(Asset_SoundPack &&) = delete;
|
|
// 全局访问点
|
|
static Asset_SoundPack &GetInstance()
|
|
{
|
|
static Asset_SoundPack instance; // 局部静态变量,保证只初始化一次
|
|
return instance;
|
|
}
|
|
|
|
/**音频NPK信息表 */
|
|
std::map<std::string, WAV> lp_arr;
|
|
/**音频储存表 */
|
|
std::map<std::string, MusicInfo> map_sound;
|
|
/**audio信息表 */
|
|
AudioConfigReader XmlConfig;
|
|
/**正在播放的背景音乐表 */
|
|
std::map<std::string, int> backgroud_music_map;
|
|
/**总通道数 */
|
|
int ChannelCount;
|
|
|
|
public:
|
|
Asset_SoundPack(/* args */);
|
|
~Asset_SoundPack();
|
|
|
|
void InitNpkList();
|
|
|
|
void Reclaims();
|
|
|
|
Mix_Chunk *GetOgg(const std::string &lpWavName);
|
|
|
|
/**播放音频 */
|
|
void PlayAudio(const std::string Key);
|
|
/**停止音频 */
|
|
void StopAudio(const std::string Key);
|
|
|
|
void PlayMusic(const std::string Key, const std::string oggpath);
|
|
void PlayEffect(const std::string Key, int Volume);
|
|
|
|
/**停止通道播放音频 */
|
|
void StopChannel(int Channel);
|
|
/**设置所有通道音量 */
|
|
void SetAllChannelVolume(int Volume);
|
|
/**获取正在播放的背景音乐 */
|
|
std::map<std::string, int> GetBackgroudMusicVector();
|
|
|
|
/**获取空闲的通道 */
|
|
int FindFreeChannelInRange(int Start, int End);
|
|
};
|