Skip to content

Commit a56bb4e

Browse files
author
dashodanger
committed
Add int16_t output to pl_mpeg
1 parent ebebbd4 commit a56bb4e

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

libraries/pl_mpeg/pl_mpeg.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#define PL_MPEG_IMPLEMENTATION
2+
#define PLM_AUDIO_INTERLEAVED_SHORT
23

34
#include "pl_mpeg.h"

libraries/pl_mpeg/pl_mpeg.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,11 @@ typedef void(*plm_video_decode_callback)
248248
typedef struct {
249249
double time;
250250
unsigned int count;
251-
#ifdef PLM_AUDIO_SEPARATE_CHANNELS
251+
#if defined PLM_AUDIO_SEPARATE_CHANNELS
252252
float left[PLM_AUDIO_SAMPLES_PER_FRAME];
253253
float right[PLM_AUDIO_SAMPLES_PER_FRAME];
254+
#elif defined PLM_AUDIO_INTERLEAVED_SHORT
255+
int16_t interleaved[PLM_AUDIO_SAMPLES_PER_FRAME * 2];
254256
#else
255257
float interleaved[PLM_AUDIO_SAMPLES_PER_FRAME * 2];
256258
#endif
@@ -4121,6 +4123,20 @@ void plm_audio_decode_frame(plm_audio_t *self) {
41214123
for (int j = 0; j < 32; j++) {
41224124
out_channel[out_pos + j] = self->U[j] / 2147418112.0f;
41234125
}
4126+
#elif defined PLM_AUDIO_INTERLEAVED_SHORT
4127+
for (int j = 0; j < 32; j++) {
4128+
float x = self->U[j] / 2147418112.0f + 384.0f;
4129+
#if defined _MSC_VER || (defined __SIZEOF_FLOAT__ && __SIZEOF_FLOAT__ == 4)
4130+
uint32_t y = *(uint32_t *)&x - 0x43C00000u;
4131+
uint32_t z = 0x7FFFu - (y ^ (0u - (y >> 31)));
4132+
y = y ^ (z & (0u - (z >> 31)));
4133+
self->samples.interleaved[((out_pos + j) << 1) + ch] =
4134+
(int16_t)(y & 0xFFFF);
4135+
#else
4136+
self->samples.interleaved[((out_pos + j) << 1) + ch] =
4137+
(int16)(x * 0x8000);
4138+
#endif
4139+
}
41244140
#else
41254141
for (int j = 0; j < 32; j++) {
41264142
self->samples.interleaved[((out_pos + j) << 1) + ch] =

source_files/edge/i_movie.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ void MovieAudioCallback(plm_t *mpeg, plm_samples_t *samples, void *user)
6464
{
6565
(void)mpeg;
6666
(void)user;
67-
//SoundData *movie_buf = SoundQueueGetFreeBuffer(PLM_AUDIO_SAMPLES_PER_FRAME);
68-
//if (movie_buf)
67+
SoundData *movie_buf = SoundQueueGetFreeBuffer(PLM_AUDIO_SAMPLES_PER_FRAME);
68+
if (movie_buf)
6969
{
70-
/*movie_buf->length_ = PLM_AUDIO_SAMPLES_PER_FRAME;
71-
memcpy(movie_buf->data_, samples->interleaved, PLM_AUDIO_SAMPLES_PER_FRAME * 2 * sizeof(float));
72-
SoundQueueAddBuffer(movie_buf, movie_sample_rate);*/
70+
movie_buf->length_ = PLM_AUDIO_SAMPLES_PER_FRAME;
71+
memcpy(movie_buf->data_, samples->interleaved, PLM_AUDIO_SAMPLES_PER_FRAME * 2 * sizeof(int16_t));
72+
SoundQueueAddBuffer(movie_buf, movie_sample_rate);
7373
}
7474
}
7575

0 commit comments

Comments
 (0)