// Copyright 2011-2023 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef __DNR_DSP_BUF_H__
#define __DNR_DSP_BUF_H__

#include <xs1.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <platform.h>
#include "c_dsp.h"

#define DNR_50MS 1
//#define DEBUG_DNR
#if (DNR_50MS == 1)
#define DNR_DSP_FRAME_SIZE 512
#else
#define DNR_DSP_FRAME_SIZE 128
#endif

#define BUF_SLOT_NUM    3   //one for input, one for output, one for processing
#define DSP_CH_NUM      2

#if __XC__
extern "C" {
#endif



void dsp_buf_init();
void buf_slot_rotate();
void write_to_sample_in_buf(unsigned data, unsigned index, unsigned ch);
void read_from_sample_out_buf(unsigned* read_data, unsigned index, unsigned ch);
void start_dsp_processing(unsigned samFreq);


#if __XC__
} //extern c
#endif

#define AGC_ENABLED 1
#define DNR_ENABLED 1

#define KEY_MIC_VOL_DN 0x08
#define KEY_MUTE 0x10
#define KEY_MIC_VOL_UP 0x20
#define KEY_PLAY_VOL_DN 0x40
#define KEY_PLAY_VOL_UP 0x80
#define KEY_BITS (KEY_MIC_VOL_DN | KEY_MUTE | KEY_MIC_VOL_UP | KEY_PLAY_VOL_DN | KEY_PLAY_VOL_UP)

#if defined (PHATEN_GSV2)
#define DEBOUNCE_TIMEOUT 10     // in units of 2.6ms; 128 samples/frame
#else
#error "Please define DEBOUNCE_TIMEOUT"
#endif

#define MUTED_MIC 0x5A
#define UNMUTED_MIC 0xA5

// 改动原因：添加HID控制命令宏定义，用于button_task中的按键处理（从dnr_dsp_buf.c移到这里，以便dsp.c可以访问）
#define HID_CONTROL_PLAYPAUSE   0x01
#define HID_CONTROL_NEXT        0x02
#define HID_CONTROL_PREV        0x04
#define HID_CONTROL_VOLUP       0x00
#define HID_CONTROL_VOLDN       0x01
#define HID_CONTROL_MUTE        0x20

#endif //RINGBUFFER_H

