mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Add an encoding API.
This API is called ma_encoder. Currently it only supports encoding to WAV files, which is done via dr_wav.
This commit is contained in:
+442
-78
@@ -4796,7 +4796,18 @@ float ma_gain_db_to_factor(float gain);
|
|||||||
#endif /* MA_NO_DEVICE_IO */
|
#endif /* MA_NO_DEVICE_IO */
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(MA_NO_DECODING) || !defined(MA_NO_ENCODING)
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ma_seek_origin_start,
|
||||||
|
ma_seek_origin_current
|
||||||
|
} ma_seek_origin;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ma_resource_format_wav
|
||||||
|
} ma_resource_format;
|
||||||
|
#endif
|
||||||
|
|
||||||
/************************************************************************************************************************************************************
|
/************************************************************************************************************************************************************
|
||||||
|
|
||||||
@@ -4808,15 +4819,8 @@ you do your own synchronization.
|
|||||||
|
|
||||||
************************************************************************************************************************************************************/
|
************************************************************************************************************************************************************/
|
||||||
#ifndef MA_NO_DECODING
|
#ifndef MA_NO_DECODING
|
||||||
|
|
||||||
typedef struct ma_decoder ma_decoder;
|
typedef struct ma_decoder ma_decoder;
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
ma_seek_origin_start,
|
|
||||||
ma_seek_origin_current
|
|
||||||
} ma_seek_origin;
|
|
||||||
|
|
||||||
typedef size_t (* ma_decoder_read_proc) (ma_decoder* pDecoder, void* pBufferOut, size_t bytesToRead); /* Returns the number of bytes read. */
|
typedef size_t (* ma_decoder_read_proc) (ma_decoder* pDecoder, void* pBufferOut, size_t bytesToRead); /* Returns the number of bytes read. */
|
||||||
typedef ma_bool32 (* ma_decoder_seek_proc) (ma_decoder* pDecoder, int byteOffset, ma_seek_origin origin);
|
typedef ma_bool32 (* ma_decoder_seek_proc) (ma_decoder* pDecoder, int byteOffset, ma_seek_origin origin);
|
||||||
typedef ma_uint64 (* ma_decoder_read_pcm_frames_proc) (ma_decoder* pDecoder, void* pFramesOut, ma_uint64 frameCount); /* Returns the number of frames read. Output data is in internal format. */
|
typedef ma_uint64 (* ma_decoder_read_pcm_frames_proc) (ma_decoder* pDecoder, void* pFramesOut, ma_uint64 frameCount); /* Returns the number of frames read. Output data is in internal format. */
|
||||||
@@ -4950,6 +4954,58 @@ ma_result ma_decode_memory(const void* pData, size_t dataSize, ma_decoder_config
|
|||||||
#endif /* MA_NO_DECODING */
|
#endif /* MA_NO_DECODING */
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************************************************************************************************
|
||||||
|
|
||||||
|
Encoding
|
||||||
|
========
|
||||||
|
|
||||||
|
Encoders do not perform any format conversion for you. If your target format does not support the format, and error will be returned.
|
||||||
|
|
||||||
|
************************************************************************************************************************************************************/
|
||||||
|
#ifndef MA_NO_ENCODING
|
||||||
|
typedef struct ma_encoder ma_encoder;
|
||||||
|
|
||||||
|
typedef size_t (* ma_encoder_write_proc) (ma_encoder* pEncoder, const void* pBufferIn, size_t bytesToWrite); /* Returns the number of bytes written. */
|
||||||
|
typedef ma_bool32 (* ma_encoder_seek_proc) (ma_encoder* pEncoder, int byteOffset, ma_seek_origin origin);
|
||||||
|
typedef ma_result (* ma_encoder_init_proc) (ma_encoder* pEncoder);
|
||||||
|
typedef void (* ma_encoder_uninit_proc) (ma_encoder* pEncoder);
|
||||||
|
typedef ma_uint64 (* ma_encoder_write_pcm_frames_proc)(ma_encoder* pEncoder, const void* pFramesIn, ma_uint64 frameCount);
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ma_resource_format resourceFormat;
|
||||||
|
ma_format format;
|
||||||
|
ma_uint32 channels;
|
||||||
|
ma_uint32 sampleRate;
|
||||||
|
ma_allocation_callbacks allocationCallbacks;
|
||||||
|
} ma_encoder_config;
|
||||||
|
|
||||||
|
ma_encoder_config ma_encoder_config_init(ma_resource_format resourceFormat, ma_format format, ma_uint32 channels, ma_uint32 sampleRate);
|
||||||
|
|
||||||
|
struct ma_encoder
|
||||||
|
{
|
||||||
|
ma_encoder_config config;
|
||||||
|
ma_encoder_write_proc onWrite;
|
||||||
|
ma_encoder_seek_proc onSeek;
|
||||||
|
ma_encoder_init_proc onInit;
|
||||||
|
ma_encoder_uninit_proc onUninit;
|
||||||
|
ma_encoder_write_pcm_frames_proc onWritePCMFrames;
|
||||||
|
void* pUserData;
|
||||||
|
void* pInternalEncoder; /* <-- The drwav/drflac/stb_vorbis/etc. objects. */
|
||||||
|
void* pFile; /* FILE*. Only used when initialized with ma_encoder_init_file(). */
|
||||||
|
};
|
||||||
|
|
||||||
|
ma_result ma_encoder_init(ma_encoder_write_proc onWrite, ma_encoder_seek_proc onSeek, void* pUserData, const ma_encoder_config* pConfig, ma_encoder* pEncoder);
|
||||||
|
#ifndef MA_NO_STDIO
|
||||||
|
ma_result ma_encoder_init_file(const char* pFilePath, const ma_encoder_config* pConfig, ma_encoder* pEncoder);
|
||||||
|
ma_result ma_encoder_init_file_w(const wchar_t* pFilePath, const ma_encoder_config* pConfig, ma_encoder* pEncoder);
|
||||||
|
#endif
|
||||||
|
void ma_encoder_uninit(ma_encoder* pEncoder);
|
||||||
|
ma_uint64 ma_encoder_write_pcm_frames(ma_encoder* pEncoder, const void* pFramesIn, ma_uint64 frameCount);
|
||||||
|
|
||||||
|
#endif /* MA_NO_ENCODING */
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************************************************************************************************
|
/************************************************************************************************************************************************************
|
||||||
|
|
||||||
Generation
|
Generation
|
||||||
@@ -5928,6 +5984,122 @@ char* ma_copy_string(const char* src, const ma_allocation_callbacks* pAllocation
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FILE* ma_fopen(const char* pFilePath, const char* pOpenMode)
|
||||||
|
{
|
||||||
|
FILE* pFile;
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
|
if (fopen_s(&pFile, pFilePath, pOpenMode) != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
pFile = fopen(pFilePath, pOpenMode);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return pFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
_wfopen() isn't always available in all compilation environments.
|
||||||
|
|
||||||
|
* Windows only.
|
||||||
|
* MSVC seems to support it universally as far back as VC6 from what I can tell (haven't checked further back).
|
||||||
|
* MinGW-64 (both 32- and 64-bit) seems to support it.
|
||||||
|
* MinGW wraps it in !defined(__STRICT_ANSI__).
|
||||||
|
|
||||||
|
This can be reviewed as compatibility issues arise. The preference is to use _wfopen_s() and _wfopen() as opposed to the wcsrtombs()
|
||||||
|
fallback, so if you notice your compiler not detecting this properly I'm happy to look at adding support.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW64__) || !defined(__STRICT_ANSI__)
|
||||||
|
#define MA_HAS_WFOPEN
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
FILE* ma_wfopen(const wchar_t* pFilePath, const wchar_t* pOpenMode, ma_allocation_callbacks* pAllocationCallbacks)
|
||||||
|
{
|
||||||
|
FILE* pFile = NULL;
|
||||||
|
|
||||||
|
#if defined(MA_HAS_WFOPEN)
|
||||||
|
(void)pAllocationCallbacks;
|
||||||
|
|
||||||
|
/* Use _wfopen() on Windows. */
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
|
if (_wfopen_s(&pFile, pFilePath, pOpenMode) != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
pFile = _wfopen(pFilePath, pOpenMode);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
Use fopen() on anything other than Windows. Requires a conversion. This is annoying because fopen() is locale specific. The only real way I can
|
||||||
|
think of to do this is with wcsrtombs(). Note that wcstombs() is apparently not thread-safe because it uses a static global mbstate_t object for
|
||||||
|
maintaining state. I've checked this with -std=c89 and it works, but if somebody get's a compiler error I'll look into improving compatibility.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
mbstate_t mbs;
|
||||||
|
size_t lenMB;
|
||||||
|
const wchar_t* pFilePathTemp = pFilePath;
|
||||||
|
char* pFilePathMB = NULL;
|
||||||
|
char pOpenModeMB[32] = {0};
|
||||||
|
|
||||||
|
if (pOpenMode == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the length first. */
|
||||||
|
MA_ZERO_OBJECT(&mbs);
|
||||||
|
lenMB = wcsrtombs(NULL, &pFilePathTemp, 0, &mbs);
|
||||||
|
if (lenMB == (size_t)-1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pFilePathMB = (char*)ma_malloc(lenMB + 1, pAllocationCallbacks);
|
||||||
|
if (pFilePathMB == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pFilePathTemp = pFilePath;
|
||||||
|
MA_ZERO_OBJECT(&mbs);
|
||||||
|
wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
|
||||||
|
|
||||||
|
/* The open mode should always consist of ASCII characters so we should be able to do a trivial conversion. */
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
for (;;) {
|
||||||
|
if (pOpenMode[i] == 0) {
|
||||||
|
pOpenModeMB[i] = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pOpenModeMB[i] = (char)pOpenMode[i];
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pFile = fopen(pFilePathMB, pOpenModeMB);
|
||||||
|
|
||||||
|
ma_free(pFilePathMB, pAllocationCallbacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pFile == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return pFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static MA_INLINE void ma_copy_memory_64(void* dst, const void* src, ma_uint64 sizeInBytes)
|
static MA_INLINE void ma_copy_memory_64(void* dst, const void* src, ma_uint64 sizeInBytes)
|
||||||
{
|
{
|
||||||
#if 0xFFFFFFFFFFFFFFFF <= MA_SIZE_MAX
|
#if 0xFFFFFFFFFFFFFFFF <= MA_SIZE_MAX
|
||||||
@@ -38762,16 +38934,10 @@ static ma_result ma_decoder__preinit_file(const char* pFilePath, const ma_decode
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
pFile = ma_fopen(pFilePath, "rb");
|
||||||
if (fopen_s(&pFile, pFilePath, "rb") != 0) {
|
|
||||||
return MA_ERROR;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
pFile = fopen(pFilePath, "rb");
|
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return MA_ERROR;
|
return MA_ERROR;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* We need to manually set the user data so the calls to ma_decoder__on_seek_stdio() succeed. */
|
/* We need to manually set the user data so the calls to ma_decoder__on_seek_stdio() succeed. */
|
||||||
pDecoder->pUserData = pFile;
|
pDecoder->pUserData = pFile;
|
||||||
@@ -38779,23 +38945,6 @@ static ma_result ma_decoder__preinit_file(const char* pFilePath, const ma_decode
|
|||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
_wfopen() isn't always available in all compilation environments.
|
|
||||||
|
|
||||||
* Windows only.
|
|
||||||
* MSVC seems to support it universally as far back as VC6 from what I can tell (haven't checked further back).
|
|
||||||
* MinGW-64 (both 32- and 64-bit) seems to support it.
|
|
||||||
* MinGW wraps it in !defined(__STRICT_ANSI__).
|
|
||||||
|
|
||||||
This can be reviewed as compatibility issues arise. The preference is to use _wfopen_s() and _wfopen() as opposed to the wcsrtombs()
|
|
||||||
fallback, so if you notice your compiler not detecting this properly I'm happy to look at adding support.
|
|
||||||
*/
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW64__) || !defined(__STRICT_ANSI__)
|
|
||||||
#define MA_HAS_WFOPEN
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static ma_result ma_decoder__preinit_file_w(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
|
static ma_result ma_decoder__preinit_file_w(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
|
||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
@@ -38816,55 +38965,10 @@ static ma_result ma_decoder__preinit_file_w(const wchar_t* pFilePath, const ma_d
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MA_HAS_WFOPEN)
|
pFile = ma_wfopen(pFilePath, L"rb", &pDecoder->allocationCallbacks);
|
||||||
/* Use _wfopen() on Windows. */
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
||||||
if (_wfopen_s(&pFile, pFilePath, L"rb") != 0) {
|
|
||||||
return MA_ERROR;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
pFile = _wfopen(pFilePath, L"rb");
|
|
||||||
if (pFile == NULL) {
|
|
||||||
return MA_ERROR;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
Use fopen() on anything other than Windows. Requires a conversion. This is annoying because fopen() is locale specific. The only real way I can
|
|
||||||
think of to do this is with wcsrtombs(). Note that wcstombs() is apparently not thread-safe because it uses a static global mbstate_t object for
|
|
||||||
maintaining state. I've checked this with -std=c89 and it works, but if somebody get's a compiler error I'll look into improving compatibility.
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
mbstate_t mbs;
|
|
||||||
size_t lenMB;
|
|
||||||
const wchar_t* pFilePathTemp = pFilePath;
|
|
||||||
char* pFilePathMB = NULL;
|
|
||||||
|
|
||||||
/* Get the length first. */
|
|
||||||
MA_ZERO_OBJECT(&mbs);
|
|
||||||
lenMB = wcsrtombs(NULL, &pFilePathTemp, 0, &mbs);
|
|
||||||
if (lenMB == (size_t)-1) {
|
|
||||||
return MA_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
pFilePathMB = (char*)ma__malloc_from_callbacks(lenMB + 1, &pDecoder->allocationCallbacks);
|
|
||||||
if (pFilePathMB == NULL) {
|
|
||||||
return MA_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
pFilePathTemp = pFilePath;
|
|
||||||
MA_ZERO_OBJECT(&mbs);
|
|
||||||
wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
|
|
||||||
|
|
||||||
pFile = fopen(pFilePathMB, "rb");
|
|
||||||
|
|
||||||
ma__free_from_callbacks(pFilePathMB, &pDecoder->allocationCallbacks);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return MA_ERROR;
|
return MA_ERROR;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* We need to manually set the user data so the calls to ma_decoder__on_seek_stdio() succeed. */
|
/* We need to manually set the user data so the calls to ma_decoder__on_seek_stdio() succeed. */
|
||||||
pDecoder->pUserData = pFile;
|
pDecoder->pUserData = pFile;
|
||||||
@@ -39295,10 +39399,270 @@ ma_result ma_decode_memory(const void* pData, size_t dataSize, ma_decoder_config
|
|||||||
|
|
||||||
return ma_decoder__full_decode_and_uninit(&decoder, pConfig, pFrameCountOut, ppPCMFramesOut);
|
return ma_decoder__full_decode_and_uninit(&decoder, pConfig, pFrameCountOut, ppPCMFramesOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MA_NO_DECODING */
|
#endif /* MA_NO_DECODING */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MA_NO_ENCODING
|
||||||
|
|
||||||
|
#if defined(MA_HAS_WAV)
|
||||||
|
size_t ma_encoder__internal_on_write_wav(void* pUserData, const void* pData, size_t bytesToWrite)
|
||||||
|
{
|
||||||
|
ma_encoder* pEncoder = (ma_encoder*)pUserData;
|
||||||
|
MA_ASSERT(pEncoder != NULL);
|
||||||
|
|
||||||
|
return pEncoder->onWrite(pEncoder, pData, bytesToWrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
drwav_bool32 ma_encoder__internal_on_seek_wav(void* pUserData, int offset, drwav_seek_origin origin)
|
||||||
|
{
|
||||||
|
ma_encoder* pEncoder = (ma_encoder*)pUserData;
|
||||||
|
MA_ASSERT(pEncoder != NULL);
|
||||||
|
|
||||||
|
return pEncoder->onSeek(pEncoder, offset, (origin == drwav_seek_origin_start) ? ma_seek_origin_start : ma_seek_origin_current);
|
||||||
|
}
|
||||||
|
|
||||||
|
ma_result ma_encoder__on_init_wav(ma_encoder* pEncoder)
|
||||||
|
{
|
||||||
|
drwav_data_format wavFormat;
|
||||||
|
drwav_allocation_callbacks allocationCallbacks;
|
||||||
|
drwav* pWav;
|
||||||
|
|
||||||
|
MA_ASSERT(pEncoder != NULL);
|
||||||
|
|
||||||
|
pWav = (drwav*)ma__malloc_from_callbacks(sizeof(*pWav), &pEncoder->config.allocationCallbacks);
|
||||||
|
if (pWav == NULL) {
|
||||||
|
return MA_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
wavFormat.container = drwav_container_riff;
|
||||||
|
wavFormat.channels = pEncoder->config.channels;
|
||||||
|
wavFormat.sampleRate = pEncoder->config.sampleRate;
|
||||||
|
wavFormat.bitsPerSample = ma_get_bytes_per_sample(pEncoder->config.format) * 8;
|
||||||
|
if (pEncoder->config.format == ma_format_f32) {
|
||||||
|
wavFormat.format = DR_WAVE_FORMAT_IEEE_FLOAT;
|
||||||
|
} else {
|
||||||
|
wavFormat.format = DR_WAVE_FORMAT_PCM;
|
||||||
|
}
|
||||||
|
|
||||||
|
allocationCallbacks.pUserData = pEncoder->config.allocationCallbacks.pUserData;
|
||||||
|
allocationCallbacks.onMalloc = pEncoder->config.allocationCallbacks.onMalloc;
|
||||||
|
allocationCallbacks.onRealloc = pEncoder->config.allocationCallbacks.onRealloc;
|
||||||
|
allocationCallbacks.onFree = pEncoder->config.allocationCallbacks.onFree;
|
||||||
|
|
||||||
|
if (!drwav_init_write(pWav, &wavFormat, ma_encoder__internal_on_write_wav, ma_encoder__internal_on_seek_wav, pEncoder, &allocationCallbacks)) {
|
||||||
|
return MA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
pEncoder->pInternalEncoder = pWav;
|
||||||
|
|
||||||
|
return MA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ma_encoder__on_uninit_wav(ma_encoder* pEncoder)
|
||||||
|
{
|
||||||
|
drwav* pWav;
|
||||||
|
|
||||||
|
MA_ASSERT(pEncoder != NULL);
|
||||||
|
|
||||||
|
pWav = (drwav*)pEncoder->pInternalEncoder;
|
||||||
|
MA_ASSERT(pWav != NULL);
|
||||||
|
|
||||||
|
drwav_uninit(pWav);
|
||||||
|
ma__free_from_callbacks(pWav, &pEncoder->config.allocationCallbacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
ma_uint64 ma_encoder__on_write_pcm_frames_wav(ma_encoder* pEncoder, const void* pFramesIn, ma_uint64 frameCount)
|
||||||
|
{
|
||||||
|
drwav* pWav;
|
||||||
|
|
||||||
|
MA_ASSERT(pEncoder != NULL);
|
||||||
|
|
||||||
|
pWav = (drwav*)pEncoder->pInternalEncoder;
|
||||||
|
MA_ASSERT(pWav != NULL);
|
||||||
|
|
||||||
|
return drwav_write_pcm_frames(pWav, frameCount, pFramesIn);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ma_encoder_config ma_encoder_config_init(ma_resource_format resourceFormat, ma_format format, ma_uint32 channels, ma_uint32 sampleRate)
|
||||||
|
{
|
||||||
|
ma_encoder_config config;
|
||||||
|
|
||||||
|
MA_ZERO_OBJECT(&config);
|
||||||
|
config.resourceFormat = resourceFormat;
|
||||||
|
config.format = format;
|
||||||
|
config.channels = channels;
|
||||||
|
config.sampleRate = sampleRate;
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
ma_result ma_encoder_preinit(const ma_encoder_config* pConfig, ma_encoder* pEncoder)
|
||||||
|
{
|
||||||
|
ma_result result;
|
||||||
|
|
||||||
|
if (pEncoder == NULL) {
|
||||||
|
return MA_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
MA_ZERO_OBJECT(pEncoder);
|
||||||
|
|
||||||
|
if (pConfig == NULL) {
|
||||||
|
return MA_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pConfig->format == ma_format_unknown || pConfig->channels == 0 || pConfig->sampleRate == 0) {
|
||||||
|
return MA_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pEncoder->config = *pConfig;
|
||||||
|
|
||||||
|
result = ma_allocation_callbacks_init_copy(&pEncoder->config.allocationCallbacks, &pConfig->allocationCallbacks);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ma_result ma_encoder_init__internal(ma_encoder_write_proc onWrite, ma_encoder_seek_proc onSeek, void* pUserData, ma_encoder* pEncoder)
|
||||||
|
{
|
||||||
|
ma_result result;
|
||||||
|
|
||||||
|
/* This assumes ma_encoder_preinit() has been called prior. */
|
||||||
|
MA_ASSERT(pEncoder != NULL);
|
||||||
|
|
||||||
|
if (onWrite == NULL || onSeek == NULL) {
|
||||||
|
return MA_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pEncoder->onWrite = onWrite;
|
||||||
|
pEncoder->onSeek = onSeek;
|
||||||
|
pEncoder->pUserData = pUserData;
|
||||||
|
|
||||||
|
switch (pEncoder->config.resourceFormat)
|
||||||
|
{
|
||||||
|
case ma_resource_format_wav:
|
||||||
|
{
|
||||||
|
#if defined(MA_HAS_WAV)
|
||||||
|
pEncoder->onInit = ma_encoder__on_init_wav;
|
||||||
|
pEncoder->onUninit = ma_encoder__on_uninit_wav;
|
||||||
|
pEncoder->onWritePCMFrames = ma_encoder__on_write_pcm_frames_wav;
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
return MA_NO_BACKEND;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
default: return MA_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Getting here means we should have our backend callbacks set up. */
|
||||||
|
result = pEncoder->onInit(pEncoder);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef MA_NO_STDIO
|
||||||
|
size_t ma_encoder__on_write_stdio(ma_encoder* pEncoder, const void* pBufferIn, size_t bytesToWrite)
|
||||||
|
{
|
||||||
|
return fwrite(pBufferIn, 1, bytesToWrite, (FILE*)pEncoder->pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
ma_bool32 ma_encoder__on_seek_stdio(ma_encoder* pEncoder, int byteOffset, ma_seek_origin origin)
|
||||||
|
{
|
||||||
|
return fseek((FILE*)pEncoder->pFile, byteOffset, (origin == ma_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ma_result ma_encoder_init_file(const char* pFilePath, const ma_encoder_config* pConfig, ma_encoder* pEncoder)
|
||||||
|
{
|
||||||
|
ma_result result;
|
||||||
|
FILE* pFile;
|
||||||
|
|
||||||
|
result = ma_encoder_preinit(pConfig, pEncoder);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now open the file. If this fails we don't need to uninitialize the encoder. */
|
||||||
|
pFile = ma_fopen(pFilePath, "wb");
|
||||||
|
if (pFile == NULL) {
|
||||||
|
return MA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
pEncoder->pFile = pFile;
|
||||||
|
|
||||||
|
return ma_encoder_init__internal(ma_encoder__on_write_stdio, ma_encoder__on_seek_stdio, NULL, pEncoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
ma_result ma_encoder_init_file_w(const wchar_t* pFilePath, const ma_encoder_config* pConfig, ma_encoder* pEncoder)
|
||||||
|
{
|
||||||
|
ma_result result;
|
||||||
|
FILE* pFile;
|
||||||
|
|
||||||
|
result = ma_encoder_preinit(pConfig, pEncoder);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now open the file. If this fails we don't need to uninitialize the encoder. */
|
||||||
|
pFile = ma_wfopen(pFilePath, L"wb", &pEncoder->config.allocationCallbacks);
|
||||||
|
if (pFile != NULL) {
|
||||||
|
return MA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
pEncoder->pFile = pFile;
|
||||||
|
|
||||||
|
return ma_encoder_init__internal(ma_encoder__on_write_stdio, ma_encoder__on_seek_stdio, NULL, pEncoder);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ma_result ma_encoder_init(ma_encoder_write_proc onWrite, ma_encoder_seek_proc onSeek, void* pUserData, const ma_encoder_config* pConfig, ma_encoder* pEncoder)
|
||||||
|
{
|
||||||
|
ma_result result;
|
||||||
|
|
||||||
|
result = ma_encoder_preinit(pConfig, pEncoder);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ma_encoder_init__internal(onWrite, onSeek, pUserData, pEncoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ma_encoder_uninit(ma_encoder* pEncoder)
|
||||||
|
{
|
||||||
|
if (pEncoder == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEncoder->onUninit) {
|
||||||
|
pEncoder->onUninit(pEncoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef MA_NO_STDIO
|
||||||
|
/* If we have a file handle, close it. */
|
||||||
|
if (pEncoder->onWrite == ma_encoder__on_write_stdio) {
|
||||||
|
fclose((FILE*)pEncoder->pFile);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ma_uint64 ma_encoder_write_pcm_frames(ma_encoder* pEncoder, const void* pFramesIn, ma_uint64 frameCount)
|
||||||
|
{
|
||||||
|
if (pEncoder == NULL || pFramesIn == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pEncoder->onWritePCMFrames(pEncoder, pFramesIn, frameCount);
|
||||||
|
}
|
||||||
|
#endif /* MA_NO_ENCODING */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************************************************************************************************
|
/**************************************************************************************************************************************************************
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "../test_common/ma_test_common.c"
|
#include "../test_common/ma_test_common.c"
|
||||||
|
|
||||||
ma_result filtering_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_decoder* pDecoder, drwav* pEncoder)
|
ma_result filtering_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_decoder* pDecoder, ma_encoder* pEncoder)
|
||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder_config decoderConfig;
|
ma_decoder_config decoderConfig;
|
||||||
drwav_data_format wavFormat;
|
ma_encoder_config encoderConfig;
|
||||||
|
|
||||||
decoderConfig = ma_decoder_config_init(format, 0, 0);
|
decoderConfig = ma_decoder_config_init(format, 0, 0);
|
||||||
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, pDecoder);
|
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, pDecoder);
|
||||||
@@ -12,10 +12,11 @@ ma_result filtering_init_decoder_and_encoder(const char* pInputFilePath, const c
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
wavFormat = drwav_data_format_from_minaudio_format(pDecoder->outputFormat, pDecoder->outputChannels, pDecoder->outputSampleRate);
|
encoderConfig = ma_encoder_config_init(ma_resource_format_wav, pDecoder->outputFormat, pDecoder->outputChannels, pDecoder->outputSampleRate);
|
||||||
if (!drwav_init_file_write(pEncoder, pOutputFilePath, &wavFormat, NULL)) {
|
result = ma_encoder_init_file(pOutputFilePath, &encoderConfig, pEncoder);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(pDecoder);
|
ma_decoder_uninit(pDecoder);
|
||||||
return MA_ERROR;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
ma_result bpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, drwav* pEncoder)
|
ma_result bpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, ma_encoder* pEncoder)
|
||||||
{
|
{
|
||||||
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,13 @@ ma_result test_bpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
ma_bpf2_config bpfConfig;
|
ma_bpf2_config bpfConfig;
|
||||||
ma_bpf2 bpf;
|
ma_bpf2 bpf;
|
||||||
|
|
||||||
printf(" %s\n", pOutputFilePath);
|
printf(" %s\n", pOutputFilePath);
|
||||||
|
|
||||||
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ ma_result test_bpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
result = ma_bpf2_init(&bpfConfig, &bpf);
|
result = ma_bpf2_init(&bpfConfig, &bpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,14 +42,14 @@ ma_result test_bpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
ma_bpf2_process_pcm_frames(&bpf, tempOut, tempIn, framesJustRead);
|
ma_bpf2_process_pcm_frames(&bpf, tempOut, tempIn, framesJustRead);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,13 +68,13 @@ ma_result test_bpf4__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
ma_bpf_config bpfConfig;
|
ma_bpf_config bpfConfig;
|
||||||
ma_bpf bpf;
|
ma_bpf bpf;
|
||||||
|
|
||||||
printf(" %s\n", pOutputFilePath);
|
printf(" %s\n", pOutputFilePath);
|
||||||
|
|
||||||
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ ma_result test_bpf4__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
result = ma_bpf_init(&bpfConfig, &bpf);
|
result = ma_bpf_init(&bpfConfig, &bpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,14 +102,14 @@ ma_result test_bpf4__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
ma_bpf_process_pcm_frames(&bpf, tempOut, tempIn, framesJustRead);
|
ma_bpf_process_pcm_frames(&bpf, tempOut, tempIn, framesJustRead);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ ma_result test_dithering__u8(const char* pInputFilePath)
|
|||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder_config decoderConfig;
|
ma_decoder_config decoderConfig;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav_data_format wavFormat;
|
ma_encoder_config encoderConfig;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
|
|
||||||
decoderConfig = ma_decoder_config_init(ma_format_f32, 0, 0);
|
decoderConfig = ma_decoder_config_init(ma_format_f32, 0, 0);
|
||||||
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, &decoder);
|
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, &decoder);
|
||||||
@@ -14,10 +14,11 @@ ma_result test_dithering__u8(const char* pInputFilePath)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
wavFormat = drwav_data_format_from_minaudio_format(ma_format_u8, decoder.outputChannels, decoder.outputSampleRate);
|
encoderConfig = ma_encoder_config_init(ma_resource_format_wav, ma_format_u8, decoder.outputChannels, decoder.outputSampleRate);
|
||||||
if (!drwav_init_file_write(&wav, pOutputFilePath, &wavFormat, NULL)) {
|
result = ma_encoder_init_file(pOutputFilePath, &encoderConfig, &encoder);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
return MA_ERROR;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -35,14 +36,14 @@ ma_result test_dithering__u8(const char* pInputFilePath)
|
|||||||
ma_convert_pcm_frames_format(tempOut, ma_format_u8, tempIn, decoder.outputFormat, framesJustRead, decoder.outputChannels, ma_dither_mode_triangle);
|
ma_convert_pcm_frames_format(tempOut, ma_format_u8, tempIn, decoder.outputFormat, framesJustRead, decoder.outputChannels, ma_dither_mode_triangle);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
ma_result hpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, drwav* pEncoder)
|
ma_result hpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, ma_encoder* pEncoder)
|
||||||
{
|
{
|
||||||
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,13 @@ ma_result test_hpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
ma_hpf1_config hpfConfig;
|
ma_hpf1_config hpfConfig;
|
||||||
ma_hpf1 hpf;
|
ma_hpf1 hpf;
|
||||||
|
|
||||||
printf(" %s\n", pOutputFilePath);
|
printf(" %s\n", pOutputFilePath);
|
||||||
|
|
||||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ ma_result test_hpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
result = ma_hpf1_init(&hpfConfig, &hpf);
|
result = ma_hpf1_init(&hpfConfig, &hpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,14 +42,14 @@ ma_result test_hpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
ma_hpf1_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
ma_hpf1_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,13 +68,13 @@ ma_result test_hpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
ma_hpf2_config hpfConfig;
|
ma_hpf2_config hpfConfig;
|
||||||
ma_hpf2 hpf;
|
ma_hpf2 hpf;
|
||||||
|
|
||||||
printf(" %s\n", pOutputFilePath);
|
printf(" %s\n", pOutputFilePath);
|
||||||
|
|
||||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ ma_result test_hpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
result = ma_hpf2_init(&hpfConfig, &hpf);
|
result = ma_hpf2_init(&hpfConfig, &hpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,14 +102,14 @@ ma_result test_hpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
ma_hpf2_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
ma_hpf2_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,13 +128,13 @@ ma_result test_hpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
ma_hpf_config hpfConfig;
|
ma_hpf_config hpfConfig;
|
||||||
ma_hpf hpf;
|
ma_hpf hpf;
|
||||||
|
|
||||||
printf(" %s\n", pOutputFilePath);
|
printf(" %s\n", pOutputFilePath);
|
||||||
|
|
||||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ ma_result test_hpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
result = ma_hpf_init(&hpfConfig, &hpf);
|
result = ma_hpf_init(&hpfConfig, &hpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,14 +162,14 @@ ma_result test_hpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
ma_hpf_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
ma_hpf_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
ma_result lpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, drwav* pEncoder)
|
ma_result lpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, ma_encoder* pEncoder)
|
||||||
{
|
{
|
||||||
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,13 @@ ma_result test_lpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
ma_lpf1_config lpfConfig;
|
ma_lpf1_config lpfConfig;
|
||||||
ma_lpf1 lpf;
|
ma_lpf1 lpf;
|
||||||
|
|
||||||
printf(" %s\n", pOutputFilePath);
|
printf(" %s\n", pOutputFilePath);
|
||||||
|
|
||||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ ma_result test_lpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
result = ma_lpf1_init(&lpfConfig, &lpf);
|
result = ma_lpf1_init(&lpfConfig, &lpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,14 +42,14 @@ ma_result test_lpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
ma_lpf1_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
ma_lpf1_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,13 +68,13 @@ ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
ma_lpf2_config lpfConfig;
|
ma_lpf2_config lpfConfig;
|
||||||
ma_lpf2 lpf;
|
ma_lpf2 lpf;
|
||||||
|
|
||||||
printf(" %s\n", pOutputFilePath);
|
printf(" %s\n", pOutputFilePath);
|
||||||
|
|
||||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
result = ma_lpf2_init(&lpfConfig, &lpf);
|
result = ma_lpf2_init(&lpfConfig, &lpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,14 +102,14 @@ ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
ma_lpf2_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
ma_lpf2_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,13 +129,13 @@ ma_result test_lpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav wav;
|
ma_encoder encoder;
|
||||||
ma_lpf_config lpfConfig;
|
ma_lpf_config lpfConfig;
|
||||||
ma_lpf lpf;
|
ma_lpf lpf;
|
||||||
|
|
||||||
printf(" %s\n", pOutputFilePath);
|
printf(" %s\n", pOutputFilePath);
|
||||||
|
|
||||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ ma_result test_lpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
result = ma_lpf_init(&lpfConfig, &lpf);
|
result = ma_lpf_init(&lpfConfig, &lpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,14 +163,14 @@ ma_result test_lpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
|||||||
ma_lpf_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
ma_lpf_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||||
|
|
||||||
/* Write to the WAV file. */
|
/* Write to the WAV file. */
|
||||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||||
|
|
||||||
if (framesJustRead < framesToRead) {
|
if (framesJustRead < framesToRead) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
ma_encoder_uninit(&encoder);
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user