pspAudio and my emulator.

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
HexDump
Posts: 70
Joined: Tue Jun 07, 2005 9:18 pm

pspAudio and my emulator.

Post by HexDump »

Hi,

I know this could be the wrong place to ask about this, but I didn´t find any better place, so here we are:


I have a little problem with my emulator and sound. I´m using pspAudioLib to output the sound from my emulator. I have a callback that is called by the psp when he needs the channel to be feed with new samples, ok, here comes the problem, there are a lot of times, where the psp asks for a number of samples to be written but the emulator has not produced such quantity, so glitches are heard all along.

How do peopple avoid this problem?.

Thanks in advance,
HexDump.
RCON
Posts: 16
Joined: Wed Aug 03, 2005 1:02 am
Contact:

Post by RCON »

I am using a similar callback and I reset the audio buffer to 0 and then return if a sound is not playing. It looks something like this:

Code: Select all

if (!soundplaying) {
  for &#40;i=0; i<length; ++i&#41; &#123;
    buf&#91;i * 2&#93;     = 0;
    buf&#91;i * 2 + 1&#93; = 0;
  &#125;
  return;
&#125;
// Continue processing your audio if a sound is playing
I'm not sure how you fill your audio buffer but this method worked for me.
HexDump
Posts: 70
Joined: Tue Jun 07, 2005 9:18 pm

Post by HexDump »

Yes, I use the same method (Well, I don´t check if a sound is playing because I allways write into the buffer what emulator says, if no sound emulator outs 0's).

The problem is that a lot of times I can´t fill the psp audio buffer with "length" samples, because my emulator has produced less than that.


Example: pspAudio hsa a buffer of 1024 samples by default, so when the callback is called it asks for 1024 samples -> length=1024. Then problem is that my emulator only has produced for example 800, there are 124 missing.

Thanks in advance,
HexDump.
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

The problem is, the emulator's not running fast enough. It has to produce at least 1024 samples to fill that buffer. If it's done more than 1024 then the emulation is going too fast. There's not a lot you can do about that, except turn everything on its head - ie. inside the callback from the audio device, run the emulation until it produces 1024 samples. Depending on how long that takes it will give you more or less problems and better or worse clicking.

Jim
RCON
Posts: 16
Joined: Wed Aug 03, 2005 1:02 am
Contact:

Post by RCON »

my program gets audio artifacts too when I try to do a lot of calculations and can't fill the buffer. I optimized a lot of my code using tips from this site and it helped a lot. I was doing a lot of calculations/loops when I didn't need to.

http://bdn.borland.com/article/0,1410,28278,00.html

make sure you optimize one part of your code and then test it, if you try to do too much at once you could break it and not know where the problem is.
HexDump
Posts: 70
Joined: Tue Jun 07, 2005 9:18 pm

Post by HexDump »

Thanks to everyone answering, the problem was that I did calculations by hand, and I was executing less cycles by frame than I should.

Sorry to waste your time mates, and thanks again.


HexDump.
Post Reply