0

我正在制作一个名为 XMusic 的音乐播放器,您可能从我在此处发布的另一个问题中了解到。如果你不这样做,我正在为 PC 和 Xbox 制作它(使用 nxdk),它使用 SDL_mixer 库。我的问题是它没有打开任何文件来播放它,但这是一个不同的问题。从昨天开始,我还遇到了一个问题,即在选择文件(甚至使用固定文件)后它只是冻结。这是一个包含上述两个问题的示例(来自这里和我的另一个问题)

#include <stdio.h>
#include <SDL.h>
#include <SDL_mixer.h>
#if defined (NXDK)
#include <video.h>
#endif

static int audio_open = 0;
static Mix_Music *music = NULL;
char* fileToPlay = "D:\\Pause Test.wav";

static void PlayFile() {

int audio_rate = 48000; //48KHz saves Xbox CPU time
Uint16 audio_format = AUDIO_S16LSB;
int audio_channels = 2; 
int audio_buffers = 4096;
int audio_volume = MIX_MAX_VOLUME;
int looping = 1;

if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
  printf("Couldn't open audio: %s\n", SDL_GetError());
} 
else {
  Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
  printf("Opened audio at %d Hz %d bit%s %s %d bytes audio buffer\n", audio_rate,
  (audio_format&0xFF), (SDL_AUDIO_ISFLOAT(audio_format) ? " (float)" : ""),
  (audio_channels > 2) ? "surround" : (audio_channels > 1) ? "stereo" : "mono",
  audio_buffers);
}
audio_open = 1;

printf("Setting volume\n");
Mix_VolumeMusic(audio_volume);
printf("Opening %s\n", fileToPlay);

SDL_RWops *rw = SDL_RWFromFile(fileToPlay, "rb");

if (rw == NULL) {
    printf("Couldn't open %s: %s\n",
    fileToPlay, Mix_GetError());
}
printf("Loading %s\n", fileToPlay);
music = Mix_LoadMUS_RW(rw, SDL_TRUE);
if (music == NULL) {
    printf("Couldn't load %s: %s\n",
    fileToPlay, Mix_GetError());
}
printf("Loaded %s\n", fileToPlay);
Mix_FadeInMusic(music, looping, 2000);
 }


int main() {

#if defined (NXDK)
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
#endif

SDL_Init(SDL_INIT_AUDIO|SDL_INIT_JOYSTICK);
Mix_Init(MIX_INIT_OGG|MIX_INIT_MP3);


PlayFile();

SDL_Delay(6000);

}

在 XQEMU(一个低级仿真器)上运行的 XMusic 的调试版本上运行 GDB 显示它被 SDL_mixer 的 3 个函数卡住了。Mix_HaltChannel()、Mix_QuerySpec() 和 Mix_AllocateChannels()。就像它正在循环所有这 3 个。

XMusic的完整代码:https://github.com/kosmas12/My-code-stuff/tree/nxdk/Music%20player%20(C)

4

0 回答 0