refactor mpr layer
This commit is contained in:
parent
07eb5db9df
commit
08a69f4a31
@ -1,7 +1,7 @@
|
||||
#include "mp3.h"
|
||||
|
||||
#if PlatformIsWindows
|
||||
# include "mp3_core_mmf.c"
|
||||
# include "mp3_mmf.c"
|
||||
#else
|
||||
# error Mp3 core not implemented for this platform
|
||||
#endif
|
||||
|
||||
@ -5,4 +5,19 @@
|
||||
|
||||
#include "mp3_core.h"
|
||||
|
||||
#if PlatformIsWindows
|
||||
#pragma warning(push, 0)
|
||||
# define COBJMACROS
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# define UNICODE
|
||||
# include <Windows.h>
|
||||
# include <uuids.h>
|
||||
# include <mfapi.h>
|
||||
# include <mfidl.h>
|
||||
# include <mfreadwrite.h>
|
||||
# include <Shlwapi.h>
|
||||
# pragma warning(pop)
|
||||
# include "mp3_mmf.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,10 +1,20 @@
|
||||
#define MP3_DECODE_FLAG_NONE 0x00
|
||||
#define MP3_DECODE_FLAG_STEREO 0x01
|
||||
////////////////////////////////
|
||||
//~ Mp3 structs
|
||||
|
||||
Struct(MP3_Result) {
|
||||
typedef u32 MP3_DecodeFlag; enum
|
||||
{
|
||||
MP3_DecodeFlag_None = (0),
|
||||
MP3_DecodeFlag_Stereo = (1 << 0),
|
||||
};
|
||||
|
||||
Struct(MP3_Result)
|
||||
{
|
||||
u64 samples_count;
|
||||
i16 *samples;
|
||||
b32 success;
|
||||
};
|
||||
|
||||
MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags);
|
||||
////////////////////////////////
|
||||
//~ Mp3 operations
|
||||
|
||||
MP3_Result MP3_Decode(Arena *arena, String encoded, u32 sample_rate, MP3_DecodeFlag flags);
|
||||
|
||||
@ -1,31 +1,15 @@
|
||||
/* ========================== *
|
||||
* Microsoft Media Foundation (MMF) mp3 decoder
|
||||
* ========================== */
|
||||
|
||||
#pragma warning(push, 0)
|
||||
# define COBJMACROS
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# define UNICODE
|
||||
# include <Windows.h>
|
||||
# include <uuids.h>
|
||||
# include <mfapi.h>
|
||||
# include <mfidl.h>
|
||||
# include <mfreadwrite.h>
|
||||
# include <Shlwapi.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma comment(lib, "mfplat")
|
||||
#pragma comment(lib, "mfreadwrite")
|
||||
#pragma comment(lib, "shlwapi")
|
||||
|
||||
MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
|
||||
MP3_Result MP3_Decode(Arena *arena, String encoded, u32 sample_rate, MP3_DecodeFlag flags)
|
||||
{
|
||||
MP3_Result result = ZI;
|
||||
u64 bytes_per_sample = 2;
|
||||
|
||||
u64 channel_count;
|
||||
u32 channel_mask;
|
||||
if (flags & MP3_DECODE_FLAG_STEREO) {
|
||||
if (flags & MP3_DecodeFlag_Stereo) {
|
||||
channel_count = 2;
|
||||
channel_mask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
|
||||
} else {
|
||||
@ -33,9 +17,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
|
||||
channel_mask = SPEAKER_FRONT_CENTER;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Startup
|
||||
* ========================== */
|
||||
//- Startup
|
||||
|
||||
MFStartup(MF_VERSION, MFSTARTUP_LITE);
|
||||
|
||||
@ -50,9 +32,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
|
||||
IMFSourceReader *reader;
|
||||
MFCreateSourceReaderFromByteStream(byte_stream, 0, &reader);
|
||||
|
||||
/* ========================== *
|
||||
* Get media type
|
||||
* ========================== */
|
||||
//- Get media type
|
||||
|
||||
/* Read only first audio stream */
|
||||
IMFSourceReader_SetStreamSelection(reader, (DWORD)MF_SOURCE_READER_ALL_STREAMS, 0);
|
||||
@ -80,9 +60,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
|
||||
IMFSourceReader_SetCurrentMediaType(reader, (DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, type);
|
||||
IMFMediaType_Release(type);
|
||||
|
||||
/* ========================== *
|
||||
* Read
|
||||
* ========================== */
|
||||
//- Read
|
||||
|
||||
result.samples = PushDry(arena, i16);
|
||||
u64 sample_bytes_read = 0;
|
||||
@ -121,9 +99,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
|
||||
|
||||
result.samples_count = sample_bytes_read / bytes_per_sample;
|
||||
|
||||
/* ========================== *
|
||||
* Cleanup
|
||||
* ========================== */
|
||||
//- Cleanup
|
||||
|
||||
IMFSourceReader_Release(reader);
|
||||
IMFByteStream_Close(byte_stream);
|
||||
0
src/mp3/mp3_mmf.h
Normal file
0
src/mp3/mp3_mmf.h
Normal file
@ -8,24 +8,24 @@
|
||||
#include "platform_log.h"
|
||||
|
||||
#if PlatformIsWindows
|
||||
#pragma warning(push, 0)
|
||||
# define UNICODE
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# pragma warning(push, 0)
|
||||
# define UNICODE
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
/* FIXME: Remove this */
|
||||
# define NTDDI_WIN11_DT 0x0C0A0000
|
||||
# define NTDDI_VERSION 0x0A000000
|
||||
# include <Windows.h>
|
||||
# include <WinSock2.h>
|
||||
# include <TlHelp32.h>
|
||||
# include <WS2tcpip.h>
|
||||
# include <windowsx.h>
|
||||
# include <ShlObj_core.h>
|
||||
# include <fileapi.h>
|
||||
# include <dwmapi.h>
|
||||
# include <bcrypt.h>
|
||||
# include <avrt.h>
|
||||
# include <shellapi.h>
|
||||
#pragma warning(pop)
|
||||
# define NTDDI_WIN11_DT 0x0C0A0000
|
||||
# define NTDDI_VERSION 0x0A000000
|
||||
# include <Windows.h>
|
||||
# include <WinSock2.h>
|
||||
# include <TlHelp32.h>
|
||||
# include <WS2tcpip.h>
|
||||
# include <windowsx.h>
|
||||
# include <ShlObj_core.h>
|
||||
# include <fileapi.h>
|
||||
# include <dwmapi.h>
|
||||
# include <bcrypt.h>
|
||||
# include <avrt.h>
|
||||
# include <shellapi.h>
|
||||
# pragma warning(pop)
|
||||
# include "platform_win32.h"
|
||||
#endif
|
||||
|
||||
|
||||
@ -90,9 +90,9 @@ internal P_JobDef(sound_load_asset_job, job)
|
||||
if (resource_exists(&sound_rs)) {
|
||||
u64 decode_flags = 0;
|
||||
if (flags & SOUND_FLAG_STEREO) {
|
||||
decode_flags |= MP3_DECODE_FLAG_STEREO;
|
||||
decode_flags |= MP3_DecodeFlag_Stereo;
|
||||
}
|
||||
decoded = mp3_decode(scratch.arena, resource_get_data(&sound_rs), SOUND_SAMPLE_RATE, decode_flags);
|
||||
decoded = MP3_Decode(scratch.arena, resource_get_data(&sound_rs), SOUND_SAMPLE_RATE, decode_flags);
|
||||
if (!decoded.success) {
|
||||
error_msg = Lit("Failed to decode sound file");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user