Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/audio/pcm.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmpeg3/audio/pcm.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/audio/pcm.c b/core/multimedia/opieplayer/libmpeg3/audio/pcm.c new file mode 100644 index 0000000..8fa0d25 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/pcm.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include "mpeg3audio.h" | ||
2 | #include "../libmpeg3.h" | ||
3 | #include "../mpeg3protos.h" | ||
4 | |||
5 | int mpeg3audio_read_pcm_header(mpeg3audio_t *audio) | ||
6 | { | ||
7 | unsigned int code; | ||
8 | |||
9 | code = mpeg3bits_getbits(audio->astream, 16); | ||
10 | while(!mpeg3bits_eof(audio->astream) && code != MPEG3_PCM_START_CODE) | ||
11 | { | ||
12 | code <<= 8; | ||
13 | code &= 0xffff; | ||
14 | code |= mpeg3bits_getbits(audio->astream, 8); | ||
15 | } | ||
16 | |||
17 | audio->avg_framesize = audio->framesize = 0x7db; | ||
18 | audio->channels = 2; | ||
19 | |||
20 | return mpeg3bits_eof(audio->astream); | ||
21 | } | ||
22 | |||
23 | int mpeg3audio_do_pcm(mpeg3audio_t *audio) | ||
24 | { | ||
25 | int i, j, k; | ||
26 | MPEG3_INT16 sample; | ||
27 | int frame_samples = (audio->framesize - 3) / audio->channels / 2; | ||
28 | |||
29 | if(mpeg3bits_read_buffer(audio->astream, audio->ac3_buffer, frame_samples * audio->channels * 2)) | ||
30 | return 1; | ||
31 | |||
32 | /* Need more room */ | ||
33 | if(audio->pcm_point / audio->channels >= audio->pcm_allocated - MPEG3AUDIO_PADDING * audio->channels) | ||
34 | { | ||
35 | mpeg3audio_replace_buffer(audio, audio->pcm_allocated + MPEG3AUDIO_PADDING * audio->channels); | ||
36 | } | ||
37 | |||
38 | k = 0; | ||
39 | for(i = 0; i < frame_samples; i++) | ||
40 | { | ||
41 | for(j = 0; j < audio->channels; j++) | ||
42 | { | ||
43 | sample = ((MPEG3_INT16)(audio->ac3_buffer[k++])) << 8; | ||
44 | sample |= audio->ac3_buffer[k++]; | ||
45 | audio->pcm_sample[audio->pcm_point + i * audio->channels + j] = | ||
46 | (mpeg3_real_t)sample / 32767; | ||
47 | } | ||
48 | } | ||
49 | audio->pcm_point += frame_samples * audio->channels; | ||
50 | return 0; | ||
51 | } | ||