M
M
Michael2014-11-03 23:26:56
Programming
Michael, 2014-11-03 23:26:56

How to process and filter the audio signal?

Hello. Your advice is very necessary. The university was asked to write a sound filtering program. (removal of noise and unnecessary harmonics). I took, translated and slightly changed the finished example from bass.dll as a basis.
Next, my plan is:

  1. I read signals in portions of a certain length
  2. For each "portion" I spend the fast Fourier transform.
  3. As a result, I get an array of frequencies. I remove the excess from it.
  4. I perform the inverse Fourier transform of this array.
  5. I display the graph without noise on the screen.

In general: 2 graphs should be drawn in real time with minimal delay. The first is sound with noise. The second is sound without noise. (then the graph of the autocorrelation function should also be added ... but that's later)
At the first stage, I had the following questions:
  1. If I want to organize reading of the signal in portions of 4096 bytes in this program, then how is it better to implement it, and what time period should I use? What formula do I need to calculate it?
  2. How to organize this audio conversion without loss during its buffering and unnecessary overdubs? How to calculate the time correctly so that there is no lost information between two BPP samples and so that one sample does not overlap with the other?
  3. What does the RecordingCallback function take as arguments?
#define FREQ 44100               // частота дискретизации
#define BUFSTEP 200000        // блок распределения памяти
#define CHANS 1                   // количество каналов
char *recbuf=NULL;		  // буфер записи
int reclen;			          // длина записи
HRECORD rchan=0;		  // канал записи
HSTREAM chan=0;		  // канал воспроизведения

BOOL CALLBACK RecordingCallback(HRECORD handle, const void *buffer, DWORD length, void *user)  //вызывается каждые 100 мс.
  {
  if ((reclen%BUFSTEP)+length>=BUFSTEP)    // увеличить размер буфера при необходимости
    	{
    	recbuf = (char *)realloc(recbuf,((reclen+length)/BUFSTEP+1)*BUFSTEP);
    	if (!recbuf)
         {
         rchan=0;
         return FALSE; // стоп
         }
    	}
  memcpy(recbuf+reclen,buffer,length);        // буфер данных
  reclen+=length;
  return TRUE; // продолжить запись
  }

void StartRecording()
  {
  WAVEFORMATEX *wf;
  if(recbuf)
    	{
    	BASS_StreamFree(chan);     // освободить старый канал
    	chan=0;
      free(recbuf);
      recbuf=NULL;
    	BASS_Free();
      }
  recbuf=(char *)malloc(BUFSTEP);  // выделить персональный буфер и освободить место для заголовка
  reclen=44;
  memcpy(recbuf,"RIFF\0\0\0\0WAVEfmt \20\0\0\0",20);     // заполнить заголовок
  memcpy(recbuf+36,"data\0\0\0\0",8);
  wf=(WAVEFORMATEX*)(recbuf+20);
  wf->wFormatTag=1;                                      // тип аудио сигнала
  wf->nChannels=CHANS;                                   // количество каналов аудиоданных
  wf->wBitsPerSample=16;                                 // количество бит на сэмпл
  wf->nSamplesPerSec=FREQ;                               // частота дискретизации
  wf->nBlockAlign=wf->nChannels*wf->wBitsPerSample/8;      // выравнивание блока в байтах
  wf->nAvgBytesPerSec=wf->nSamplesPerSec*wf->nBlockAlign;   // скорость передачи данных в байтах в секунду
  rchan = BASS_RecordStart(FREQ,CHANS,0,RecordingCallback,0);  // начать запись
  }

I reviewed a bunch of topics, but I didn’t find anything for this case ... Yes, I’m stupid, but I really want to figure it out ...
Just don’t say that everything is bad :)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2014-11-04
@mmisin1

What does the RecordingCallback function take as arguments?

BOOL CALLBACK RecordingCallback(HRECORD handle, const void *buffer, DWORD length, void *user)
handle of the recording process through which this process can be controlled somehow, the
sample buffer, the length of the buffer in bytes, and the pointer passed to BASS_RecordStart as the last argument.
Sample is the value of the amplitude of the audio signal in one channel. The sample format is specified by the least significant bits of the third parameter of the BASS_RecordStart function. If there is 0, then the format is a 16-bit signed integer. When recording multi-channel audio, the channel samples are taken in order.
The callback itself is called periodically, the length of the period can be set by the high bits of the third parameter.
See www.un4seen.com/doc/#bass/BASS_RecordStart.html

N
nehyrb, 2014-12-26
@nehyrb

I experimented with the DFT, driving a signal through it. I took 1024 samples and ran forward + reverse. The signal is restored, however, there is a jump at the junctions, so each window is separated by a click, in total, a constant click is heard in the received signal.
It is very interesting how to join the borders in order to avoid distortions?

M
Michael, 2014-12-03
@mmisin1

jcmvbkbc : I understood from the help that the callback is called every 100 milliseconds. Each time this callback was called, I displayed the leght parameter. He was not static. Here is his output: 5512 11024 8268 8268 8268 11024 8268 and so on. Can it be changed and fixed somehow?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question