Starting Out in Audio

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

Moderators: cheriff, TyRaNiD

Post Reply
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Starting Out in Audio

Post by Vincent_M »

I've seen the source to loading aac, at3, the at3mod, and some other source code, but it's still a bit too complex for me at the moment in terms of working with audio. My end goal is to be able to load and play (stream) at3 files on a separate thread using the Media Engine. I need to do a little work on threading, because I haven't worked with threading on the PSP before, and I have no audio programming experience at all. Saying that, I know I won't be able to do anything too seriousely just yet. What I'm looking for right now is some sources to completely load and play music. I'm not looking for any tutorials, or code (I've got plenty of demo code), but simply just some advice where to start, I know there's a lot to know before I get into anything huge, so I'm just looking for opinions/suggestions on where to start. I've been researching a little on how certain file formats such as the wav format, and how compression works with the mp3 format. I haven't been able to find any useful information on the at3 format, but I've heard that it is easier to use than the mp3 format. I've looked through pspaudio.h, pspaudiolib.h, and pspaudiocode.h, but I don't have any luck on where to go in terms of learning how to load sound data from files in a way that the PSP can use to produce sound on the PSP speakers.
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

I'm not an audio guy, so I hope this info is correct.

First off the best place to start learning audio is in the SDK samples (surely?) there is a WAVE generator there. It'll create a nice sinewave that if you put high enough will give you a headache in a few seconds. ;) this should give you an idea on how to interface with the PSP's audio hardware.

It may also have some examples of threading there, possibly some ME stuff. I know that there are a few ME samples floating about.

Secondly as for decoding atract stuff there is another thread about that someone found firmware calls to decode atrac and mp3 via the firmware. chances are that these are using the ME(?), or that they're going pretty well so trying to make it work faster maybe a challenge. I don't know tho!

Good luck in whatever you're up to! :)
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

cooleyes is your guy for at3/mp3/acc sample

as for goal of producing sound with efficient
memory usage do research more on DOUBLE BUFFERS

struct AUDIO_BUFFER aud_buff[2] ; // thats two buffers

take same aspect as draw/display buffers for graphics
and utilize FLIPPING those buffers, constantly filling them

Code: Select all

/*c++*/
for&#40;i=0; i < 2; ++i&#41; &#123;
    if&#40; i > 1 &#41;  i = 0; // remember array is &#91;0, 1&#93;

    aud_fill_buffer&#40; aud_buf&#91; i &#93; &#41; ; // try and always fill 32KB of data from
                                    // FILE* tip&#58; just use pointer arithmetic
                                    // to increment always by an aligned
                                    // buffer struct that is 32KB 
    aud_play_buffer&#40; aud_buf&#91; i &#93; &#41; ;
    aud_buf&#91; i &#93; = aud_flip_buffer&#40;&#41; ; // safer
    
&#125;

// ** this is only if you want to be clever **
#define AUD_BUFF_START &#40;0&#41;
#define AUD_BUFF0  &#40;0&#41;
#define AUD_BUFF1  &#40;1&#41;

char cur_buff = AUD_BUFF_START ;
switch&#40; cur_buff &#41; &#123;
   case AUD_BUFF0 &#58;
         // do your filling of this buffer_0
         // @ end ; do NOT free instead just refill buffer_0 = NULL ; 
         // this can be optimized out
        aud_buff&#91;1&#93; = aud_buff&#91;0&#93; ;
        aud_buff&#91;0&#93; = NULL ;

        cur_buff = AUD_BUFF1 ; // OR you could FALL thru  
   case AUD_BUFF1 &#58;
         // do your sending buffer_0 to buffer_1 and then send to audio system
         // @ end ;
        cur_buff = AUD_BUFF0 ; // start process all over again
    default &#58; cur_buf = AUD_BUFF_START ; // f*ck exceptions ;P
&#125;
once you got filling two buffers out of the way then really
look into MUTEX and semaphores and a queue system
to help keep locking things out like artifacts, threads getting into memory usage etc...

as for THREADING, look into POSIX threads and how threads
work together once they understand their priorities
hey one day you could even do double threads that each handle their
OWN buffer from the aud_buff[] array, then your guranteed they never
mix up which of 0 or 1 they should be handling

just make sure threads are highest priority if you utilize a PAUSE menu
10011011 00101010 11010111 10001001 10111010
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Post by Vincent_M »

Awesome example for streaming! I'll ask cooleyes on how to feed music data to the PSP's ME.
Post Reply