Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / libmpeg3 / audio / pcm.c
blob4904dcb30af21f5925c5ab729e29ea93822f3b3e
1 #include "mpeg3private.h"
2 #include "mpeg3protos.h"
4 #include <stdlib.h>
7 mpeg3_pcm_t* mpeg3_new_pcm()
9 mpeg3_pcm_t *result = calloc(1, sizeof(mpeg3_pcm_t));
10 return result;
15 void mpeg3_delete_pcm(mpeg3_pcm_t *audio)
17 free(audio);
21 int mpeg3_pcm_check(unsigned char *header)
23 if(header[0] == ((MPEG3_PCM_START_CODE & 0xff000000) >> 24) &&
24 header[1] == ((MPEG3_PCM_START_CODE & 0xff0000) >> 16) &&
25 header[2] == ((MPEG3_PCM_START_CODE & 0xff00) >> 8) &&
26 header[3] == (MPEG3_PCM_START_CODE & 0xff))
27 return 0;
28 else
29 return 1;
35 int mpeg3_pcm_header(mpeg3_pcm_t *audio, unsigned char *data)
37 if(mpeg3_pcm_check(data)) return 0;
39 /* Custom header generated by the demuxer */
40 audio->samplerate = *(int32_t*)(data + 4);
41 audio->bits = *(int32_t*)(data + 8);
42 audio->channels = *(int32_t*)(data + 12);
43 audio->framesize = *(int32_t*)(data + 16);
45 return audio->framesize;
48 int mpeg3audio_dopcm(mpeg3_pcm_t *audio,
49 char *frame,
50 int frame_size,
51 float **output,
52 int render)
54 int bytes_per_sample = audio->bits / 8 * audio->channels;
55 int output_size = (frame_size - PCM_HEADERSIZE) / bytes_per_sample;
56 int i, j;
57 //printf("mpeg3audio_dopcm 2 %d\n", frame_size);
59 if(render)
61 for(i = 0; i < audio->channels; i++)
63 //printf("mpeg3audio_dopcm 3\n");
64 float *output_channel = output[i];
65 //printf("mpeg3audio_dopcm 4\n");
66 switch(audio->bits)
68 case 16:
70 //printf("mpeg3audio_dopcm 5\n");
71 unsigned char *input = frame +
72 PCM_HEADERSIZE +
73 audio->bits / 8 * i;
74 int16_t sample;
75 //printf("mpeg3audio_dopcm 6\n");
76 for(j = 0; j < output_size; j++)
78 sample = ((int16_t)(input[0])) << 8;
79 sample |= input[1];
80 *output_channel = (float)sample / 32767.0;
81 input += bytes_per_sample;
82 output_channel++;
84 //printf("mpeg3audio_dopcm 7\n");
86 break;
92 * printf("mpeg3audio_dopcm 2 %02x%02x%02x%02x\n",
93 * *(unsigned char*)(frame + PCM_HEADERSIZE + 0),
94 * *(unsigned char*)(frame + PCM_HEADERSIZE + 1),
95 * *(unsigned char*)(frame + PCM_HEADERSIZE + 2),
96 * *(unsigned char*)(frame + PCM_HEADERSIZE + 3));
99 return output_size;