/* mpg123clr: MPEG Audio Decoder library Common Language Runtime version. copyright 2009-2011 by Malcolm Boczek - free software under the terms of the LGPL 2.1 mpg123clr.dll is a derivative work of libmpg123 - all original mpg123 licensing terms apply. All rights to this work freely assigned to the mpg123 project. */ /* libmpg123: MPEG Audio Decoder library copyright 1995-2011 by the mpg123 project - free software under the terms of the LGPL 2.1 see COPYING and AUTHORS files in distribution or http://mpg123.org */ /* 1.8.1.0 04-Aug-09 Initial release. 1.9.0.0 24-Sep-09 Function names harmonized with libmpg123 (mb) 1.10.0.0 30-Nov-09 release match - added mpg123_feature (mb) 1.12.0.0 14-Apr-10 release match - added framebyframe and "handle" ReplaceReaders (mb) 1.13.0.0 13-Jan-11 release match - added encsize (mb) */ #pragma once #pragma warning(disable : 4635) #include "mpg123.h" #pragma warning(default : 4635) #include "enum.h" #include "error.h" #include "id3v1.h" #include "id3v2.h" #include "advanced.h" #include // for posix proof of concept only #include #include #include #include using namespace std; using namespace System; using namespace System::IO; using namespace System::Runtime::InteropServices; namespace mpg123clr { // Recommended usage when creating reference type on the managed heap (not using stack semantics // for reference types...) [see (Microsoft) Destructors and Finalizers in Visual C++] // // C++/CLI // A myA; // // use myA here // // Equivalent user code: // // A ^ myA = gcnew A; // try { /* use myA here */ } finally { delete myA; } // // // C# (from wikipedia) // using(A myA = new A()) { /* Use myA here */ } // Compiler calls myA.Dispose(), in a "finally" of a "try/finally" block // // Equivalent user code: // // A myA = new myA(); // try { /* Use myA here */ } finally { myA.Dispose(); } // // Otherwise Finalizer will be nondeterministically called by GC ///Wrapper for libmpg123. public ref class mpg123 { #pragma region Callback and Delegate // Functional callbacks for low-level I/O ReplaceReader public: ///Seek Delegate. ///Callback seek function to provide low-level stream access to posix-like seek operations. /// Requires user supplied static callback fuction of form off_t fn(int fd, off_t offset, int origin). ///Returns callee supplied resulting offset from start of file or -1 for error. /// ///Contains file descriptor. ///Contains required offset value. ///Contains relative origin value (whence) applied to offset. ///Callee supplied resulting offset from start of file or -1 for error. [UnmanagedFunctionPointer(CallingConvention::Cdecl)] delegate off_t SeekDelegate(int fd, off_t offset, int origin); [UnmanagedFunctionPointer(CallingConvention::Cdecl)] delegate off_t SeekHandleDelegate(void* handle, off_t offset, int origin); ///Read Delegate. ///Callback read function to provide low-level stream access to posix-like read operations. /// Requires user supplied static callback fuction of form ssize_t fn(int fd, void* buffer, size_t size). ///Returns callee supplied resulting actual number of bytes read or -1 for error. /// ///Contains file descriptor. ///Contains address of buffer. ///Contains size of buffer. ///Callee supplied resulting actual number of bytes read or -1 for error. [UnmanagedFunctionPointer(CallingConvention::Cdecl)] delegate ssize_t ReadDelegate(int fd, void* buffer, size_t size); [UnmanagedFunctionPointer(CallingConvention::Cdecl)] delegate ssize_t ReadHandleDelegate(void* handle, void* buffer, size_t size); [UnmanagedFunctionPointer(CallingConvention::Cdecl)] delegate void CleanupHandleDelegate(void* handle); private: // Delegate "keep alive" fields to prevent GC of delegate. SeekDelegate^ seekDel; ReadDelegate^ readDel; SeekHandleDelegate^ seekHDel; ReadHandleDelegate^ readHDel; CleanupHandleDelegate^ cleanHDel; GCHandle userObjectHandle; // Temporary delegate store, replacereader action is defered until next stream 'open' action SeekDelegate^ r_seekDel; ReadDelegate^ r_readDel; SeekHandleDelegate^ r_seekHDel; ReadHandleDelegate^ r_readHDel; CleanupHandleDelegate^ r_cleanHDel; bool useHandleReplacement; bool lastReplacementWasHandle; #pragma endregion -Callback and Delegate #pragma region Library and Handle Setup // \defgroup mpg123_init mpg123 library and handle setup // // Functions to initialise and shutdown the mpg123 library and handles. // The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-) // Tip: Use a RVA setting... // private: mpg123_handle* mh; internal: mpg123(mpg123_handle* mh); protected: ///Finalizer. ///Cleanly handles mpg123_delete of internal (unmanaged) mpg123 handle. /// Implementation of CLR Finalize(). !mpg123(void); public: ///Constructor. ///Only creates mpg123 object, you must call one of the New() methods to obtain a decoder library handle. ///Recommended usage: using(mpg123 obj = new mpg123()){ use obj here } mpg123(void); ///Destructor. Used for final object deletion. ///Calls finalizer for clean disposal of internal (unmanaged) library handles. /// /// Implementation of CLR Dispose(). /// ~Destructor and !Finalizer are the prescribed implementation of Dispose() and Finalize(). /// See Destructors and Finalizers in Visual C++ ~mpg123(void); ///(mpg123_init) Function to initialise the mpg123 library. ///This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. ///Returns MPG123_OK if successful, otherwise an error number. ///Returns MPG123_OK if successful, otherwise an error number. static mpg123clr::mpg::ErrorCode __clrcall mpg123_init(void); ///(mpg123_exit) Function to close down the mpg123 library. ///This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. static void __clrcall mpg123_exit(void); ///(mpg123_new) Obtain am mpg123 handle with designated decoder. ///Returns MPG123_OK or applicable error code. /// ///Name of the decoder to attach. ///MPG123_OK or applicable error code. mpg123clr::mpg::ErrorCode __clrcall mpg123_new(String ^ decoder); ///Obtain an mpg123 handle with default decoder. ///Returns MPG123_OK or applicable error code. /// ///MPG123_OK or applicable error code. mpg123clr::mpg::ErrorCode __clrcall mpg123_new(void); ///Obtain am mpg123 handle with default decoder. ///Allows use of common parms object for multiple connections. ///Returns MPG123_OK or applicable error code. /// ///Supplied Advanced parameter object. ///MPG123_OK or applicable error code. mpg123clr::mpg::ErrorCode __clrcall mpg123_parnew(mpg123clr::advpars^ par); ///Obtain am mpg123 handle with designated decoder. ///Allows use of common parms object for multiple connections. ///Returns MPG123_OK or applicable error code. /// ///Supplied Advanced parameter object. ///Name of the decoder to attach. ///MPG123_OK or applicable error code. mpg123clr::mpg::ErrorCode __clrcall mpg123_parnew(mpg123clr::advpars^ par, String^ decoder); ///(mpg123_delete) Delete internal mpg123 handle. ///The framework will dispose of the object when it goes out of scope - you do not need to explicitly call Delete(). /// However it is available to allow reuse of this object with successive handles - using New()/Delete() pairs. /// void __clrcall mpg123_delete(void); public: ///Set a specific parameter value. ///Returns MPG123_OK or applicable error code. /// ///Define the parameter to be set. (parms enumeration) ///Integer value to apply. ///Real value to apply. ///MPG123_OK or applicable error code. mpg123clr::mpg::ErrorCode __clrcall mpg123_param(mpg123clr::mpg::parms type, int val, double fval); ///Get a specific parameter value. ///Returns MPG123_OK or applicable error code. /// ///Define the parameter to get. (parms enumeration) ///Returned integer value. ///Returned real value. ///MPG123_OK or applicable error code. mpg123clr::mpg::ErrorCode __clrcall mpg123_getparam(mpg123clr::mpg::parms type, [Out] int% val, [Out] double% fval); ///Query libmpg123 feature. ///Returns 1 for success, 0 for unimplemented feature. /// ///Define the feature to query. (feature_set enumeration) ///1 for success, 0 for unimplemented feature. static int __clrcall mpg123_feature(mpg123clr::mpg::feature_set key); #pragma endregion -Library and Handle Setup #pragma region Internal Helpers internal: array^ StringArrayFromPtr(const char ** ptr); #pragma endregion -Internal Helpers #pragma region Error Handling // \defgroup mpg123_error mpg123 error handling // // Functions to get text version of the error numbers and an enumeration // of the error codes returned by libmpg123. // // Most functions operating on a mpg123_handle simply return MPG123_OK on success and MPG123_ERR on failure (setting the internal error variable of the handle to the specific error code). // Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (please read up on these on how to react!). // The positive range of return values is used for "useful" values when appropriate. // public: ///Get string describing what error has occured in the context of this object. ///When a function operating on an mpg123 handle returns MPG123_ERR, you should use this function to check the actual reason. ///This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE. ///Returns text representation of last error (incl. None) encountered by this object. /// ///Text representation of last error (incl. None) encountered by this object. String^ __clrcall mpg123_strerror(void); ///Get last error encountered in the context of this object. ///When a function operating on an mpg123 handle returns MPG123_ERR, you should use this function to check the actual reason. ///This function will catch internal handle == NULL and return MPG123_BAD_HANDLE. ///Returns ErrorCode for last encountered error. /// ///The plain errcode intead of a string of last error (incl. None) encountered by this object. mpg123clr::mpg::ErrorCode __clrcall mpg123_errcode(void); #pragma endregion -Error Handling #pragma region Decoder Selection // \defgroup mpg123_decoder mpg123 decoder selection // // Functions to list and select the available decoders. // Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is). // public: ///Obtain list of generally available decoder names (plain 8bit ASCII). ///Retuns a string array of generally available decoder names (plain 8bit ASCII). /// ///A string array of generally available decoder names (plain 8bit ASCII). array^ __clrcall mpg123_decoders(void); ///Obtain list of the decoders supported by the CPU (plain 8bit ASCII). ///Returns a string array of the decoders supported by the CPU (plain 8bit ASCII). /// ///A string array of the decoders supported by the CPU (plain 8bit ASCII). array^ __clrcall mpg123_supported_decoders(void); ///Select the decoder to use. ///Returns MPG123_OK or applicable error code. /// ///Name of the required decoder. (should be in SupportedDecoders list) ///MPG123_OK or applicable error code. mpg123clr::mpg::ErrorCode __clrcall mpg123_decoder(String^ name); ///Get the currently active decoder engine name. ///The active decoder engine can vary depening on output constraints, mostly non-resampling, integer output is accelerated via 3DNow and Co. /// but for other modes a fallback engine kicks in. ///Note that this can return a decoder that is ony active in the hidden and not available as decoder choice from the outside. ///Returns the decoder name or String.Empty on error. /// ///The decoder name or String.Empty on error. String^ __clrcall mpg123_current_decoder(void); #pragma endregion -Decoder Selection #pragma region Output Audio Format // \defgroup mpg123_output mpg123 output audio format // // Functions to get and select the format of the decoded audio. // public: ///Get an array of supported standard sample rates. ///These are possible native sample rates of MPEG audio files. /// You can still force mpg123 to resample to a different one, but by default you will only get audio in one of these samplings. ///Returns array of sample rates. /// ///An array of sample rates. array^ __clrcall mpg123_rates(void); ///An array of supported audio encodings. ///An audio encoding is one of the fully qualified members of mpg.enc ///Returns array of supported Encodings. /// ///An array of supported Encodings. array^ __clrcall mpg123_encodings(void); ///Get the size (in bytes) of one mono sample of the named encoding. ///Returns the positive size of encoding in bytes, 0 on invalid encoding. /// ///The encoding value to analyze. ///The positive size of encoding in bytes, 0 on invalid encoding. static int __clrcall mpg123_encsize(mpg123clr::mpg::enc encoding); ///Configure mpg123 to accept no output format at all. ///Use to clear default parameters prior to applying specific settings. ///Returns MPG123 error codes. /// ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_format_none(void); ///Configure mpg123 to accept all formats including any custom formats - this is the default. ///Returns MPG123 error codes. /// ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_format_all(void); ///Configure detailed output formats. ///Returns MPG123 error codes. /// ///Sample rate (Hertz) ///Combination of channelcount.stereo and channelcount.mono ///Combination of accepted encodings for rate and channels e.g. enc.enc_signed16 | enc.enc_ulaw_8 (or 0 for none) ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_format(int rate, mpg123clr::mpg::channelcount channels, mpg123clr::mpg::enc encodings); ///Get available support for supplied rate and encoding. ///Returns 0 for no support (includes invalid parameters), or combination of channelcount.stereo and channelcount.mono. /// ///Sample rate (Hertz) ///Combination of accepted encodings for rate and channels e.g. enc.enc_signed16 | enc.enc_ulaw_8 (or 0 for none) ///Returns 0 for no support (includes invalid parameters), or combination of channelcount.stereo and channelcount.mono. mpg123clr::mpg::channelcount __clrcall mpg123_format_support(int rate, mpg123clr::mpg::enc encoding); ///Get current output format. ///Returns MPG123 error codes. /// ///Returns current sample rate (Hertz) ///Returns combination of channelcount.stereo and channelcount.mono ///Returns combination of accepted encodings for rate and channels e.g. enc.enc_signed16 | enc.enc_ulaw_8 (or 0 for none) ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_getformat([Out] int% rate, [Out] mpg123clr::mpg::channelcount% channels, [Out] mpg123clr::mpg::enc% encoding); #pragma endregion -Output Audio Format #pragma region File Input and Decoding // \defgroup mpg123_input mpg123 file input and decoding // // Functions for input bitstream and decoding operations. // Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (please read up on these on how to react!). // public: ///Open and prepare to decode the file specified by ANSI filename. ///This does not open HTTP urls; the mpg library contains no networking code. /// If you want to decode internet streams, use Open(fd) or Open(). /// ///Returns MPG123 error codes /// ///ANSI file path. Accepts ANSI path characters. For Unicode paths use tOpen. /// NOTE: can be used in Unicode environment as long as wide-char codepages are avoided. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_open(String^ path); ///Use a previously obtained file descriptor as the bitstream input. ///NOTE: Close() will NOT close a file opened with this method. ///Returns MPG123 error codes. /// ///File Descriptor of pre required file. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_open_fd(int fd); ///Use an opaque handle as bitstream input. ///This works only with the replaced I/O from mpg123_replace_reader_handle()! ///mpg123_close() will call the cleanup callback for your handle (if you gave one). ///Returns MPG123 error codes. /// ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_open_handle(System::Object^ obj); ///Open a new bitstream and prepare for direct feeding. ///This works together with Decode(); you are responsible for reading and feeding the input bitstream. ///Returns MPG123 error codes. /// ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_open_feed(void); ///Closes the source, if the library opened it. ///Returns MPG123 error codes. /// ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_close(void); ///Open and prepare to decode the file specified by UNICODE (wide-character) filename. ///This does not open HTTP urls; the mpg library contains no networking code. /// If you want to decode internet streams, use Open(fd) or Open(). /// ///Returns MPG123 error codes /// ///UNICODE wide-character file path. See also ANSI Open(path). ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_topen(String^ path); ///Closes the file opened with tOpen. ///Returns MPG123 error codes. /// ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_tclose(void); ///Read from stream and decode. ///Equivalent to mpg123_read(,,,) ///Returns MPG123 error codes. (watch out for MPG123_DONE and friends!) /// ///Supplied buffer in which to return audio output data. ///Returns number of actual audio output bytes returned. ///MPG123 error codes. (watch out for MPG123_DONE and friends!) mpg123clr::mpg::ErrorCode __clrcall mpg123_read(array^ buffer, [Out] size_t% count); ///Read from stream and decode. ///Equivalent to mpg123_read(,,,) but modified to better support CLR Stream.Read ///Returns MPG123 error codes. (watch out for MPG123_DONE and friends!) /// ///Supplied buffer in which to return audio output data. ///Offset in buffer at which to begin storing data. ///Maximum number of bytes to return. ///Returns number of actual audio output bytes returned. ///MPG123 error codes. (watch out for MPG123_DONE and friends!) mpg123clr::mpg::ErrorCode __clrcall mpg123_read(array^ buffer, size_t offset, size_t size, [Out] size_t% count); ///Feed data for a stream that has been opened with Open() - (mpg123_open_feed). ///Equivalent to mpg123_feed(...), it's give and take: You provide the bytestream, mpg123 gives you the decoded samples. ///Returns MPG123 error codes. /// ///Input buffer. ///Number of input bytes. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_feed(array^ inbuffer, size_t size); ///Decode MPEG Audio from inmemory to outmemory. ///This is very close to a drop-in replacement for old mpglib. ///When you give zero-sized output buffer the input will be parsed until /// decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it) /// without taking decoded data. ///Think of this function being the union of Read() and Feed() (which it actually is, sort of;-). /// You can actually always decide if you want those specialized functions in separate steps or one call this one here. ///Returns MPG123 error codes. (watch out especially for MPG123_NEED_MORE) /// ///Input buffer. ///Number of input bytes. ///Supplied buffer in which to return audio output data. ///Size in bytes of buffer. ///Returns number of actual audio output bytes returned. ///MPG123 error codes. (watch out especially for MPG123_NEED_MORE) mpg123clr::mpg::ErrorCode __clrcall mpg123_decode(array^ inbuffer, size_t insize, array^ outbuffer, size_t outsize, [Out] size_t% count); ///Decode next MPEG frame to internal buffer or read a frame and return after setting a new format. ///Returns MPG123 error codes. (watch out for MPG123_NEW_FORMAT) /// ///Returns current frame offset. ///Returns pointer to internal buffer to read the decoded audio from. (Can be NULL for NEW_FORMAT) ///Returns number of actual audio output bytes ready in the buffer. ///MPG123 error codes. (watch out for MPG123_NEW_FORMAT) mpg123clr::mpg::ErrorCode __clrcall mpg123_decode_frame([Out] off_t% num, [Out] IntPtr% audio, [Out] size_t% count); ///Decode current MPEG frame to internal buffer. ///Use with mpg123_framebyframe_next to progress through data. ///Warning: This is experimental API that might change in future releases! /// Please watch mpg123 development closely when using it. ///Returns MPG123 error codes. /// ///Returns current frame offset. ///Returns pointer to internal buffer to read the decoded audio from. (Can be NULL for NEW_FORMAT) ///Returns number of actual audio output bytes ready in the buffer. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_framebyframe_decode([Out] off_t% num, [Out] IntPtr% audio, [Out] size_t% bytes); ///Find, read and parse the next mp3 frame. ///Use with mpg123_framebyframe_decode to obtain frame data. ///Warning: This is experimental API that might change in future releases! /// Please watch mpg123 development closely when using it. ///Returns MPG123 error codes. (watch out for MPG123_NEW_FORMAT) /// ///MPG123 error codes. (watch out for MPG123_NEW_FORMAT) mpg123clr::mpg::ErrorCode __clrcall mpg123_framebyframe_next(void); #pragma endregion -File Input and Decoding #pragma region Position and Seeking // \defgroup mpg123_seek mpg123 position and seeking // // Functions querying and manipulating position in the decoded audio bitstream. // The position is measured in decoded audio samples, or MPEG frame offset for the specific functions. // If gapless code is in effect, the positions are adjusted to compensate the skipped padding/delay - meaning, you should not care about that at all and just use the position defined for the samples you get out of the decoder;-) // The general usage is modelled after stdlib's ftell() and fseek(). // Especially, the whence parameter for the seek functions has the same meaning as the one for fseek() and needs the same constants from stdlib.h: // - SEEK_SET: set position to (or near to) specified offset // - SEEK_CUR: change position by offset from now // - SEEK_END: set position to offset from end // // Note that sample-accurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise. // Also, really sample-accurate seeking (meaning that you get the identical sample value after seeking compared to plain decoding up to the position) is only guaranteed when you do not mess with the position code by using MPG123_UPSPEED, MPG123_DOWNSPEED or MPG123_START_FRAME. The first two mainly should cause trouble with NtoM resampling, but in any case with these options in effect, you have to keep in mind that the sample offset is not the same as counting the samples you get from decoding since mpg123 counts the skipped samples, too (or the samples played twice only once)! // Short: When you care about the sample position, don't mess with those parameters;-) // Also, seeking is not guaranteed to work for all streams (underlying stream may not support it). // public: ///Get the current position in samples. On the next read, you'd get that sample. ///Returns the current sample position. /// ///The current sample position. long long __clrcall mpg123_tell(); ///Get the frame number that the next read will give you data from. ///Returns the current frame number position. /// ///The current frame number position. long long __clrcall mpg123_tellframe(); ///Get the current byte offset in the input stream. ///Returns the current byte offset. /// ///The current byte offset. long long __clrcall mpg123_tell_stream(); ///Seek to a desired sample offset. ///Returns the resulting offset >= 0 or error/message code. /// ///The distance to move. ///(whence) The relative location to move from.(SeekOrigin.Begin, SeekOrigin.Current, SeekOrigin.End) ///Returns the resulting offset >= 0 or error/message code. long long __clrcall mpg123_seek(long long offset, SeekOrigin origin); ///Seek to a desired sample offset in data feeding mode. ///This just prepares things to be right only if you ensure that the next chunk of input data will be from input_offset byte position. ///Returns the resulting offset >= 0 or error/message code. /// ///The distance to move. ///(whence) The relative location to move from.(SeekOrigin.Begin, SeekOrigin.Current, SeekOrigin.End) ///Returns the position it expects to be at the next time data is fed to Decode(). ///Returns the resulting offset >= 0 or error/message code. long long __clrcall mpg123_feedseek(long long offset, SeekOrigin origin, [Out] long long% input_offset); ///Seek to a desired MPEG frame index. ///Returns the resulting offset >= 0 or error/message code. /// ///The numberof frames to move. ///(whence) The relative location to move from.(SEEK_SET, SEEK_CUR or SEEK_END) ///Returns the resulting offset >= 0 or error/message code. long long __clrcall mpg123_seek_frame(long long frameoffset, SeekOrigin origin); ///Seek to an absolute MPEG frame offset corresponding to an offset in seconds. ///This assumes that the samples per frame do not change in the file/stream, which is a good assumption for any sane file/stream only. ///Returns the resulting offset >= 0 or error/message code. /// ///The absolute time offset required. ///Returns the resulting offset >= 0 or error/message code. long long __clrcall mpg123_timeframe(double seconds); ///Get a copy of the frame index table. Somewhat equivalent to mpg123_index(,,). ///The library requests not to modify table values. Since this is a copy, modification is meaningless - it has no effect on library routines. ///NOTE: The returned index table value types are Int64 independant of library build. ///Returns MPG123 error codes. /// ///Returns array of source file position offsets (not output samples). Length of array is equivalent to mpg123_index "fill" parameter. ///Returns number of MPEG frames per index entry. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_index([Out] array^% index, [Out] long long% step); ///Get a pointer to the frame index table. Equivalent to mpg123_index(,,). ///Do not modify table values unless you really know what you are doing! ///NOTE: The returned index table value types may be Int32 or Int64 depending on library build. ///Returns MPG123 error codes. /// ///Returns pointer to source file position offset index array (not output samples). ///Returns number of MPEG frames per index entry. ///Returns number of recorded index offsets; size of the array. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_index([Out] IntPtr% indexarr, [Out] long long% step, [Out] size_t% fill); ///Get information about current and remaining frames/seconds. Equivalent to mpg123_position(,,,,,,). ///WARNING: This function is there because of special usage by standalone mpg123 and may be removed in the final version of libmpg123! ///You provide an offset (in frames) from now and a number of output bytes /// served by libmpg123 but not yet played. You get the projected current frame /// and seconds, as well as the remaining frames/seconds. This does _not_ care /// about skipped samples due to gapless playback. ///Returns MPG123 error codes. /// ///Offset (in frames) from now. ///Number of output bytes served by library but not yet played. ///Returns projected current frame. ///Returns projected frames remaining. ///Returns projected current seconds. ///Returns projected seconds remaining. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_position(long long frameoffset, long long bufferedbytes, [Out] long long% currentframe, [Out] long long% framesleft, [Out] double% currentseconds, [Out] double% secondsleft); #pragma endregion -Position and Seeking #pragma region Volume and Equalizer // \defgroup mpg123_voleq mpg123 volume and equalizer // public: ///Set the 32 Band Audio Equalizer settings. ///Returns MPG123 error codes. /// ///Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both. (enum mpg.channels) ///The equaliser band to change (from 0 to 31) ///The (linear) adjustment factor to be applied. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_eq(mpg123clr::mpg::channels channel, int band, double fval); ///Get the 32 Band Audio Equalizer settings. ///Rreturns the (linear) adjustment factor. /// ///Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both. (enum mpg.channels) ///The equaliser band to get (from 0 to 31) ///The (linear) adjustment factor. double __clrcall mpg123_geteq(mpg123clr::mpg::channels channel, int band); ///Reset the 32 Band Audio Equalizer settings to flat. ///Returns MPG123 error codes. /// ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_reset_eq(); ///Set the absolute output volume including the RVA setting. ///Returns MPG123 error codes. /// ///The (linear) adjustment factor to be applied, volume < 0 just applies (a possibly changed) RVA setting. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_volume(double volume); ///Adjust output volume including the RVA setting. ///Returns MPG123 error codes. /// ///The (linear) adjustment factor to be applied. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_volume_change(double change); ///Get the current volume setting, the actual value due to RVA, and the RVA adjustment itself. ///Returns MPG123 error codes. /// ///Returns the current linear volume factor. (not percent) ///Returns the actual linear volume factor due to RVA. (not percent) ///Returns the RVA adjustment in decibels. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_getvolume([Out] double% basevol, [Out] double% really, [Out] double% rva_db); #pragma endregion -Volume and Equalizer #pragma region Status and Information // \defgroup mpg123_status mpg123 status and information // // // [StructLayout(LayoutKind::Sequential, CharSet=CharSet::Ansi, Pack=1)] ref struct mpeg_frameinfo { mpg123clr::mpg::mpeg_version version; // The MPEG version (1.0/2.0/2.5). int layer; // The MPEG Audio Layer (MP1/MP2/MP3). long rate; // The sampling rate in Hz. mpg123clr::mpg::mpeg_mode mode; // The audio mode (Mono, Stereo, Joint-stero, Dual Channel). int mode_ext; // The mode extension bit flag. int framesize; // The size of the frame (in bytes). mpg123clr::mpg::mpeg_flags flags; // MPEG Audio flag bits. int emphasis; // The emphasis type. int bitrate; // Bitrate of the frame (kbps). int abr_rate; // The target average bitrate. mpg123clr::mpg::mpeg_vbr vbr; // The VBR mode. }; ///Get the frame information about the MPEG audio bitstream. ///Returns MPG123 error codes. /// ///Returns the frame information. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_info([Out]mpeg_frameinfo^% finfo); ///Get the frame information about the MPEG audio bitstream. ///SafeInfo uses "safe" managed structures but is somewhat slower than Info(). /// Recommend using Info() unless it gives specific problems. ///Returns MPG123 error codes. /// ///Returns the frame information. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_safeinfo([Out]mpeg_frameinfo^% finfo); ///Get the safe output buffer size for all cases (when you want to replace the internal buffer). ///Returns safe buffer size. /// ///Safe buffer size. static size_t __clrcall mpg123_safe_buffer(void); ///Make a full parsing scan of each frame in the file. ///ID3 tags are found. An accurate length value is stored. Seek index will be filled. /// A seek back to current position is performed. ///This function refuses work when stream is not seekable. ///Returns MPG123 error codes. /// ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_scan(void); ///Return, if possible, the full (expected) length of current track in samples. ///Returns length (>= 0) or MPG123_ERR if there is no length guess possible. (Multiply by BlockAlign for byte-count) /// ///Length (>= 0) or MPG123_ERR if there is no length guess possible. (Multiply by BlockAlign for byte-count) long long __clrcall mpg123_length(void); ///Override the value for file size in bytes. ///Useful for getting sensible track length values in feed mode or for HTTP streams. ///Returns MPG123 error codes. /// ///Size to set. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_set_filesize(long long size); ///Time Per Frame (seconds). ///Returns time per frame in seconds ( < 0 is error ). /// ///Time per frame in seconds ( < 0 is error ). double __clrcall mpg123_tpf(void); ///Get and reset the clip count. ///Returns the number of previously encountered clips. /// ///The number of previously encountered clips. long __clrcall mpg123_clip(); ///Get various current decoder/stream state information. ///Returns MPG123 error codes. /// ///The key to identify the information to get (enum mpg.state). ///Returns integer values. ///Returns real values. ///MPG123 error codes. mpg123clr::mpg::ErrorCode __clrcall mpg123_getstate(mpg123clr::mpg::state key, [Out] int% val, [Out] double% fval); #pragma endregion -Status and Information #pragma region Metadata Handling // \defgroup mpg123_metadata mpg123 metadata handling // // Functions to retrieve the metadata from MPEG Audio files and streams. // Also includes string handling functions. // // clr - much of the metadata has been relocated to class files for maintainability // see string.h, text.h, id3v1.h and id3v2.h // ///Query if there is (new) meta info, be it ID3 or ICY (or something new in future). ///Returns a combination of flags. (enum id3.id3check) /// ///Returns a combination of flags. (enum id3.id3check) mpg123clr::id3::id3check __clrcall mpg123_meta_check(void); /* On error (no valid handle) just 0 is returned. */ ///Get ID3 data. Data structures may change on any (next) read/decode function call. ///v1 and/or v2 may be Empty if no corresponding data exists. ///Returns MPG123_OK or MPG123_ERR. /// ///Returns mpg123id3v1 data structure containing ID3v1 data (usually from end of file). ///Returns mpg123id3v2 data structure containing ID3v2 data (usually - but not restricted to - from beginning of file). ///Returns MPG123_OK or MPG123_ERR. mpg123clr::mpg::ErrorCode __clrcall mpg123_id3([Out]id3::mpg123id3v1^% v1, [Out]id3::mpg123id3v2^% v2); ///Get ICY meta data. Data structure may change on any (next) read/decode function call. ///Icy_meta may be null if no corresponding data exists. ///Returns MPG123_OK or MPG123_ERR. /// ///Returns ICY meta data (windows-1252 encoded). ///Returns MPG123_OK or MPG123_ERR. mpg123clr::mpg::ErrorCode __clrcall mpg123_icy([Out]IntPtr% icy_meta); /* same for ICY meta string */ ///Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8. ///Returns byte array of utf8 encoded data. /// ///ICY meta data in ICY encoding. ///Returns byte array of utf8 encoded data. static array^ __clrcall mpg123_icy2utf8(IntPtr icy_text); #pragma endregion -Metadata Handling #pragma region Advanced Parameter API // \defgroup mpg123_advpar mpg123 advanced parameter API // // Direct access to a parameter set without full handle around it. // Possible uses: // - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE). // - Use one set of parameters for multiple handles. // // The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt() // family) directly return a fully qualified mpg123 error code, the ones // operating on full handles normally MPG123_OK or MPG123_ERR, storing the // specific error code itself inside the handle. // // see advanced.h #pragma endregion -Advanced Parameter API #pragma region Low Level I/O // \defgroup mpg123_lowio mpg123 low level I/O // You may want to do tricky stuff with I/O that does not work with mpg123's default file access or you want to make it decode into your own pocket... // ///Replace default internal buffer with user-supplied buffer. ///Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio. ///The data buffer should be pinned before calling this function. ///Returns MPG123_OK or MPG123 error code. /// ///Pointer to supplied buffer. ///Size of supplied buffer. ///MPG123_OK or MPG123_ERR code. mpg123clr::mpg::ErrorCode __clrcall mpg123_replace_buffer(IntPtr data, size_t size); ///The max size of one frame's decoded output with current settings. ///Use that to determine an appropriate minimum buffer size for decoding one frame. ///Returns size of required buffer. /// ///Size of required buffer. size_t __clrcall mpg123_outblock(void); ///Replace low-level stream access functions; read and lseek as known in POSIX. ///You can use this to make any fancy file opening/closing yourself, /// using mpg123_open_fd() to set the file descriptor for your read/lseek (doesn't need to be a 'real' file descriptor...). ///Setting a function to NULL means that the default internal function is used (active from next Open call onward). ///////////////////////// ///Always returns MPG123_OK. /// ///Delegate for read function, null for default. ///Delegate for lseek function, null for default. ///Always MPG123_OK. mpg123clr::mpg::ErrorCode __clrcall mpg123_replace_reader(ReadDelegate^ r_read, SeekDelegate^ r_lseek); /////////////////////////////////////// mpg123clr::mpg::ErrorCode __clrcall mpg123_replace_reader_handle(ReadHandleDelegate^ rh_read, SeekHandleDelegate^ rh_lseek, CleanupHandleDelegate^ rh_clean); private: // Defered internal implementation of ReplaceReader - action is defered until next 'Open' operation. void __clrcall _ReplaceReader(void); public: // These functions are not part of the mpg123clr wrapper but are included as proof of concept // of how to implement callback functions. ///Proof of concept posix-like lseek function. ///This routine should not normally be called from your callback routine, it is a sample function /// showing how such a callback could be implemented. /// ///File descriptor. ///Required position. ///Whence. ///Resultant position. static long PosixSeek(int fd, long offset, int origin) { long ret = _lseek(fd, offset, origin); return ret; } ///Proof of concept posix-like read function. ///This routine should not normally be called from your callback routine, it is a sample function /// showing how such a callback could be implemented. /// ///File descriptor. ///Buffer address. ///Size of buffer. ///Actual bytes read. static int PosixRead(int fd, void*buf, unsigned int count) { int ret = _read(fd, buf, count); return ret; } #pragma endregion -Low Level I/O }; }