#include "SDL.h"
struct {
Uint8 *sound; // pointer to wave data
Uint32 soundlen; // length of wave data
int soundpos; // current play position
}wave;
int done;
static void quit(int rc)
{
SDL_Quit();
exit(rc);
}
void SDLCALL fill_audio(void *unused, Uint8 *stream, int len)
{
Uint8 *waveptr;
int waveleft;
int copylen;
SDL_memset(stream, 0, len);
if (wave.soundpos == wave.soundlen)
{
done = 1;
return;
}
waveptr = wave.sound + wave.soundpos;
waveleft = wave.soundlen - wave.soundpos;
waveleft <= len ? (copylen = waveleft) : (copylen = len);
SDL_memcpy(stream, waveptr, copylen);
wave.soundpos += copylen;
SDL_Log("len: %d, copylen:%d\n", len, copylen);
}
/*
SDL播放音频wave文件测试
*/
int audio_test()
{
SDL_AudioSpec spec;
const char * audio_file = "sample.wav";
SDL2.0学习笔记6--用SDL播放音频wave文件
最新推荐文章于 2024-09-11 16:40:56 发布
本文介绍了如何利用SDL2.0库播放wave音频文件,包括初始化音频子系统、打开wave文件、启动音频播放线程、填充音频数据以及播放结束后的资源释放步骤。
摘要由CSDN通过智能技术生成