forked from xufuji456/FFmpegAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcm_process.cpp
More file actions
93 lines (83 loc) · 2.22 KB
/
pcm_process.cpp
File metadata and controls
93 lines (83 loc) · 2.22 KB
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
//
// Created by xu fulong on 2022/8/5.
//
#include <cstdio>
#include <cerrno>
#include <cstdlib>
#include <cstring>
void pcm_raise_speed(char *input_path, char *output_path)
{
FILE *input = fopen(input_path, "rb+");
FILE *output = fopen(output_path, "wb+");
if (!input && !output) {
printf("open file fail, msg=%s\n", strerror(errno));
return;
}
int count = 0;
char *buf = (char*) malloc(sizeof(char) * 4);
while(!feof(input)) {
fread(buf, sizeof(char), 4, input);
if (count % 2 == 0) {
// L
fwrite(buf, sizeof(char), 2, output);
// R
fwrite(buf + 2, sizeof(char), 2, output);
}
count++;
}
free(buf);
fclose(output);
fclose(input);
}
void pcm_change_volume(char *input_path, char *output_path)
{
FILE *input = fopen(input_path, "rb+");
FILE *output = fopen(output_path, "wb+");
if (!input && !output) {
printf("open file fail, msg=%s\n", strerror(errno));
return;
}
int count = 0;
char *buf = (char*) malloc(sizeof(char) * 4);
while(!feof(input)) {
fread(buf, sizeof(char), 4, input);
short *left = (short*) buf;
*left /= 2;
short *right = (short*) (buf + 2);
*right /= 2;
// L
fwrite(left, sizeof(short), 1, output);
// R
fwrite(right, sizeof(short), 1, output);
count++;
}
printf("resample count=%d\n", count);
free(buf);
fclose(output);
fclose(input);
}
void pcm_split_channel(char *input_path, char *left_path, char *right_path)
{
FILE *input = fopen(input_path, "rb+");
FILE *left = fopen(left_path, "wb+");
FILE *right = fopen(right_path, "wb+");
if (!input && !left && !right) {
printf("open file fail, msg=%s\n", strerror(errno));
return;
}
int count = 0;
char *buf = (char*) malloc(sizeof(char) * 4);
while(!feof(input)) {
fread(buf, sizeof(char), 4, input);
// L
fwrite(buf, sizeof(char), 2, left);
// R
fwrite(buf+2, sizeof(char), 2, right);
count++;
}
printf("resample count=%d\n", count);
free(buf);
fclose(left);
fclose(right);
fclose(input);
}