File: pcm.c

package info (click to toggle)
libmpeg3 1.8.dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 3,900 kB
  • ctags: 2,881
  • sloc: ansic: 18,524; asm: 761; makefile: 301; sh: 26
file content (100 lines) | stat: -rw-r--r-- 2,158 bytes parent folder | download | duplicates (6)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "mpeg3private.h"
#include "mpeg3protos.h"

#include <stdlib.h>


mpeg3_pcm_t* mpeg3_new_pcm()
{
	mpeg3_pcm_t *result = calloc(1, sizeof(mpeg3_pcm_t));
	return result;
}



void mpeg3_delete_pcm(mpeg3_pcm_t *audio)
{
	free(audio);
}


int mpeg3_pcm_check(unsigned char *header)
{
	if(header[0] == ((MPEG3_PCM_START_CODE & 0xff000000) >> 24) &&
		header[1] == ((MPEG3_PCM_START_CODE & 0xff0000) >> 16) &&
		header[2] == ((MPEG3_PCM_START_CODE & 0xff00) >> 8) &&
		header[3] == (MPEG3_PCM_START_CODE & 0xff))
		return 0;
	else
		return 1;
}




int mpeg3_pcm_header(mpeg3_pcm_t *audio, unsigned char *data)
{
	if(mpeg3_pcm_check(data)) return 0;

/* Custom header generated by the demuxer */
	audio->samplerate = *(int32_t*)(data + 4);
	audio->bits = *(int32_t*)(data + 8);
	audio->channels = *(int32_t*)(data + 12);
	audio->framesize = *(int32_t*)(data + 16);

	return audio->framesize;
}

int mpeg3audio_dopcm(mpeg3_pcm_t *audio, 
	char *frame, 
	int frame_size, 
	float **output,
	int render)
{
	int bytes_per_sample = audio->bits / 8 * audio->channels;
	int output_size = (frame_size - PCM_HEADERSIZE) / bytes_per_sample;
	int i, j;
//printf("mpeg3audio_dopcm 2 %d\n", frame_size);

	if(render)
	{
		for(i = 0; i < audio->channels; i++)
		{
//printf("mpeg3audio_dopcm 3\n");
			float *output_channel = output[i];
//printf("mpeg3audio_dopcm 4\n");
			switch(audio->bits)
			{
				case 16:
				{
//printf("mpeg3audio_dopcm 5\n");
					unsigned char *input = frame + 
						PCM_HEADERSIZE + 
						audio->bits / 8 * i;
						int16_t sample;
//printf("mpeg3audio_dopcm 6\n");
					for(j = 0; j < output_size; j++)
					{
						sample = ((int16_t)(input[0])) << 8;
						sample |= input[1];
						*output_channel = (float)sample / 32767.0;
						input += bytes_per_sample;
						output_channel++;
					}
//printf("mpeg3audio_dopcm 7\n");
				}
					break;
			}
		}
	}

/*
 * printf("mpeg3audio_dopcm 2 %02x%02x%02x%02x\n", 
 * *(unsigned char*)(frame + PCM_HEADERSIZE + 0),
 * *(unsigned char*)(frame + PCM_HEADERSIZE + 1),
 * *(unsigned char*)(frame + PCM_HEADERSIZE + 2),
 * *(unsigned char*)(frame + PCM_HEADERSIZE + 3));
 */

	return output_size;
}