我只是 android studio 的新人。这是我提高音频(mp3,wav)文件增益的代码。我不知道如何在 android studio 中实现。我已经在 raw 目录中存储了一个 mp3 文件,我正在使用文本框或搜索栏从用户那里获取增益值,之后它将播放改进的增益音频。有人知道该怎么做吗?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef struct header_file
{
char chunk_id[4];
int chunk_size;
char format[4];
char subchunk1_id[4];
int subchunk1_size;
short int audio_format;
short int num_channels;
int sample_rate;
int byte_rate;
short int block_align;
short int bits_per_sample;
char subchunk2_id[4];
int subchunk2_size;
} header;
typedef struct header_file* header_p;
typedef float float32_t;
typedef int uint32_t;
FILE *fr, *fw;
float fs;
#define FRAME 256
int main(int argc, char *argv[] )
{
char a[100];
strcpy(a,argv[1]);
int gain=atoi(a);
fr = fopen("sweeptest.wav", "rb");
fw = fopen( "out1.wav", "wb");
header_p meta = (header_p) malloc(sizeof(header));
fread(meta, 1, sizeof(header), fr);
fwrite(meta, 1, sizeof(header), fw);
fs = meta->sample_rate;
float src[FRAME] = { 0 };
float out1[FRAME] = { 0 };
float out[FRAME] = { 0 };
short Inbuf[256] = { 0 };
short outbuf[256] = { 0 };
int i=0;
float j = gain/20;
float gain_value = pow(10,j);
while (!feof(fr)) {
fread(Inbuf, sizeof(short int), FRAME, fr);
for ( i = 0; i < FRAME; i++)
{
src[i] = (float)(Inbuf[i] / 32767.f);
out1[i] = (src[i] * gain_value);
outbuf[i] =(short)( (out1[i]* 32767.f));
}
fwrite(outbuf, sizeof(short int), FRAME, fw);
}
printf("Program finished");
return 0;
}