diff options
Diffstat (limited to 'plugins/ape')
-rw-r--r-- | plugins/ape/Makefile.am | 7 | ||||
-rw-r--r-- | plugins/ape/ape.c | 259 | ||||
-rw-r--r-- | plugins/ape/apewrapper.cpp | 77 | ||||
-rw-r--r-- | plugins/ape/apewrapper.h | 139 |
4 files changed, 0 insertions, 482 deletions
diff --git a/plugins/ape/Makefile.am b/plugins/ape/Makefile.am deleted file mode 100644 index d5678f4f..00000000 --- a/plugins/ape/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -apedir = $(libdir)/$(PACKAGE) -pkglib_LTLIBRARIES = ape.la -ape_la_SOURCES = ape.c apewrapper.cpp apewrapper.h -ape_la_LDFLAGS = -module - -ape_la_LIBADD = $(LDADD) $(APE_LIBS) -AM_CFLAGS = $(CFLAGS) -std=c99 -O0 -g diff --git a/plugins/ape/ape.c b/plugins/ape/ape.c deleted file mode 100644 index 9443dfa2..00000000 --- a/plugins/ape/ape.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - apedec - Monkey's Audio Decoder plugin for DeaDBeeF player - http://deadbeef.sourceforge.net - - Copyright (C) 2009 Alexey Yakovenko - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Note: DeaDBeeF player itself uses different license -*/ -#include <stdio.h> -#include <string.h> -#include <time.h> -#include "../../deadbeef.h" -#include "apewrapper.h" - -#define min(x,y) ((x)<(y)?(x):(y)) -#define max(x,y) ((x)>(y)?(x):(y)) - -static DB_decoder_t plugin; -static DB_functions_t *deadbeef; - -static void *ape_dec; -static int ape_blk_size; - -#define READBUF_SIZE 0x20000 - -static char ape_readbuf[READBUF_SIZE]; -static int ape_blocks_left; -static int ape_total_blocks; -static float timestart; -static float timeend; -static int samplesdecoded; - -// precalc for bps conversion -static int32_t mask; -static float scaler; -static int32_t neg; -static int32_t sign; -static int32_t signshift; - -static int -ape_seek (float seconds); - -static int -ape_init (DB_playItem_t *it) { - ape_dec = ape_decompress_create (it->fname); - if (!ape_dec) { - printf ("ape_decompress_create failed for file %s\n", it->fname); - return -1; - } - WAVEFORMATEX wfe; - ape_decompress_get_info_data (ape_dec, APE_INFO_WAVEFORMATEX, &wfe); - int size = ape_decompress_get_info_int (ape_dec, APE_INFO_WAV_HEADER_BYTES); - char buf[size]; - ape_decompress_get_info_data_sized (ape_dec, APE_INFO_WAV_HEADER_DATA, buf, size); - ape_blk_size = ape_decompress_get_info_int (ape_dec, APE_INFO_BLOCK_ALIGN); - ape_total_blocks = ape_blocks_left = ape_decompress_get_info_int (ape_dec, APE_DECOMPRESS_TOTAL_BLOCKS); - samplesdecoded = 0; - plugin.info.bps = wfe.wBitsPerSample; - plugin.info.samplerate = wfe.nSamplesPerSec; - plugin.info.channels = wfe.nChannels; - plugin.info.readpos = 0; - if (it->timeend > 0) { - timestart = it->timestart; - timeend = it->timeend; - ape_seek (0); - } - else { - timestart = 0; - timeend = it->duration; - } - - mask = (1<<(plugin.info.bps-1))-1; - scaler = 1.f / ((1<<(plugin.info.bps-1))-1); - neg = 1<<plugin.info.bps; - sign = (1<<31); - signshift = plugin.info.bps-1; - return 0; -} - -static void -ape_free (void) { - if (ape_dec) { - ape_decompress_destroy (ape_dec); - ape_dec = NULL; - } -} - -static int -ape_read_int16 (char *buffer, int size) { - int initsize = size; - int nblocks = size / plugin.info.channels / 2; - nblocks = min (nblocks, ape_blocks_left); - nblocks = ape_decompress_getdata (ape_dec, ape_readbuf, nblocks); - - uint8_t *in = ape_readbuf; - for (int i = 0; i < nblocks*plugin.info.channels; i++) { - // convert from bps to int32_t - int32_t sample = 0; - int shift = 0; - while (shift < plugin.info.bps - 8) { - sample |= (*in << shift); - in++; - shift += 8; - } - sample |= ((char)(*in)) << (plugin.info.bps - 8); - in++; - - // now that's convertable to 16 bit - *((int16_t*)buffer) = (int16_t)sample; - buffer += 2; - } - - ape_blocks_left -= nblocks; - samplesdecoded += nblocks; - plugin.info.readpos = samplesdecoded / (float)plugin.info.samplerate - timestart; - if (plugin.info.readpos >= timeend) { - return 0; - } - return nblocks * 2 * plugin.info.channels; -} - -static int -ape_read_float32 (char *buffer, int size) { - int initsize = size; - int nblocks = size / plugin.info.channels / sizeof (float); - nblocks = min (nblocks, ape_blocks_left); - nblocks = ape_decompress_getdata (ape_dec, ape_readbuf, nblocks); - - uint8_t *in = ape_readbuf; - for (int i = 0; i < nblocks*plugin.info.channels; i++) { - // convert from bps to int32_t - int32_t sample = 0; - int shift = 0; - while (shift < plugin.info.bps - 8) { - sample |= (*in << shift); - in++; - shift += 8; - } - sample |= ((char)(*in)) << (plugin.info.bps - 8); - in++; - - // now that's convertable to float32 - *((float*)buffer) = (sample - ((sample&sign)>>signshift)*neg) * scaler; - buffer += sizeof (float); - } - - ape_blocks_left -= nblocks; - samplesdecoded += nblocks; - plugin.info.readpos = samplesdecoded / (float)plugin.info.samplerate - timestart; - if (plugin.info.readpos >= timeend) { - return 0; - } - return nblocks * sizeof (float) * plugin.info.channels; -} - -static int -ape_seek (float seconds) { - seconds += timestart; - int nblock = seconds * plugin.info.samplerate; - ape_decompress_seek (ape_dec, nblock); - samplesdecoded = nblock; - ape_blocks_left = ape_total_blocks - nblock; - plugin.info.readpos = samplesdecoded / (float)plugin.info.samplerate - timestart; - return 0; -} - -static DB_playItem_t * -ape_insert (DB_playItem_t *after, const char *fname) { - void *dec = ape_decompress_create (fname); - if (!dec) { - return NULL; - } - WAVEFORMATEX wfe; - ape_decompress_get_info_data (dec, APE_INFO_WAVEFORMATEX, &wfe); - - float duration = ape_decompress_get_info_int (dec, APE_DECOMPRESS_TOTAL_BLOCKS) / (float)wfe.nSamplesPerSec; - ape_decompress_destroy (dec); - DB_playItem_t *it; - it = deadbeef->pl_insert_cue (after, fname, &plugin, "APE", duration); - if (it) { - return it; - } - - it = deadbeef->pl_item_alloc (); - it->decoder = &plugin; - it->fname = strdup (fname); - it->filetype = "APE"; - it->duration = duration; - - // try to read tags - FILE *fp = fopen (fname, "rb"); - if (!fp) { - deadbeef->pl_item_free (it); - return NULL; - } - - int v2err = deadbeef->junk_read_id3v2 (it, fp); - int v1err = deadbeef->junk_read_id3v1 (it, fp); - if (v1err >= 0) { - fseek (fp, -128, SEEK_END); - } - else { - fseek (fp, 0, SEEK_END); - } - int apeerr = deadbeef->junk_read_ape (it, fp); - deadbeef->pl_add_meta (it, "title", NULL); - fclose (fp); - - after = deadbeef->pl_insert_item (after, it); - - return after; -} - -static const char * exts[] = { "ape", NULL }; -static const char *filetypes[] = { "APE", NULL }; - -// define plugin interface -static DB_decoder_t plugin = { - DB_PLUGIN_SET_API_VERSION - .plugin.version_major = 0, - .plugin.version_minor = 1, - .plugin.type = DB_PLUGIN_DECODER, - .plugin.name = "Monkey's Audio decoder", - .plugin.author = "Alexey Yakovenko", - .plugin.email = "waker@users.sourceforge.net", - .plugin.website = "http://deadbeef.sf.net", - .init = ape_init, - .free = ape_free, - .read_int16 = ape_read_int16, - .read_float32 = ape_read_float32, - .seek = ape_seek, - .insert = ape_insert, - .exts = exts, - .id = "stdape", - .filetypes = filetypes -}; - -DB_plugin_t * -ape_load (DB_functions_t *api) { - deadbeef = api; - return DB_PLUGIN (&plugin); -} - diff --git a/plugins/ape/apewrapper.cpp b/plugins/ape/apewrapper.cpp deleted file mode 100644 index 3e13136c..00000000 --- a/plugins/ape/apewrapper.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - apedec - Monkey's Audio Decoder plugin for DeaDBeeF player - http://deadbeef.sourceforge.net - - Copyright (C) 2009 Alexey Yakovenko - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Note: DeaDBeeF player itself uses different license -*/ -#include <mac/All.h> -#include <mac/GlobalFunctions.h> -#include <mac/MACLib.h> -#include <mac/CharacterHelper.h> -#include <mac/APETag.h> -#include "apewrapper.h" - -void * -ape_decompress_create (const char *fname) { - int ret; - CSmartPtr<wchar_t> str; - str.Assign (GetUTF16FromUTF8 ((const str_utf8 *)fname), TRUE); - IAPEDecompress *dec = CreateIAPEDecompress(str, &ret); - return dec; -} - -void -ape_decompress_destroy (void *d) { - IAPEDecompress *dec = (IAPEDecompress *)d; - delete dec; -} - -int -ape_decompress_get_info_int (void *d, int id) { - IAPEDecompress *dec = (IAPEDecompress *)d; - return dec->GetInfo ((APE_DECOMPRESS_FIELDS)id); -} - -int -ape_decompress_get_info_data (void *d, int id, void *ptr) { - IAPEDecompress *dec = (IAPEDecompress *)d; - return dec->GetInfo ((APE_DECOMPRESS_FIELDS)id, (intptr_t)ptr); -} - -int -ape_decompress_get_info_data_sized (void *d, int id, void *ptr, int size) { - IAPEDecompress *dec = (IAPEDecompress *)d; - return dec->GetInfo ((APE_DECOMPRESS_FIELDS)id, (intptr_t)ptr, size); -} - -int -ape_decompress_getdata (void *d, char *buffer, int nblocks) { - IAPEDecompress *dec = (IAPEDecompress *)d; - int retr; - int res = dec->GetData (buffer, nblocks, &retr); - return retr; -} - -int -ape_decompress_seek (void *d, int nblockoffs) { - IAPEDecompress *dec = (IAPEDecompress *)d; - return dec->Seek (nblockoffs); -} diff --git a/plugins/ape/apewrapper.h b/plugins/ape/apewrapper.h deleted file mode 100644 index ca3c0f92..00000000 --- a/plugins/ape/apewrapper.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - apedec - Monkey's Audio Decoder plugin for DeaDBeeF player - http://deadbeef.sourceforge.net - - Copyright (C) 2009 Alexey Yakovenko - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Note: DeaDBeeF player itself uses different license -*/ -#ifndef __APEWRAPPER_H -#define __APEWRAPPER_H - -#ifdef __cplusplus -extern "C" { -#endif - -// decode process: -// 1. get input format: -// WAVEFORMATEX wfe; -// GetInfo(APE_INFO_WAVEFORMATEX, (intptr_t)&wfe) -// 2. get wav header -// int size = GetInfo(APE_INFO_WAV_HEADER_BYTES) -// char buf[size]; -// GetInfo (APE_INFO_WAV_HEADER_DATA, (intptr_t)buf, size); -// 3. allocate space for readbuffer -// int bufsize = GetInfo(APE_INFO_BLOCK_ALIGN) * BLOCKS_PER_DECODE; -// char readbuf[bufsize]; -// 4. get total number of blocks -// int blocksleft = GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS); -// 5. decompress -// while (blocksleft > 0) { -// int ndecoded; -// GetData (readbuf, BLOCKS_PER_DECODE, &ndecoded); -// nblocksleft -= ndecoded; -// } -// 6. terminate output -// if (GetInfo(APE_INFO_WAV_TERMINATING_BYTES) > 0) { -// GetInfo(APE_INFO_WAV_TERMINATING_DATA, (intptr_t)readbuf, GetInfo(APE_INFO_WAV_TERMINATING_BYTES)); -// } -#ifndef APE_MACLIB_H - -typedef struct tWAVEFORMATEX -{ - uint16_t wFormatTag; /* format type */ - uint16_t nChannels; /* number of channels (i.e. mono, stereo...) */ - uint32_t nSamplesPerSec; /* sample rate */ - uint32_t nAvgBytesPerSec; /* for buffer estimation */ - uint16_t nBlockAlign; /* block size of data */ - uint16_t wBitsPerSample; /* number of bits per sample of mono data */ - uint16_t cbSize; /* the count in bytes of the size of */ - /* extra information (after cbSize) */ -} WAVEFORMATEX; - -enum APE_DECOMPRESS_FIELDS -{ - APE_INFO_FILE_VERSION = 1000, // version of the APE file * 1000 (3.93 = 3930) [ignored, ignored] - APE_INFO_COMPRESSION_LEVEL = 1001, // compression level of the APE file [ignored, ignored] - APE_INFO_FORMAT_FLAGS = 1002, // format flags of the APE file [ignored, ignored] - APE_INFO_SAMPLE_RATE = 1003, // sample rate (Hz) [ignored, ignored] - APE_INFO_BITS_PER_SAMPLE = 1004, // bits per sample [ignored, ignored] - APE_INFO_BYTES_PER_SAMPLE = 1005, // number of bytes per sample [ignored, ignored] - APE_INFO_CHANNELS = 1006, // channels [ignored, ignored] - APE_INFO_BLOCK_ALIGN = 1007, // block alignment [ignored, ignored] - APE_INFO_BLOCKS_PER_FRAME = 1008, // number of blocks in a frame (frames are used internally) [ignored, ignored] - APE_INFO_FINAL_FRAME_BLOCKS = 1009, // blocks in the final frame (frames are used internally) [ignored, ignored] - APE_INFO_TOTAL_FRAMES = 1010, // total number frames (frames are used internally) [ignored, ignored] - APE_INFO_WAV_HEADER_BYTES = 1011, // header bytes of the decompressed WAV [ignored, ignored] - APE_INFO_WAV_TERMINATING_BYTES = 1012, // terminating bytes of the decompressed WAV [ignored, ignored] - APE_INFO_WAV_DATA_BYTES = 1013, // data bytes of the decompressed WAV [ignored, ignored] - APE_INFO_WAV_TOTAL_BYTES = 1014, // total bytes of the decompressed WAV [ignored, ignored] - APE_INFO_APE_TOTAL_BYTES = 1015, // total bytes of the APE file [ignored, ignored] - APE_INFO_TOTAL_BLOCKS = 1016, // total blocks of audio data [ignored, ignored] - APE_INFO_LENGTH_MS = 1017, // length in ms (1 sec = 1000 ms) [ignored, ignored] - APE_INFO_AVERAGE_BITRATE = 1018, // average bitrate of the APE [ignored, ignored] - APE_INFO_FRAME_BITRATE = 1019, // bitrate of specified APE frame [frame index, ignored] - APE_INFO_DECOMPRESSED_BITRATE = 1020, // bitrate of the decompressed WAV [ignored, ignored] - APE_INFO_PEAK_LEVEL = 1021, // peak audio level (obsolete) (-1 is unknown) [ignored, ignored] - APE_INFO_SEEK_BIT = 1022, // bit offset [frame index, ignored] - APE_INFO_SEEK_BYTE = 1023, // byte offset [frame index, ignored] - APE_INFO_WAV_HEADER_DATA = 1024, // error code [buffer *, max bytes] - APE_INFO_WAV_TERMINATING_DATA = 1025, // error code [buffer *, max bytes] - APE_INFO_WAVEFORMATEX = 1026, // error code [waveformatex *, ignored] - APE_INFO_IO_SOURCE = 1027, // I/O source (CIO *) [ignored, ignored] - APE_INFO_FRAME_BYTES = 1028, // bytes (compressed) of the frame [frame index, ignored] - APE_INFO_FRAME_BLOCKS = 1029, // blocks in a given frame [frame index, ignored] - APE_INFO_TAG = 1030, // point to tag (CAPETag *) [ignored, ignored] - - APE_DECOMPRESS_CURRENT_BLOCK = 2000, // current block location [ignored, ignored] - APE_DECOMPRESS_CURRENT_MS = 2001, // current millisecond location [ignored, ignored] - APE_DECOMPRESS_TOTAL_BLOCKS = 2002, // total blocks in the decompressors range [ignored, ignored] - APE_DECOMPRESS_LENGTH_MS = 2003, // total blocks in the decompressors range [ignored, ignored] - APE_DECOMPRESS_CURRENT_BITRATE = 2004, // current bitrate [ignored, ignored] - APE_DECOMPRESS_AVERAGE_BITRATE = 2005, // average bitrate (works with ranges) [ignored, ignored] - - APE_INTERNAL_INFO = 3000 // for internal use -- don't use (returns APE_FILE_INFO *) [ignored, ignored] -}; -#endif - -void * -ape_decompress_create (const char *fname); - -void -ape_decompress_destroy (void *d); - -int -ape_decompress_get_info_int (void *d, int id); - -int -ape_decompress_get_info_data (void *d, int id, void *ptr); - -int -ape_decompress_get_info_data_sized (void *d, int id, void *ptr, int size); - -int -ape_decompress_getdata (void *d, char *buffer, int nblocks); - -int -ape_decompress_seek (void *d, int nblockoffs); - -#ifdef __cplusplus -} -#endif - -#endif // __APEWRAPPER_H |