久しぶりに、実装を行う。
とりあえず、読み込んだ mp3 などを Fade in/out 可能で流せるようにしたり、読み込んだ wav を鳴らせるようにした。つか、SDL_mixer をクラスにしただけ。
ちゃんと動作した。いい感じ。
音楽を鳴らすサンプル
#include "soundPlay.h"
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc < 1) {
printf("usage:\n\t%s <music file>\n", argv[0]);
exit(1);
}
const char* music_file = argv[1];
SoundPlay* music = SoundPlay::getObject();
bool ret = music->load(music_file);
if (ret == false) {
printf("SoundPlay error\n");
exit(1);
}
music->play(true, 1000);
printf("playing...\n");
getchar();
music->stop(1000);
while (music->playing()) {
SDL_Delay(100);
}
return 0;
}
効果音を鳴らすサンプル
#include <stdio.h>
#include <stdlib.h>
#include "effectPlay.h"
int main(int argc, char *argv[]) {
if (argc < 1) {
printf("usage:\n\t%s <wav file>\n", argv[0]);
exit(1);
}
const char* wav_file = argv[1];
EffectPlay effect(wav_file);
printf("hit return key to play");
while (1) {
getchar();
printf("play");
effect.play();
}
}