audio sample

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

Moderators: cheriff, TyRaNiD

Post Reply
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

audio sample

Post by JJPeerless »

can someone write up a quick audio sample for the sdk or for me =) and the rest of the forums..

ONLY have it just play a wav/mp3 whatever filetype psp can play.. i dont know yet..

no text to screen, nothing at all..

when you run the rpogram, it just plays the audio..

thats all i want to see..keep it simple.
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

It's in SVN. Either checkout the PSPSDK of svn, or go to the html page of the audio here
Lego of my Ago!
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

Post by JJPeerless »

those 2 samples "wavegen" and "polyphonic" dont load a wav file or mp3 file or something..

is that possible?
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

Yes, just write the code to do it.

For wav files, start at www.wotsit.org ;P
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

Post by JJPeerless »

bleh, seems like too much work =)


how about
int wavFile;
wavFile =pspLoadWavFile("ms0:/fittycent.wav");
wavFile.play();
wavFile.stop();

there. i wrote it =) (i wish i couild do something easy like that)
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

JJPeerless wrote:those 2 samples "wavegen" and "polyphonic" dont load a wav file or mp3 file or something..

is that possible?
We would welcome a simple wave loader/player - but anything above that would be a bit complicated for a PSPSDK sample.
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

JJPeerless wrote:bleh, seems like too much work =)


how about
int wavFile;
wavFile =pspLoadWavFile("ms0:/fittycent.wav");
wavFile.play();
wavFile.stop();

there. i wrote it =) (i wish i couild do something easy like that)
that wouldn't even compile!!!!! integers dont have functions in them, and the c programming language doesnt have OOP (well, technically it does with function pointers, but the wavFile isn't a struct...)

it would have to be something like this:

typedef struct {
[some function pointer] open;
[some function poitner] play;
[some function pointer] stop;
} media;

media wavFile;

wavFile.open("file");
wavFile.play();
wavFile.stop();

:-P

I think what he's trying to say is that there is not built-in function to just "load a file", you have to go thru the wav file and play it as you are reading it.
Lego of my Ago!
KprOfTime
Posts: 3
Joined: Mon Jun 27, 2005 3:34 pm

Post by KprOfTime »

I was working on a Memory game to learn how to do graphics, sound, input and IO. All of it was before the SDK was released, and I stopped working on it at that point, as everything was obsolete. This is some code I put together from various places to load WAV files and play them, and I'm sure it could be adapted to be used with the SDK functions:

sound.c

Code: Select all

#define PGA_CHANNELS 3
#define PGA_SAMPLES 256
#define MAXVOLUME 0x8000
#define SND1_MAXSLOT 16
#define PB_N 32
#define WAVFILEMAX_BG 8*1024*1024
#define O_RDONLY    0x0001 
#define O_WRONLY    0x0002 
#define O_RDWR      0x0003 
#define O_NBLOCK    0x0010 
#define O_APPEND    0x0100 
#define O_CREAT     0x0200 
#define O_TRUNC     0x0400 
#define O_NOWAIT    0x8000 
#define MAX_PATH 512
//---------- variables
int pga_ready=0;
int pga_handle[PGA_CHANNELS];
short pga_sndbuf[PGA_CHANNELS][2][PGA_SAMPLES][2];
int pga_threadhandle[PGA_CHANNELS];
volatile int pga_terminate=0;

typedef int (*pg_threadfunc_t)(int args, void *argp);

typedef struct {
	unsigned long channels;
	unsigned long samplerate;
	unsigned long samplecount;
	unsigned long datalength;
	char *wavdata;
	unsigned long rateratio;		// samplerate / 44100 * 0x10000
	unsigned long playptr;
	unsigned long playptr_frac;
	int playloop;
} wavout_wavinfo_t;

wavout_wavinfo_t *wavout_snd0_wavinfo=0;
wavout_wavinfo_t wavout_snd1_wavinfo[SND1_MAXSLOT];

int wavout_snd1_playing[SND1_MAXSLOT];


int wavout_snd0_ready=0;
unsigned long wavout_snd0_playptr=0;
int wavout_snd0_playend=0;


short powerbuf[PB_N][256];
unsigned int powerbuf_in=0;

short powersrc[256];
short powersrc2[256];


char wavdata_bg[WAVFILEMAX_BG];
wavout_wavinfo_t wavinfo_bg;
char pg_mypath[MAX_PATH];
char pg_workdir[MAX_PATH];

