ありがとうございます。
無事にPlaySoundの方で実装でき、
ストリーミング再生にしてロード時間も短くできました。
ところで、しばらく動かしていたところ、倍率によって、微妙に時間がずれてくることに気づきました。
そこで、以下のようなプログラムを書いたところ、
やはり1倍速以外では少しずつずれていくようです。
どうしてなのでしょうか?
#include "DxLib.h"
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow ){
ChangeWindowMode(TRUE);
SetAlwaysRunFlag(TRUE);
if( DxLib_Init() == -1 ){
return -1; // エラーが起きたら直ちに終了
}
int hSound = -1;
int timeStart;
double keyshift = 1.0;
int mode = 1;
int modeInt[3]={
DX_SOUNDDATATYPE_MEMNOPRESS,
DX_SOUNDDATATYPE_MEMPRESS,
DX_SOUNDDATATYPE_FILE,
};
char *modeStr[3]={
"DX_SOUNDDATATYPE_MEMNOPRESS",
"DX_SOUNDDATATYPE_MEMPRESS",
"DX_SOUNDDATATYPE_FILE",
};
while(1){
if( ProcessMessage() == -1 ){
break ;
}
SetDrawScreen(DX_SCREEN_BACK);
ClearDrawScreen();
char ch = GetInputChar(TRUE);
if(ch == CTRL_CODE_ESC){
break;
}
if(hSound != -1){
switch(ch){
case '1':
DeleteSoundMem(hSound);
hSound=-1;
keyshift=0.5;
break;
case '2':
DeleteSoundMem(hSound);
hSound=-1;
keyshift=0.75;
break;
case '3':
DeleteSoundMem(hSound);
hSound=-1;
keyshift=1.0;
break;
case '4':
DeleteSoundMem(hSound);
hSound=-1;
keyshift=1.5;
break;
case '5':
DeleteSoundMem(hSound);
hSound=-1;
keyshift=2.0;
break;
case 'q':
case 'Q':
DeleteSoundMem(hSound);
hSound=-1;
mode=0;
break;
case 'w':
case 'W':
DeleteSoundMem(hSound);
hSound=-1;
mode=1;
break;
case 'e':
case 'E':
DeleteSoundMem(hSound);
hSound=-1;
mode=2;
break;
}
}
char *text="再生速度変更: 1,2,3,4,5, 再生モード変更: Q,W,E";
DrawString(10, 10, text, GetColor(255, 255, 255));
DrawFormatString(10, 200, GetColor(255, 255, 255),
"再生速度: %4.2f 倍, モード: %s", keyshift, modeStr[mode]);
if(hSound != -1){
int a = GetNowCount() - timeStart;
int b = (GetSoundCurrentTime(hSound))/keyshift;
DrawFormatString(10, 100, GetColor(255, 255, 255),
"%2d (= %d-%d) ← 実測 - 再生位置/倍率", a - b, a, b);
}
ScreenFlip();
if(hSound == -1){
SetCreateSoundDataType(modeInt[mode]);
//hSound = LoadSoundMem("test.mp3");
hSound = LoadSoundMem("test.wav");
SetFrequencySoundMem(GetFrequencySoundMem(hSound)*keyshift, hSound);
PlaySoundMem(hSound, DX_PLAYTYPE_BACK);
timeStart = GetNowCount();
}
}
DxLib_End() ;
return 0 ;
}