내 목표는 엔진의 RPM을 사운드 피치에 연결하는 것입니다. 오디오 백엔드로 SDL을 사용하고 있습니다.SDL 오디오 피치 - 재생 속도
그래서 내 생각은 웨이브 버퍼에서 샘플을 정상보다 빨리했습니다. 그래서 흔적과 오류로 나는 내 엔진 소리를 "단계별로"피치 할 수있게되었습니다. 나는에서이 부분을 변경하는 경우
질문 # 1
는 :
audioBuff += 1 + pitch * 2;
audioBuff += 2
에 난 그냥 노이즈를 얻을. 왜? 이것은 스테레오 채널과 관련이 있습니까?
질문 # 2
가 어떻게이 선형 피치 할 수 ? 현재 그것은 "스테핑"피치입니다. AUDIO_S16
에 당신은 오디오 형식을 설정하는
#include "SDL2/SDL.h"
#include <iostream>
void audioCallback(void* userdata, Uint8 *stream, int len);
Uint8 *audioBuff = nullptr;
Uint8 *audioBuffEnd = nullptr;
Uint32 audioLen = 0;
bool quit = false;
Uint16 pitch = 0;
int main()
{
if(SDL_Init(SDL_INIT_AUDIO) < 0)
return -1;
Uint32 wavLen = 0;
Uint8 *wavBuff = nullptr;
SDL_AudioSpec wavSpec;
if(SDL_LoadWAV("test.wav", &wavSpec, &wavBuff, &wavLen) == nullptr)
{
return 1;
}
wavSpec.callback = audioCallback;
wavSpec.userdata = nullptr;
wavSpec.format = AUDIO_S16;
wavSpec.samples = 2048;
audioBuff = wavBuff;
audioBuffEnd = &wavBuff[wavLen];
audioLen = wavLen;
if(SDL_OpenAudio(&wavSpec, NULL) < 0)
{
fprintf(stderr, "Could not open audio: %s\n", SDL_GetError());
return 1;
}
SDL_PauseAudio(0);
while(!quit)
{
SDL_Delay(500);
pitch ++;
}
SDL_CloseAudio();
SDL_FreeWAV(wavBuff);
return 0;
}
Uint32 sampleIndex = 0;
void audioCallback(void* userdata, Uint8 *stream, int len)
{
Uint32 length = (Uint32)len;
length = (length > audioLen ? audioLen : length);
for(Uint32 i = 0; i < length; i++)
{
if(audioBuff > audioBuffEnd)
{
quit = true;
return;
}
// why pitch * 2?
// how to get a smooth pitch?
stream[i] = audioBuff[0];
audioBuff += 1 + pitch * 2;
fprintf(stdout, "pitch: %u\n", pitch);
}
}
"선형 피치"란 무엇을 의미합니까? – 1201ProgramAlarm
같은 질문을 스스로하겠습니다. @ 1201ProgramAlarm – Hydren
SDL_mixer의 Mix_Chunk에 음조를 적용 할 수 있습니까? – Hydren