//------------ Tableau de merde
int brtbl[]={
  0,128, 64,192, 32,160, 96,224, 16,144, 80,208, 48,176,112,240,  8,136, 72,200, 40,168,104,232, 24,152, 88,216, 56,184,120,248,
  4,132, 68,196, 36,164,100,228, 20,148, 84,212, 52,180,116,244, 12,140, 76,204, 44,172,108,236, 28,156, 92,220, 60,188,124,252,
  2,130, 66,194, 34,162, 98,226, 18,146, 82,210, 50,178,114,242, 10,138, 74,202, 42,170,106,234, 26,154, 90,218, 58,186,122,250,
  6,134, 70,198, 38,166,102,230, 22,150, 86,214, 54,182,118,246, 14,142, 78,206, 46,174,110,238, 30,158, 94,222, 62,190,126,254,
  1,129, 65,193, 33,161, 97,225, 17,145, 81,209, 49,177,113,241,  9,137, 73,201, 41,169,105,233, 25,153, 89,217, 57,185,121,249,
  5,133, 69,197, 37,165,101,229, 21,149, 85,213, 53,181,117,245, 13,141, 77,205, 45,173,109,237, 29,157, 93,221, 61,189,125,253,
  3,131, 67,195, 35,163, 99,227, 19,147, 83,211, 51,179,115,243, 11,139, 75,203, 43,171,107,235, 27,155, 91,219, 59,187,123,251,
  7,135, 71,199, 39,167,103,231, 23,151, 87,215, 55,183,119,247, 15,143, 79,207, 47,175,111,239, 31,159, 95,223, 63,191,127,255,
};

