LibAmp 0.3 Based on Amp 0.7.6 by Tomislav Uzelac Ported to DJGPP/Allegro and turned into library form by Ove Kaaven To try it out, type "make", this will build the library and libdemo.exe. (the direct Amp port can be made with: make -f makefile.amp) Typing "make install" will copy the library and include file to \djgpp\lib and \djgpp\include, respectively. To use, #include "libamp.h" into your program and link with -lamp (Beware of name clashes between routines in this library and your program, there is potentially some serious name space pollution here.) See the demo MP3 player libdemo.c for an example. (You're welcome to write a better player if you wish.) New in LibAmp 0.3 support for 3.0+WIP stereo mode packfile support some minor optimizations New in LibAmp 0.2 amp_reverse_phase, enables the classic 3D effect volume slider in libdemo Notes: #defines in audio.h USE_PACKFILE is used to force amp to use Allegro's pack_f* routines instead of the stdio f* routines for accessing MP3 files. This will make seeking and restarting slower, but allows you to embed MP3 files in Allegro .dat files (or even to your .exe file using Allegro's exedat utility... if you really want a huge executable that much, anyway). Since you won't be able to compress MP3 files much, the only advantage of this is that your users won't rip your embedded MP3 files quite as easily, of course, and you can keep your file count down if you have a lot of songs. #defines in audioalg.c TRACK_FRAME is useful for players that want to show real-time scopes (like libdemo), but is otherwise unnecessary and just wastes CPU time and RAM. You may want to undefine it if you don't need it. STREAM_SAMP is how big the Allegro stream buffer size should be. Increase it if the playback becomes jerky due to run_amp() or poll_amp() not being called often enough to supply the stream with data often enough. BUF_SAMP is how big the internal audio buffer size should be. It *must* be a multiple of 2*576 *and* a multiple of STREAM_SAMP for proper operation. run_amp() will try to fill it up completely, so if the buffer is big, it may spend some time on first call after load or seek. UPD_SAMP is with what resolution amp_play_left and amp_play_right is updated to provide real-time scope functionality. amp_play_len will be set to this value. STREAM_SAMP must be a multiple of this value. It is only meaningful if TRACK_FRAME is defined. #defines in libamp.h AMP_MIXSTEREO is to use the new Allegro 3.0+WIP stereo audio streams, but since you may have programs that use the old two-channel way, it is up to you to define this. variables in libamp.h amp_bitrate is the number of kilobits per second of MP3 data that are to be transferred and decoded in realtime to playback the audio stream, e.g. you'd need ISDN to playback a 56Kbps realtime stream from the Internet. This also defines storage requirements, computational resource usage, compression level, and quality. amp_samprat is the sample rate of the decompressed audio data. Defines audio quality. Remember to configure Allegro to take advantage of high sample rates; the allegro.cfg that comes with the zip should take care of that for SB cards. amp_mpg_ver is probably 1 for MPEG version 1.0, 2 for 2.0 (the MPEG version is *not* the same thing as the MPEG layer) amp_layer is either 2 or 3, MP3 files are layer 3. This defines compression complexity, higher layers can compress with better quality with better compression ratios. amp_stereo is nonzero if it's a stereo MP3 file. amp_pollsize is the buffer/step size in samples that amp_play_left and amp_play_right moves along with if TRACK_FRAME is defined. amp_playing tells whether a MP3 file is currently playing. amp_loaded tells whether a MP3 file is currently loaded. amp_reverse_phase reverses the phase of the right stereo channel; the oldest Surround-Sound trick in the book, but it works (if it's a stereo MP3). amp_dec_frame is the current decoder positions. It should generally be a bit ahead of the actually playing position so that unexpected delays don't cause bad skips in the audio. If not, you aren't calling poll_amp() or run_amp() often enough. Generally, you don't need to bother about this variable. amp_dec_time is amp_dec_frame converted to time in seconds. amp_frame is the currently playing frame, if TRACK_FRAME is defined (otherwise it's the same as amp_dec_frame). amp_time is amp_frame converted to time in seconds. This is useful to tell the listener the current playback position. amp_buf_left and amp_buf_right is the currently playing audio stream buffers. For mono streams or if AMP_MIXSTEREO is defined, they both point to the same buffer. amp_buf_len is the length in samples of the above buffers. amp_play_left and amp_play_right is the currently playing audio stream buffer position, if TRACK_FRAME is defined (otherwise they're the same as amp_buf_left and amp_buf_right). Useful for real-time scopes. For mono streams or if AMP_MIXSTEREO is defined, they both point to the same buffer. amp_play_len is the length in samples of the above buffer parts, if TRACK_FRAME is defined (otherwise it's the same as amp_buf_len). functions in libamp.h install_amp() should be called at startup. It returns TRUE if successfully installed. load_amp() loads and starts playing the given MP3 file, returning TRUE if succesfully started. poll_amp() decodes and buffers a single MP3 frame. Obviously it needs to be called as often as possible (for a 44kHz stream it must be called at least about 76 times per second, that is about every 13ms). It returns -1 if there's nothing to play (e.g. the playback is complete), 0 if the playback buffer is full (meaning it has enough audio data for a moment and that you have an excellent opportunity to let the computer do other stuff in the meantime), and 1 if one frame was successfully decoded and buffered. run_amp() is a wrapper for poll_amp() that repeatedly calls it until it no longer returns 1, thus always making sure the playback buffers are full before returning. This allows the playback to go on for much longer periods without needing to call run_amp() again (adjustable with the STREAM_SAMP and BUF_SAMP defines in audioalg.c), but may also consume more time if a lot of frames need to be processed. It returns -1 if there's nothing to play, or 0 when the buffers are filled up. replay_amp() seeks to the beginning of the MP3 file and restarts playback. seek_amp_abs() seeks to the specified frame. Note that this is somewhat unreliable in amp 0.7.6 that LibAmp is based on. seek_amp_rel() seeks the specified number of frames forward or backwards from amp_frame. Note that this is somewhat unreliable in amp 0.7.6 that LibAmp is based on. unload_amp() stops playback and closes the currently loaded MP3 file. Usage: For example code, please refer to libdemo.c (a complete player) and playmp3.c (minimal code, for total newbies).