summaryrefslogtreecommitdiff
path: root/src/audio/mp3_sample.h
blob: bf3147a987ae8a7cb6356e3ea7e5ad62033f88be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// This file is part of the 64k demo project.
// Experimental MP3 sample decoding (non-STRIP_ALL only).
// Entire API unavailable when STRIP_ALL is defined (compile error on use).

#pragma once
#include <cstddef>
#include <cstdint>

#if !defined(STRIP_ALL)

// Opaque MP3 decoder. Create with mp3_open(), destroy with mp3_close().
// Output format: mono f32 PCM at 32 kHz (matches synth sample rate).
// |data| passed to mp3_open() must remain valid for the decoder's lifetime
// (embedded asset byte arrays satisfy this automatically).
struct Mp3Decoder;

// Open an in-memory MP3 blob for range decoding.
// Returns nullptr on error.
Mp3Decoder* mp3_open(const uint8_t* data, size_t size);

// Seek to |start_frame| and decode up to |num_frames| f32 mono samples into
// |out|. Returns the number of frames actually decoded (may be < num_frames at
// end of stream).
int mp3_decode_range(Mp3Decoder* dec, int start_frame, int num_frames,
                     float* out);

// Read up to |num_frames| f32 mono samples sequentially from current position.
// Returns frames decoded (< num_frames means end of stream).
int mp3_decode(Mp3Decoder* dec, int num_frames, float* out);

// Release the decoder.
void mp3_close(Mp3Decoder* dec);

#endif // !STRIP_ALL