I am just a new guy in android studio.This is my code for improving gain of a audio(mp3,wav)file.I don't know how to implement in android studio.I already stored a mp3 file in raw directory,I am using text box or seek bar for getting gain value from user and after it will play the improved gain audio.Can anyone know how to do this?
#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;
}