summaryrefslogtreecommitdiff
path: root/WasmAudio
diff options
context:
space:
mode:
authorZoRo <dos21h@gmail.com>2021-07-28 08:02:21 +0100
committerZoRo <dos21h@gmail.com>2021-07-28 08:02:21 +0100
commit76b7852f88b70bfb419bb1c6e9bef457c10e23a4 (patch)
tree4f1b250d8866d0e31389b83db6ea6fb46c96fd8e /WasmAudio
parent2511c4fa6b2f5c4fae85a7b2e8ff12001318d9cd (diff)
downloadWasmAudio-76b7852f88b70bfb419bb1c6e9bef457c10e23a4.tar.gz
WasmAudio-76b7852f88b70bfb419bb1c6e9bef457c10e23a4.zip
Preparing usable webgui
Diffstat (limited to 'WasmAudio')
-rw-r--r--WasmAudio/main.c78
1 files changed, 65 insertions, 13 deletions
diff --git a/WasmAudio/main.c b/WasmAudio/main.c
index 4987fff..ab17933 100644
--- a/WasmAudio/main.c
+++ b/WasmAudio/main.c
@@ -84,7 +84,8 @@ uint8_t *audio_rec_buffer=NULL;
FILE *f_1,*f_2;
fir_t fir_lp;
firw_t firw_lp;
-const int N=200;
+//const int N=200;
+#define N (200)
double h[N],w[N];
int filter_N=60;
int filter_FS_hz=48000;
@@ -164,13 +165,11 @@ int KEEPALIVE get_sample_rate() {
return filter_FS_hz;
}
-void set_sample_rate() {
-
-}
-
-void set_cutoff_freq(int cutoff) {
- if (cutoff < 0) {
+void KEEPALIVE set_cutoff_freq(int cutoff) {
+ printf(" cutoff=%d\n", cutoff);
+ if (cutoff <= 0) {
cutoff = 0;
+ printf(" cutoff=%d\n", cutoff);
filter_FC_hz = cutoff;
return;
}
@@ -178,9 +177,19 @@ void set_cutoff_freq(int cutoff) {
if (cutoff > filter_FS_hz/2) {
cutoff = filter_FS_hz/2;
filter_FC_hz = cutoff;
- filter_FC=1.0*cutoff/filter_FS_hz;
+ printf(" cutoff=%d\n", cutoff);
+ filter_FC=1.0*filter_FC_hz/filter_FS_hz;
return;
}
+ filter_FC_hz = cutoff;
+}
+
+void KEEPALIVE set_cutoff_plus_1k() {
+ set_cutoff_freq(filter_FC_hz+1000);
+}
+
+void KEEPALIVE set_cutoff_minus_1k() {
+ set_cutoff_freq(filter_FC_hz-1000);
}
int KEEPALIVE get_cutoff_freq() {
@@ -191,15 +200,31 @@ int KEEPALIVE get_tap_number() {
return filter_N;
}
-void set_tap_number(int tapN) {
+
+
+void KEEPALIVE set_tap_number(int tapN) {
if (tapN<10) {
- tapN = 10;
+ filter_N = 10;
return;
-
}
+
+ if (tapN>N) {
+ filter_N = 100;
+ return;
+ }
+
+ filter_N = tapN;
+}
+
+void KEEPALIVE set_tap_number_plus_10() {
+ set_tap_number(filter_N+10);
+}
+
+void KEEPALIVE set_tap_number_minus_10() {
+ set_tap_number(filter_N-10);
}
-int KEEPALIVE recalculate_fir() {
+int KEEPALIVE recalculate_fir(double *arr) {
int i = 0;
filter_FC=1.0*filter_FC_hz/filter_FS_hz;
fir_lp.num_taps =filter_N;
@@ -220,7 +245,10 @@ int KEEPALIVE recalculate_fir() {
//firw_rect(&firw_lp);
fir_convolute(&fir_lp, &firw_lp);
//fir_print_matlab(&fir_lp);
- return 0;
+ for (i=0;i<fir_lp.num_taps;i++) {
+ arr[i] = fir_lp.fir_coef[i];
+ }
+ return fir_lp.num_taps;
}
@@ -236,6 +264,26 @@ void convert_dobule_up() {
}
}
+void cut_up() {
+ int i=0;
+ for (i=0;i<BUFSIZE4;i++) {
+ if (process_buf[i] > 1.0) process_buf[i] = 1.0;
+ if (process_buf[i] < -1.0) process_buf[i] = -1.0;
+ }
+}
+
+#ifdef __EMSCRIPTEN__
+int KEEPALIVE stop_loop() {
+ emscripten_pause_main_loop();
+ return 0;
+}
+
+int KEEPALIVE start_loop() {
+ emscripten_resume_main_loop();
+ return 0;
+}
+#endif
+
void save_to_matlab(char *name) {
int i;
FILE *f=NULL;
@@ -368,6 +416,7 @@ int main_tick() {
fir_filter(&fir_lp, process_buf, PROCESS_BUF_SIZE, process_buf2, PROCESS_BUF_SIZE);
memcpy(process_buf,process_buf2,PROCESS_BUF_SIZE*sizeof(double));
+ cut_up();
save_to_matlab("B2");
#endif
convert_double_to_f32();
@@ -403,7 +452,10 @@ int main_tick() {
if( audio_buf_position > audio_rec_buffer_size )
{
//Stop playing audio
+ //SDL_Delay(500);
SDL_PauseAudioDevice( playbackDeviceId, SDL_TRUE );
+ //printf("%d\n",SDL_GetQueuedAudioSize(playbackDeviceId));
+ //SDL_ClearQueuedAudio(playbackDeviceId);
current_state = RECORDED;
printf("State: RECORDED\n");
}