這讓我很難過;這在單聲道中是完美的,但是當我將其改變爲立體聲時,它聽起來很波瀾不驚。這是一個交織問題,或者什麼(數據交錯,順便說一句)PortAudio - 適用於單聲道,立體聲故障?
編輯:改變了交織方法的東西更符合邏輯,但依然無果......
#include <pthread.h>
#include <portaudio/portaudio.h>
#include <sndfile.h>
#define STEREO 2
#define SAMPLE_RATE 44100
typedef struct{
M_float* data, *data_pos;
sf_count_t frames;
} StreamData;
StreamData stream_data;
int ProcessAudio(const void* input, void* output, ulong frames_per_buff,
const PaStreamCallbackTimeInfo* time_info, PaStreamCallbackFlags flags, void* strm_data){
M_StreamData* strm = (M_StreamData*)(strm_data);
M_float* strm_out = (M_float*)(output);
if(strm -> frames > frames_per_buff){
for(sf_count_t frames_iter = 0; frames_iter < frames_per_buff;){
M_float sample = (strm -> data_pos++)[0];
strm_out[frames_iter] = sample;
strm_out[++frames_iter] = sample;
}
}else{
return (paComplete);
}
return (paContinue);
}
void* StartAudio(void* params){
SF_INFO info;
info.channels = M_STEREO;
info.samplerate = M_SAMPLE_RATE;
info.format = SF_FORMAT_RAW | SF_FORMAT_FLOAT;
SNDFILE* file = sf_open(u8"californication.raw", SFM_READ, &info);
stream_data.data = malloc(info.frames * info.channels * sizeof(float));
stream_data.data_pos = stream_data.data;
stream_data.frames = sf_readf_float(file, stream_data.data, info.frames);
sf_close(file);
if(Pa_Initialize() != paNoError)exit(0);
PaStream* pa_stream = NULLPTR_T;
Pa_OpenDefaultStream(&pa_stream, 0, STEREO, paFloat32, SAMPLE_RATE, paFramesPerBufferUnspecified,
&ProcessAudio, &stream_data);
Pa_StartStream(pa_stream);
Pa_Sleep(9001);
Pa_StopStream(pa_stream);
Pa_CloseStream(pa_stream);
sf_close(file);
free(stream_data.data);
Pa_Terminate();
return (NULLPTR_T);
}
int main(void){
static pthread_t thrd;
pthread_create(&thrd, NULLPTR_T, &M_StartAudio, NULLPTR_T);
return (false);
}
什麼平臺(操作系統和版本)?什麼API? –
@bjorn roche:windows 8 x64,portaudio v19,MME聲音 – Shokwav