这让我很难过;这在单声道中非常有效,但是当我将其更改为立体声时,它听起来断断续续且静态。这是一个交错问题还是什么(数据是交错的,顺便说一句)
编辑:将交错方法更改为更合乎逻辑的方法,但仍然无济于事......
#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);
}