I am making a lightweight opus audio player. This is my portaudio callback
function. But i hear a stammering song when i try to play a .opus song
file. Can anybody say what is wrong or provide me link to any code which
can play opus file written in c/c++(light). I tried to see some open
source(vlc opus play) but was unable to follow.
int MyCallback(const void* input,
void* output,
unsigned long frameCount,
const PaStreamCallbackTimeInfo* paInfo,
PaStreamCallbackFlags paCallbacks,
void *userData
)
{
OurData *data=(OurData*) userData;
opus_int16* out=(opus_int16 *)output;
int thisSize=frameCount;
int smpls_decoded;
while (thisSize>0)
{
smpls_decoded=op_read(data->sndFile,out,thisSize,NULL);
out+=data->channels*smpls_decoded;
thisSize-=data->channels*smpls_decoded;
}
return paContinue;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.xiph.org/pipermail/opus/attachments/20131205/236007a9/attachment.htm
Akshit Jain wrote:> I am making a lightweight opus audio player. This is my portaudio > callback function. But i hear a stammering song when i try to play a > .opus song file. Can anybody say what is wrong or provide me link to any > code which can play opus file written in c/c++(light). I tried to see > some open source(vlc opus play) but was unable to follow.See opusfile_example.c in the examples/ directory of libopusfile. On Linux, ./opusfile_example foo.opus | aplay makes a rudimentary player.> smpls_decoded=op_read(data->sndFile,out,thisSize,NULL);You're using op_read(), but ignoring the link number. This will do the wrong thing on chained files where the number of channels changes between links. You can use op_read_stereo() to get a fixed number (2) of channels out regardless of the number of channels in each link. You're also not handling error return values. That should not be a problem on properly encoded files, but it is a potential security vulnerability, since you're using the return value to do pointer arithmetic. What do your Pa_OpenStream() parameters look like?