int mm1[8][128]={
{  16384,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{  16384,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{  16384, 11585,     0,-11585,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{  16384, 15136, 11585,  6269,     0, -6269,-11585,-15136,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{  16384, 16069, 15136, 13622, 11585,  9102,  6269,  3196,     0, -3196, -6269, -9102,-11585,-13622,-15136,-16069,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{  16384, 16305, 16069, 15678, 15136, 14449, 13622, 12665, 11585, 10393,  9102,  7723,  6269,  4756,  3196,  1605,     0, -1605, -3196, -4756, -6269, -7723, -9102,-10393,-11585,-12665,-13622,-14449,-15136,-15678,-16069,-16305,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{  16384, 16364, 16305, 16206, 16069, 15892, 15678, 15426, 15136, 14810, 14449, 14053, 13622, 13159, 12665, 12139, 11585, 11002, 10393,  9759,  9102,  8423,  7723,  7005,  6269,  5519,  4756,  3980,  3196,  2404,  1605,   803,     0,  -803, -1605, -2404, -3196, -3980, -4756, -5519, -6269, -7005, -7723, -8423, -9102, -9759,-10393,-11002,-11585,-12139,-12665,-13159,-13622,-14053,-14449,-14810,-15136,-15426,-15678,-15892,-16069,-16206,-16305,-16364,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{  16384, 16379, 16364, 16339, 16305, 16260, 16206, 16142, 16069, 15985, 15892, 15790, 15678, 15557, 15426, 15286, 15136, 14978, 14810, 14634, 14449, 14255, 14053, 13842, 13622, 13395, 13159, 12916, 12665, 12406, 12139, 11866, 11585, 11297, 11002, 10701, 10393, 10079,  9759,  9434,  9102,  8765,  8423,  8075,  7723,  7366,  7005,  6639,  6269,  5896,  5519,  5139,  4756,  4369,  3980,  3589,  3196,  2801,  2404,  2005,  1605,  1205,   803,   402,     0,  -402,  -803, -1205, -1605, -2005, -2404, -2801, -3196, -3589, -3980, -4369, -4756, -5139, -5519, -5896, -6269, -6639, -7005, -7366, -7723, -8075, -8423, -8765, -9102, -9434, -9759,-10079,-10393,-10701,-11002,-11297,-11585,-11866,-12139,-12406,-12665,-12916,-13159,-13395,-13622,-13842,-14053,-14255,-14449,-14634,-14810,-14978,-15136,-15286,-15426,-15557,-15678,-15790,-15892,-15985,-16069,-16142,-16206,-16260,-16305,-16339,-16364,-16379, },
};
int mm2[8][128]={
{      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{      0,-16384,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{      0,-11585,-16384,-11585,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{      0, -6269,-11585,-15136,-16383,-15136,-11585, -6269,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{      0, -3196, -6269, -9102,-11585,-13622,-15136,-16069,-16383,-16069,-15136,-13622,-11585, -9102, -6269, -3196,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{      0, -1605, -3196, -4756, -6269, -7723, -9102,-10393,-11585,-12665,-13622,-14449,-15136,-15678,-16069,-16305,-16384,-16305,-16069,-15678,-15136,-14449,-13622,-12665,-11585,-10393, -9102, -7723, -6269, -4756, -3196, -1605,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{      0,  -803, -1605, -2404, -3196, -3980, -4756, -5519, -6269, -7005, -7723, -8423, -9102, -9759,-10393,-11002,-11585,-12139,-12665,-13159,-13622,-14053,-14449,-14810,-15136,-15426,-15678,-15892,-16069,-16206,-16305,-16364,-16384,-16364,-16305,-16206,-16069,-15892,-15678,-15426,-15136,-14810,-14449,-14053,-13622,-13159,-12665,-12139,-11585,-11002,-10393, -9759, -9102, -8423, -7723, -7005, -6269, -5519, -4756, -3980, -3196, -2404, -1605,  -803,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, },
{      0,  -402,  -803, -1205, -1605, -2005, -2404, -2801, -3196, -3589, -3980, -4369, -4756, -5139, -5519, -5896, -6269, -6639, -7005, -7366, -7723, -8075, -8423, -8765, -9102, -9434, -9759,-10079,-10393,-10701,-11002,-11297,-11585,-11866,-12139,-12406,-12665,-12916,-13159,-13395,-13622,-13842,-14053,-14255,-14449,-14634,-14810,-14978,-15136,-15286,-15426,-15557,-15678,-15790,-15892,-15985,-16069,-16142,-16206,-16260,-16305,-16339,-16364,-16379,-16384,-16379,-16364,-16339,-16305,-16260,-16206,-16142,-16069,-15985,-15892,-15790,-15678,-15557,-15426,-15286,-15136,-14978,-14810,-14634,-14449,-14255,-14053,-13842,-13622,-13395,-13159,-12916,-12665,-12406,-12139,-11866,-11585,-11297,-11002,-10701,-10393,-10079, -9759, -9434, -9102, -8765, -8423, -8075, -7723, -7366, -7005, -6639, -6269, -5896, -5519, -5139, -4756, -4369, -3980, -3589, -3196, -2801, -2404, -2005, -1605, -1205,  -803,  -402, },
};

const unsigned char sqrtbl[]={
	  0,   1,   1,   1,   2,   2,   2,   2,   2,   3,   3,   3,   3,   3,   3,   3,
	  4,   4,   4,   4,   4,   4,   4,   4,   4,   5,   5,   5,   5,   5,   5,   5,
	  5,   5,   5,   5,   6,   6,   6,   6,   6,   6,   6,   6,   6,   6,   6,   6,
	  6,   7,   7,   7,   7,   7,   7,   7,   7,   7,   7,   7,   7,   7,   7,   7,
	  8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,
	  8,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,
	  9,   9,   9,   9,  10,  10,  10,  10,  10,  10,  10,  10,  10,  10,  10,  10,
	 10,  10,  10,  10,  10,  10,  10,  10,  10,  11,  11,  11,  11,  11,  11,  11,
	 11,  11,  11,  11,  11,  11,  11,  11,  11,  11,  11,  11,  11,  11,  11,  11,
	 12,  12,  12,  12,  12,  12,  12,  12,  12,  12,  12,  12,  12,  12,  12,  12,
	 12,  12,  12,  12,  12,  12,  12,  12,  12,  13,  13,  13,  13,  13,  13,  13,
	 13,  13,  13,  13,  13,  13,  13,  13,  13,  13,  13,  13,  13,  13,  13,  13,
	 13,  13,  13,  13,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,
	 14,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,  14,
	 14,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,
	 15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,  15,
	};
//---------- proto
int pgaInit();
void (*pga_channel_callback[PGA_CHANNELS])(void *buf, unsigned long reqn);
static int pga_channel_thread(int args, void *argp);
void pga_channel_thread_callback(int channel, void *buf, unsigned long reqn);
void pgaSetChannelCallback(int channel, void *callback);
int pgaOutBlocking(unsigned long channel,unsigned long vol1,unsigned long vol2,void *buf);

static void wavout_snd0_callback(short *_buf, unsigned long _reqn);
static void wavout_snd1_callback(short *_buf, unsigned long _reqn);
void powercalc(short *in);
unsigned long sqri(unsigned long d);
int wavoutLoadWav(const char *filename, wavout_wavinfo_t *wi, void *buf, unsigned long buflen);

int pgfOpen(const char *filename, unsigned long flag);
void pgfClose(int fd);
int pgfRead(int fd, void *data, int size);

void wavoutStopPlay0();
void wavoutStartPlay0(wavout_wavinfo_t *wi);

//---------- function
int pgaInit()
{
	int i,ret;
	int failed=0;
	char str[32];

	pga_terminate=0;
	pga_ready=0;

	for &#40;i=0; i<PGA_CHANNELS; i++&#41; &#123;
		pga_handle&#91;i&#93;=-1;
		pga_threadhandle&#91;i&#93;=-1;
		pga_channel_callback&#91;i&#93;=0;
	&#125;
	for &#40;i=0; i<PGA_CHANNELS; i++&#41; &#123;
		if &#40;&#40;pga_handle&#91;i&#93;=sceAudioChReserve&#40;-1,PGA_SAMPLES,0&#41;&#41;<0&#41; failed=1;
	&#125;
	if &#40;failed&#41; &#123;
		for &#40;i=0; i<PGA_CHANNELS; i++&#41; &#123;
			if &#40;pga_handle&#91;i&#93;!=-1&#41; sceAudioChRelease&#40;pga_handle&#91;i&#93;&#41;;
			pga_handle&#91;i&#93;=-1;
		&#125;
		return -1;
	&#125;
	pga_ready=1;

	_strcpy&#40;str,"pgasnd0"&#41;;
	for &#40;i=0; i<PGA_CHANNELS; i++&#41; &#123;
		str&#91;6&#93;='0'+i;
		pga_threadhandle&#91;i&#93;=sceKernelCreateThread&#40;str,&#40;pg_threadfunc_t&#41;&pga_channel_thread,0x12,0x10000,0,NULL&#41;;
		if &#40;pga_threadhandle&#91;i&#93;<0&#41; &#123;
			pga_threadhandle&#91;i&#93;=-1;
			failed=1;
			break;
		&#125;
		ret=sceKernelStartThread&#40;pga_threadhandle&#91;i&#93;,sizeof&#40;i&#41;,&i&#41;;
		if &#40;ret!=0&#41; &#123;
			failed=1;
			break;
		&#125;
	&#125;
	if &#40;failed&#41; &#123;
		pga_terminate=1;
		for &#40;i=0; i<PGA_CHANNELS; i++&#41; &#123;
			if &#40;pga_threadhandle&#91;i&#93;!=-1&#41; &#123;
				sceKernelWaitThreadEnd&#40;pga_threadhandle&#91;i&#93;,NULL&#41;;
				sceKernelDeleteThread&#40;pga_threadhandle&#91;i&#93;&#41;;
			&#125;
			pga_threadhandle&#91;i&#93;=-1;
		&#125;
		pga_ready=0;
		return -1;
	&#125;
	return 0;
&#125;

static int pga_channel_thread&#40;int args, void *argp&#41;
&#123;
	volatile int bufidx=0;
	int channel=*&#40;int *&#41;argp;
	
	while &#40;pga_terminate==0&#41; &#123;
		void *bufptr=&pga_sndbuf&#91;channel&#93;&#91;bufidx&#93;;
		void &#40;*callback&#41;&#40;void *buf, unsigned long reqn&#41;;
		callback=pga_channel_callback&#91;channel&#93;;
		if &#40;callback&#41; &#123;
			callback&#40;bufptr,PGA_SAMPLES&#41;;
		&#125; else &#123;
			unsigned long *ptr=bufptr;
			int i;
			for &#40;i=0; i<PGA_SAMPLES; ++i&#41; *&#40;ptr++&#41;=0;
		&#125;
		pgaOutBlocking&#40;channel,0x8000,0x8000,bufptr&#41;;
		bufidx=&#40;bufidx?0&#58;1&#41;;
	&#125;
	sceKernelExitThread&#40;0&#41;;
	return 0;
&#125;


void pga_channel_thread_callback&#40;int channel, void *buf, unsigned long reqn&#41;
&#123;
	void &#40;*callback&#41;&#40;void *buf, unsigned long reqn&#41;;
	callback=pga_channel_callback&#91;channel&#93;;
&#125;


void pgaSetChannelCallback&#40;int channel, void *callback&#41;
&#123;
	pga_channel_callback&#91;channel&#93;=callback;
&#125;

int pgaOutBlocking&#40;unsigned long channel,unsigned long vol1,unsigned long vol2,void *buf&#41;
&#123;
	if &#40;!pga_ready&#41; return -1;
	if &#40;channel>=PGA_CHANNELS&#41; return -1;
	if &#40;vol1>MAXVOLUME&#41; vol1=MAXVOLUME;
	if &#40;vol2>MAXVOLUME&#41; vol2=MAXVOLUME;
	return sceAudioOutputPannedBlocking&#40;pga_handle&#91;channel&#93;,vol1,vol2,buf&#41;;
&#125;

int wavoutInit&#40;&#41;
&#123;
	int i;
	
	wavout_snd0_wavinfo=0;
	
	for &#40;i=0; i<SND1_MAXSLOT; i++&#41; &#123;
		wavout_snd1_playing&#91;i&#93;=0;
	&#125;

	pgaSetChannelCallback&#40;0,wavout_snd0_callback&#41;;
	pgaSetChannelCallback&#40;1,wavout_snd1_callback&#41;;
	return 0;
&#125;

static void wavout_snd0_callback&#40;short *_buf, unsigned long _reqn&#41;
&#123;
	static int power&#91;128&#93;;
	
	unsigned long i;
	unsigned long ptr,frac,rr,max;
	int channels;
	char *src;
	short *buf=_buf;
	unsigned long reqn=_reqn;
	
	wavout_wavinfo_t *wi=wavout_snd0_wavinfo;

	if &#40;wi==0&#41; &#123;
		wavout_snd0_ready=1;
		_memset&#40;buf,0,reqn*4&#41;;
		return;
	&#125;
	
	wavout_snd0_ready=0;
	
	ptr=wi->playptr;
	frac=wi->playptr_frac;
	rr=wi->rateratio;
	max=wi->samplecount;
	channels=wi->channels;
	src=wi->wavdata;

	for &#40;; reqn>0; --reqn&#41; &#123;
		frac+=rr;
		ptr+=&#40;frac>>16&#41;;
		frac&=0xffff;
		if &#40;ptr>=max&#41; &#123;
			if &#40;wi->playloop&#41; &#123;
				ptr=0;
			&#125; else &#123;
				for &#40;; reqn>0; --reqn&#41; &#123;
					*&#40;buf++&#41;=0;
					*&#40;buf++&#41;=0;
				&#125;
				goto playend;
			&#125;
		&#125;
		if &#40;channels==1&#41; &#123;
			buf&#91;0&#93;=buf&#91;1&#93;=*&#40;short *&#41;&#40;src+ptr*2&#41;;
			buf+=2;
		&#125; else &#123;
			buf&#91;0&#93;=*&#40;short *&#41;&#40;src+ptr*4&#41;;
			buf&#91;1&#93;=*&#40;short *&#41;&#40;src+ptr*4+2&#41;;
			buf+=2;
		&#125;
	&#125;

	powercalc&#40;_buf&#41;;	//’P‚Éwave‚ð�o‚·‚¾‚¯‚È‚ç•s—v

	wavout_snd0_playptr=ptr;
	wi->playptr=ptr;
	wi->playptr_frac=frac;
	return;
	
playend&#58;
	wavout_snd0_playend=1;
	return;
&#125;

static void wavout_snd1_callback&#40;short *_buf, unsigned long _reqn&#41;
&#123;
	unsigned long i,slot;
	wavout_wavinfo_t *wi;
	unsigned long ptr,frac;
	short *buf=_buf;
	
	for &#40;i=0; i<_reqn; i++&#41; &#123;
		int outr=0,outl=0;
		for &#40;slot=0; slot<SND1_MAXSLOT; slot++&#41; &#123;
			if &#40;!wavout_snd1_playing&#91;slot&#93;&#41; continue;
			wi=&wavout_snd1_wavinfo&#91;slot&#93;;
			frac=wi->playptr_frac+wi->rateratio;
			wi->playptr=ptr=wi->playptr+&#40;frac>>16&#41;;
			wi->playptr_frac=&#40;frac&0xffff&#41;;
			if &#40;ptr>=wi->samplecount&#41; &#123;
				wavout_snd1_playing&#91;slot&#93;=0;
				break;
			&#125;
			short *src=&#40;short *&#41;wi->wavdata;
			if &#40;wi->channels==1&#41; &#123;
				outl+=src&#91;ptr&#93;;
				outr+=src&#91;ptr&#93;;
			&#125; else &#123;
				outl+=src&#91;ptr*2&#93;;
				outr+=src&#91;ptr*2+1&#93;;
			&#125;
		&#125;
		if &#40;outl<-32768&#41; outl=-32768;
		else if &#40;outl>32767&#41; outl=32767;
		if &#40;outr<-32768&#41; outr=-32768;
		else if &#40;outr>32767&#41; outr=32767;
		*&#40;buf++&#41;=outl;
		*&#40;buf++&#41;=outr;
	&#125;
&#125;

unsigned long sqri&#40;unsigned long d&#41;
&#123;
	unsigned char c;
	unsigned long r;
	
	
	if &#40;d==0&#41; return 0;
	r=	&#40;c=sqrtbl&#91;&#40;&#40;unsigned char *&#41;&d&#41;&#91;3&#93;&#93;&#41;?&#40;&#40;unsigned long&#41;c<<12&#41;&#58;&#40;
		&#40;c=sqrtbl&#91;&#40;&#40;unsigned char *&#41;&d&#41;&#91;2&#93;&#93;&#41;?&#40;&#40;unsigned long&#41;c<<8&#41;&#58;&#40;
		&#40;c=sqrtbl&#91;&#40;&#40;unsigned char *&#41;&d&#41;&#91;1&#93;&#93;&#41;?&#40;&#40;unsigned long&#41;c<<4&#41;&#58;&#40;
		sqrtbl&#91;&#40;&#40;unsigned char *&#41;&d&#41;&#91;0&#93;&#93; &#41;&#41;&#41;;
	r=&#40;d/r+r&#41;>>1;
	r=&#40;d/r+r&#41;>>1;
	r=&#40;d/r+r&#41;>>1;
	r=&#40;d/r+r&#41;>>1;
	return r;

&#125;

void powercalc&#40;short *in&#41;
&#123;
	&#123;//work with sources
		int i,j,sum;
		for &#40;i=0; i<256-16; i++&#41; powersrc&#91;i&#93;=powersrc&#91;i+16&#93;;
		sum=0;
		for &#40;i=0; i<16; i++&#41; &#123;
			powersrc&#91;256-16+i&#93;=&#40; &#40;int&#41;in&#91;i*32&#93;+&#40;int&#41;in&#91;i*32+8&#93;+&#40;int&#41;in&#91;i*32+16&#93;+&#40;int&#41;in&#91;i*32+24&#93; &#41;/4;
		&#125;
	&#125;
	&#123;
		int i;
		for &#40;i=0; i<256; i++&#41; powersrc2&#91;i&#93;=powersrc&#91;i&#93;;
		for &#40;i=0; i<32; i++&#41; &#123;
			powersrc2&#91;i&#93;=&#40;&#40;int&#41;powersrc2&#91;i&#93;&#41;*i/32;
			powersrc2&#91;255-i&#93;=&#40;&#40;int&#41;powersrc2&#91;255-i&#93;&#41;*i/32;
		&#125;
	&#125;
	
	long m=8;
	long n=256;

	long m1,m2;

	long i,i1,j,k,i2,l,l1,l2;

	int ix&#91;256&#93;,iy&#91;256&#93;;
	int tx,ty,pw;

	//shuffle
	for &#40;i=0; i<256; i++&#41; &#123;
		ix&#91;i&#93;=&#40;int&#41;&#40;powersrc2&#91;brtbl&#91;i&#93;&#93;>>1&#41;;
		iy&#91;i&#93;=0;
	&#125;

	//fft main
	l2 = 1;
	for &#40;l=0; l<8; l++&#41; &#123;
		l1 = l2;
		l2 <<= 1;
		for &#40;j=0; j<l1; j++&#41; &#123;
			m1=mm1&#91;l&#93;&#91;j&#93;/64;
			m2=mm2&#91;l&#93;&#91;j&#93;/64;
			for &#40;i=j; i<n; i+=l2&#41; &#123;
				i1 = i + l1;
				tx = &#40; m1 * ix&#91;i1&#93; - m2 * iy&#91;i1&#93; &#41;/256;
				ty = &#40; m1 * iy&#91;i1&#93; + m2 * ix&#91;i1&#93; &#41;/256;
				ix&#91;i1&#93; = ix&#91;i&#93; - tx; 
				iy&#91;i1&#93; = iy&#91;i&#93; - ty;
				ix&#91;i&#93; += tx;
				iy&#91;i&#93; += ty;
			&#125;
		&#125;
	&#125;

	//scale & normalize
	short *pp=powerbuf&#91;powerbuf_in&#93;;
	for &#40;i=0; i<128; i++&#41; &#123;
		//tx,ty &#58; re,im  forward fft scaling=256, fixed point +-16384
		tx=ix&#91;i&#93;/256;
		ty=iy&#91;i&#93;/256;
		pw=&#40;sqri&#40;tx*tx+ty*ty&#41;&#41;;
		//normalize it 
		pw=pw*&#40;j+8&#41;/512;
		if &#40;pw>127&#41; pw=127;
		*&#40;pp++&#41;=pw;
	&#125;
	powerbuf_in=&#40;&#40;powerbuf_in+1&#41;&&#40;PB_N-1&#41;&#41;;

   return;
&#125;

int wavoutLoadWav&#40;const char *filename, wavout_wavinfo_t *wi, void *buf, unsigned long buflen&#41;
&#123;
	unsigned int filelen;
	int fd;
	unsigned long channels;
	unsigned long samplerate;
	unsigned long blocksize;
	unsigned long bitpersample;
	unsigned long datalength;
	unsigned long samplecount;
	unsigned long i;
	
	char *wavfile=buf;
	wi->wavdata=NULL;

	fd=pgfOpen&#40;filename,O_RDONLY&#41;;
	if &#40;fd<0&#41; return -1;
	
	filelen=pgfRead&#40;fd,wavfile,buflen&#41;;
	pgfClose&#40;fd&#41;;
	if &#40;filelen>=buflen&#41; &#123;
		//too long
		return -1;
	&#125;
	
	if &#40;_memcmp&#40;wavfile,"RIFF",4&#41;!=0&#41; &#123;
//		pgcPuts&#40;"format err"&#41;;
		return -1;
	&#125;
	
	if &#40;_memcmp&#40;wavfile+8,"WAVEfmt \x10\x00\x00\x00\x01\x00",14&#41;!=0&#41; &#123;
//		pgcPuts&#40;"format err"&#41;;
		return -1;
	&#125;
	
	channels=*&#40;short *&#41;&#40;wavfile+0x16&#41;;
	samplerate=*&#40;long *&#41;&#40;wavfile+0x18&#41;;
	blocksize=*&#40;short *&#41;&#40;wavfile+0x20&#41;;
	bitpersample=*&#40;short *&#41;&#40;wavfile+0x22&#41;;
	
	if &#40;_memcmp&#40;wavfile+0x24,"data",4&#41;!=0&#41; &#123;
//		pgcPuts&#40;"format err"&#41;;
		return -1;
	&#125;
	
	datalength=*&#40;unsigned long *&#41;&#40;wavfile+0x28&#41;;
	
	if &#40;datalength+0x2c>filelen&#41; &#123;
//		pgcPuts&#40;"format err"&#41;;
		return -1;
	&#125;
	
	if &#40;channels!=2 && channels!=1&#41; &#123;
//		pgcPuts&#40;"format err, channel"&#41;;
		return -1;
	&#125;
	
//	if &#40;samplerate!=44100 && samplerate!=22050 && samplerate!=11025&#41; &#123;
	if &#40;samplerate>100000 || samplerate<2000&#41; &#123;
//		pgcPuts&#40;"format err, samplerate"&#41;;
		return -1;
	&#125;
	
	if &#40;blocksize!=channels*2&#41; &#123;
//		pgcPuts&#40;"format err, blocksize"&#41;;
		return -1;
	&#125;
	
	if &#40;bitpersample!=16&#41; &#123;
//		pgcPuts&#40;"format err, bitpersample"&#41;;
		return -1;
	&#125;
	
	if &#40;channels==2&#41; &#123;
		samplecount=datalength/4;
	&#125; else &#123;
		samplecount=datalength/2;
	&#125;
	if &#40;samplecount<=0&#41; &#123;
//		pgcPuts&#40;"format err, samplecount"&#41;;
		return -1;
	&#125;
	
	wi->channels=channels;
	wi->samplerate=samplerate;
	wi->samplecount=samplecount;
	wi->datalength=datalength;
	wi->wavdata=wavfile+0x2c;
	wi->rateratio=&#40;samplerate*0x4000&#41;/11025;
	wi->playptr=0;
	wi->playptr_frac=0;
	wi->playloop=0;
	
	return 0;
&#125;

int pgfOpen&#40;const char *filename, unsigned long flag&#41;
&#123;
	char fn&#91;MAX_PATH*2&#93;;
	if &#40;_strchr&#40;filename,'&#58;'&#41;!=NULL || *filename=='/' || *filename=='\\'&#41; &#123;
		return sceIoOpen&#40;filename,flag&#41;;
	&#125; else &#123;
		_strcpy&#40;fn,pg_workdir&#41;;
		_strcat&#40;fn,filename&#41;;
		return sceIoOpen&#40;fn,flag&#41;;
	&#125;
&#125;

void pgfClose&#40;int fd&#41;
&#123;
	sceIoClose&#40;fd&#41;;
&#125;

int pgfRead&#40;int fd, void *data, int size&#41;
&#123;
	return sceIoRead&#40;fd,data,size&#41;;
&#125;

void wavoutStopPlay0&#40;&#41;
&#123;
	if &#40;wavout_snd0_wavinfo!=0&#41; &#123;
		while &#40;wavout_snd0_ready&#41; pspDisplayWaitVblankStart&#40;&#41;;;
		wavout_snd0_wavinfo=0;
		while &#40;!wavout_snd0_ready&#41; pspDisplayWaitVblankStart&#40;&#41;;;
	&#125;
&#125;

void wavoutStartPlay0&#40;wavout_wavinfo_t *wi&#41;
&#123;
	wavoutStopPlay0&#40;&#41;;
	while &#40;!wavout_snd0_ready&#41; pspDisplayWaitVblankStart&#40;&#41;;;
	wavout_snd0_playptr=0;
	wavout_snd0_playend=0;
	wavout_snd0_wavinfo=wi;
	while &#40;wavout_snd0_ready&#41; pspDisplayWaitVblankStart&#40;&#41;;;
&#125;
an excerpt from my main program

Code: Select all

void xmain&#40;unsigned long args, void *argp&#41;
&#123;
	threadSetupCallbacks&#40;&#41;;
	gfxSetup&#40;&#41;;
	inputSetup&#40;&#41;;
	unsigned long n=args;
	if &#40;n>sizeof&#40;pg_mypath&#41;-1&#41; n=sizeof&#40;pg_mypath&#41;-1;
	_memcpy&#40;pg_mypath,argp,n&#41;;
	pg_mypath&#91;sizeof&#40;pg_mypath&#41;-1&#93;=0;
	_strcpy&#40;pg_workdir,pg_mypath&#41;;
	for &#40;n=_strlen&#40;pg_workdir&#41;; n>0 && pg_workdir&#91;n-1&#93;!='/'; --n&#41; pg_workdir&#91;n-1&#93;=0;
	pgaInit&#40;&#41;;
	wavoutInit&#40;&#41;;
	wavoutLoadWav&#40;"ms0&#58;/psp/game/memory/op.wav",&wavinfo_bg,wavdata_bg,sizeof&#40;wavdata_bg&#41;&#41;;
	wavinfo_bg.playloop=1;
	wavoutStartPlay0&#40;&wavinfo_bg&#41;;
If that isn't enough to get it working, I'll upload the entire source somewhere and link it.

edit The code to do the sound was taken from a few different places, mostly links off of this board. I don't take credit for writing the code, nor do I think I could write it myself. Just wanted to make sure people didn't think I was taking credit for it. I'd just like to see a way to load WAVs in the SDK as well.
maddogjt1
Posts: 13
Joined: Mon Jun 27, 2005 3:06 pm

Post by maddogjt1 »

Speaking of audio, does anybody know if the psp supports any type of midi playback or if there is a decent library out there that would be able to do a midi to wav conversion at load time or real time. If so, I'd be willing to port it and add it to the sdk.
Post Reply